SlideShare une entreprise Scribd logo
Chapter 10 Recursion
Chapter Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object]
Recursive Thinking ,[object Object],[object Object],[object Object],[object Object]
Recursive Definitions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
FIGURE 10.1   Tracing the recursive definition of a list
Infinite Recursion ,[object Object],[object Object],[object Object],[object Object],[object Object]
Recursive Definitions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Recursive Programming ,[object Object],[object Object],[object Object],[object Object]
Recursive Programming ,[object Object],[object Object],[object Object],[object Object],[object Object]
FIGURE 10.2   The sum of the numbers  1 through N, defined recursively
Recursive Programming public int sum (int num) { int result; if (num == 1) result = 1; else result = num + sum(num-1); return result; }
FIGURE 10.3   Recursive calls to the sum method
Recursion vs. Iteration ,[object Object],[object Object],[object Object],[object Object]
Recursion vs. Iteration ,[object Object],[object Object],[object Object],[object Object]
Indirect Recursion ,[object Object],[object Object],[object Object],[object Object],[object Object]
FIGURE 10.4 Indirect recursion
Maze Traversal ,[object Object],[object Object],[object Object]
Maze Traversal ,[object Object],[object Object],[object Object],[object Object]
Listing 10.1
Listing 10.2
Listing 10.2  (cont.)
Listing 10.2  (cont.)
Listing 10.2  (cont.)
Listing 10.2  (cont.)
FIGURE 10.5   UML description of the Maze and MazeSearch classes
The Towers of Hanoi ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
FIGURE 10.6   The Towers of Hanoi puzzle
FIGURE 10.7   A solution to the three-disk Towers of Hanoi puzzle
Towers of Hanoi ,[object Object],[object Object],[object Object],[object Object],[object Object]
Towers of Hanoi ,[object Object],[object Object],[object Object]
Listing 10.3
Listing 10.3  (cont.)
Listing 10.4
Listing 10.4  (cont.)
Listing 10.4  (cont.)
FIGURE 10.8  UML description of the SolveTowers and TowersofHanoi classes
Analyzing Recursive Algorithms ,[object Object],[object Object],[object Object]
Analyzing Recursive Algorithms ,[object Object],[object Object],[object Object],[object Object]

Contenu connexe

Tendances

Tendances (20)

Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
Quick sort
Quick sortQuick sort
Quick sort
 
Heap_Sort1.pptx
Heap_Sort1.pptxHeap_Sort1.pptx
Heap_Sort1.pptx
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
Unit 4 external sorting
Unit 4   external sortingUnit 4   external sorting
Unit 4 external sorting
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures  Design-Notes-Searching-Hashing.pdfAD3251-Data Structures  Design-Notes-Searching-Hashing.pdf
AD3251-Data Structures Design-Notes-Searching-Hashing.pdf
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Recursive algorithms
Recursive algorithmsRecursive algorithms
Recursive algorithms
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Binary search
Binary searchBinary search
Binary search
 
Empirical analysis
Empirical analysisEmpirical analysis
Empirical analysis
 
08 Hash Tables
08 Hash Tables08 Hash Tables
08 Hash Tables
 

En vedette

Knight’s tour algorithm
Knight’s tour algorithmKnight’s tour algorithm
Knight’s tour algorithm
Hassan Tariq
 

En vedette (20)

Recursion
RecursionRecursion
Recursion
 
PyOhio Recursion Slides
PyOhio Recursion SlidesPyOhio Recursion Slides
PyOhio Recursion Slides
 
Recursion
RecursionRecursion
Recursion
 
Introduccion a prolog
Introduccion a prologIntroduccion a prolog
Introduccion a prolog
 
Prolog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb PirzadaProlog Code [Family Tree] by Shahzeb Pirzada
Prolog Code [Family Tree] by Shahzeb Pirzada
 
Prolog programming
Prolog programmingProlog programming
Prolog programming
 
Knight’s tour algorithm
Knight’s tour algorithmKnight’s tour algorithm
Knight’s tour algorithm
 
Knight's Tour
Knight's TourKnight's Tour
Knight's Tour
 
Logic Programming and Prolog
Logic Programming and PrologLogic Programming and Prolog
Logic Programming and Prolog
 
Chaps 1-3-ai-prolog
Chaps 1-3-ai-prologChaps 1-3-ai-prolog
Chaps 1-3-ai-prolog
 
PROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In PrologPROLOG: Fact Roles And Queries In Prolog
PROLOG: Fact Roles And Queries In Prolog
 
Prolog 7-Languages
Prolog 7-LanguagesProlog 7-Languages
Prolog 7-Languages
 
ProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) IntroductionProLog (Artificial Intelligence) Introduction
ProLog (Artificial Intelligence) Introduction
 
Artificial intelligence Prolog Language
Artificial intelligence Prolog LanguageArtificial intelligence Prolog Language
Artificial intelligence Prolog Language
 
PROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In PrologPROLOG: Recursion And Lists In Prolog
PROLOG: Recursion And Lists In Prolog
 
Introduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in LogicIntroduction on Prolog - Programming in Logic
Introduction on Prolog - Programming in Logic
 
Prolog Programming : Basics
Prolog Programming : BasicsProlog Programming : Basics
Prolog Programming : Basics
 
Introduction to Prolog
Introduction to PrologIntroduction to Prolog
Introduction to Prolog
 
Prolog basics
Prolog basicsProlog basics
Prolog basics
 
PROLOG: Introduction To Prolog
PROLOG: Introduction To PrologPROLOG: Introduction To Prolog
PROLOG: Introduction To Prolog
 

Similaire à Ch10 Recursion

Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8
dplunkett
 
Python Programming unit5 (1).pdf
Python Programming unit5 (1).pdfPython Programming unit5 (1).pdf
Python Programming unit5 (1).pdf
jamvantsolanki
 
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3
Traian Rebedea
 

Similaire à Ch10 Recursion (20)

Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8
 
Complexity Analysis of Recursive Function
Complexity Analysis of Recursive FunctionComplexity Analysis of Recursive Function
Complexity Analysis of Recursive Function
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Computer Science Exam Help
Computer Science Exam Help Computer Science Exam Help
Computer Science Exam Help
 
Ca notes
Ca notesCa notes
Ca notes
 
Recursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & StructureRecursion vs. Iteration: Code Efficiency & Structure
Recursion vs. Iteration: Code Efficiency & Structure
 
Tower of Hanoi.ppt
Tower of Hanoi.pptTower of Hanoi.ppt
Tower of Hanoi.ppt
 
Loops_in_Rv1.2b
Loops_in_Rv1.2bLoops_in_Rv1.2b
Loops_in_Rv1.2b
 
Recursion in Data Structure
Recursion in Data StructureRecursion in Data Structure
Recursion in Data Structure
 
CSE680-17NP-Complete.pptx
CSE680-17NP-Complete.pptxCSE680-17NP-Complete.pptx
CSE680-17NP-Complete.pptx
 
01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes01 Notes Introduction Analysis of Algorithms Notes
01 Notes Introduction Analysis of Algorithms Notes
 
CSP UNIT 2 AIML.ppt
CSP UNIT 2 AIML.pptCSP UNIT 2 AIML.ppt
CSP UNIT 2 AIML.ppt
 
Parallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel applicationParallel Computing 2007: Bring your own parallel application
Parallel Computing 2007: Bring your own parallel application
 
Python Programming unit5 (1).pdf
Python Programming unit5 (1).pdfPython Programming unit5 (1).pdf
Python Programming unit5 (1).pdf
 
recursion.ppt
recursion.pptrecursion.ppt
recursion.ppt
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrences
 
ALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTESALGORITHMS - SHORT NOTES
ALGORITHMS - SHORT NOTES
 
algorithm unit 1
algorithm unit 1algorithm unit 1
algorithm unit 1
 
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3
 

Plus de leminhvuong

Plus de leminhvuong (20)

Proxy
ProxyProxy
Proxy
 
Lession2 Xinetd
Lession2 XinetdLession2 Xinetd
Lession2 Xinetd
 
Module 7 Sql Injection
Module 7   Sql InjectionModule 7   Sql Injection
Module 7 Sql Injection
 
Iptables
IptablesIptables
Iptables
 
Lession1 Linux Preview
Lession1 Linux PreviewLession1 Linux Preview
Lession1 Linux Preview
 
Http
HttpHttp
Http
 
Dns
DnsDns
Dns
 
Net Admin Intro
Net Admin IntroNet Admin Intro
Net Admin Intro
 
Lession4 Dhcp
Lession4 DhcpLession4 Dhcp
Lession4 Dhcp
 
Lession3 Routing
Lession3 RoutingLession3 Routing
Lession3 Routing
 
Module 1 Introduction
Module 1   IntroductionModule 1   Introduction
Module 1 Introduction
 
Wire Less
Wire LessWire Less
Wire Less
 
Net Security Intro
Net Security IntroNet Security Intro
Net Security Intro
 
Module 10 Physical Security
Module 10   Physical SecurityModule 10   Physical Security
Module 10 Physical Security
 
Module 9 Dos
Module 9   DosModule 9   Dos
Module 9 Dos
 
Module 8 System Hacking
Module 8   System HackingModule 8   System Hacking
Module 8 System Hacking
 
Module 6 Session Hijacking
Module 6   Session HijackingModule 6   Session Hijacking
Module 6 Session Hijacking
 
Module 5 Sniffers
Module 5  SniffersModule 5  Sniffers
Module 5 Sniffers
 
Module 4 Enumeration
Module 4   EnumerationModule 4   Enumeration
Module 4 Enumeration
 
Module 3 Scanning
Module 3   ScanningModule 3   Scanning
Module 3 Scanning
 

Dernier

Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Dernier (20)

Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdf
 

Ch10 Recursion