SlideShare a Scribd company logo
1 of 2
Download to read offline
Recursive algorithms

n!=n*(n-1)*(n-2) (n-3)........... 3*2*1

It can also be written as

for n≥0 n!= {1 if n=0

                   n(n-1)! Else}


We will explain recursion with a example. Consider the function for calculating the
value of n! Recursively. Here we give the number (of which the factorial is to be
found out) to the function “factorial”.

   int factorial(int n)
   {
     if (n == 0)
        return 1;
     else
        return (n * factorial(n-1));
   }



Consider the case of input 0 and 3

When input is 0

factorial(0)=> 1

When input 3

factorial(3)
3 * factorial(2)
3 * 2 * factorial(1)
3 * 2 * 1 * factorial(0)
3*2*1*1
=> 6

In case of input 3 we can see that the function calls itself repeatedly with smaller or
simpler input values. It obtains the result for the current input by applying simple
operations to the returned value for the smaller (or simpler) input.
Recursion

More Related Content

What's hot

What's hot (20)

2 1 polynomials
2 1 polynomials2 1 polynomials
2 1 polynomials
 
Piecewise Functions
Piecewise FunctionsPiecewise Functions
Piecewise Functions
 
Recursion
RecursionRecursion
Recursion
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
4.1 Inverse Functions
4.1 Inverse Functions4.1 Inverse Functions
4.1 Inverse Functions
 
Lec2
Lec2Lec2
Lec2
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Piecewise Functions in Matlab
Piecewise Functions in MatlabPiecewise Functions in Matlab
Piecewise Functions in Matlab
 
The Algebric Functions
The Algebric FunctionsThe Algebric Functions
The Algebric Functions
 
L10 sorting-searching
L10 sorting-searchingL10 sorting-searching
L10 sorting-searching
 
11 15 (doubly linked list)
11 15 (doubly linked list)11 15 (doubly linked list)
11 15 (doubly linked list)
 
Lec5
Lec5Lec5
Lec5
 
Lec9
Lec9Lec9
Lec9
 
Scilab - Piecewise Functions
Scilab - Piecewise FunctionsScilab - Piecewise Functions
Scilab - Piecewise Functions
 
Composite functions
Composite functionsComposite functions
Composite functions
 
Types of functions
Types of functionsTypes of functions
Types of functions
 
Function and Its Types.
Function and Its Types.Function and Its Types.
Function and Its Types.
 
Module#8 notes
Module#8 notesModule#8 notes
Module#8 notes
 
Linked list Output tracing
Linked list Output tracingLinked list Output tracing
Linked list Output tracing
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
 

Viewers also liked

Espíritu emprendedor
Espíritu emprendedorEspíritu emprendedor
Espíritu emprendedorbaleiron
 
Benjamin b
Benjamin bBenjamin b
Benjamin bfbcat
 
Proceso de atencion de enfermeria sem4
Proceso de atencion de enfermeria sem4Proceso de atencion de enfermeria sem4
Proceso de atencion de enfermeria sem4tracy viviana
 
Action plan
Action planAction plan
Action planhgaines
 
La historia del intLernet
La historia del intLernetLa historia del intLernet
La historia del intLernetNiko Hernandez
 
Martin Hucke Value Investing 2. Aktiencamp
Martin Hucke   Value Investing   2. AktiencampMartin Hucke   Value Investing   2. Aktiencamp
Martin Hucke Value Investing 2. Aktiencampmystocks
 
Marc Oliver Eckart Aktiencamp Berlin Eckart 5
Marc Oliver Eckart Aktiencamp Berlin Eckart 5Marc Oliver Eckart Aktiencamp Berlin Eckart 5
Marc Oliver Eckart Aktiencamp Berlin Eckart 5mystocks
 
Friends And Strangers
Friends And StrangersFriends And Strangers
Friends And StrangersMarthaRay
 
Manual do Aluno da Academia Comunicarte
Manual do Aluno da Academia ComunicarteManual do Aluno da Academia Comunicarte
Manual do Aluno da Academia ComunicarteComunicarte
 
Kunst Mal Anders
Kunst Mal AndersKunst Mal Anders
Kunst Mal Andersmmoles5
 
บทที่ 3
บทที่ 3บทที่ 3
บทที่ 3chaoey2012
 
Präsentation Knowtech 2008 seto
Präsentation Knowtech 2008 setoPräsentation Knowtech 2008 seto
Präsentation Knowtech 2008 setoStefan Meißner
 

Viewers also liked (20)

Espíritu emprendedor
Espíritu emprendedorEspíritu emprendedor
Espíritu emprendedor
 
Benjamin b
Benjamin bBenjamin b
Benjamin b
 
Proceso de atencion de enfermeria sem4
Proceso de atencion de enfermeria sem4Proceso de atencion de enfermeria sem4
Proceso de atencion de enfermeria sem4
 
SvdE verhagen2
SvdE verhagen2SvdE verhagen2
SvdE verhagen2
 
Week3 presentation
Week3  presentationWeek3  presentation
Week3 presentation
 
Buddha
BuddhaBuddha
Buddha
 
Action plan
Action planAction plan
Action plan
 
CV Adisty
CV AdistyCV Adisty
CV Adisty
 
La historia del intLernet
La historia del intLernetLa historia del intLernet
La historia del intLernet
 
Te extraño mucho
Te  extraño  muchoTe  extraño  mucho
Te extraño mucho
 
Martin Hucke Value Investing 2. Aktiencamp
Martin Hucke   Value Investing   2. AktiencampMartin Hucke   Value Investing   2. Aktiencamp
Martin Hucke Value Investing 2. Aktiencamp
 
Marc Oliver Eckart Aktiencamp Berlin Eckart 5
Marc Oliver Eckart Aktiencamp Berlin Eckart 5Marc Oliver Eckart Aktiencamp Berlin Eckart 5
Marc Oliver Eckart Aktiencamp Berlin Eckart 5
 
Friends And Strangers
Friends And StrangersFriends And Strangers
Friends And Strangers
 
Manual do Aluno da Academia Comunicarte
Manual do Aluno da Academia ComunicarteManual do Aluno da Academia Comunicarte
Manual do Aluno da Academia Comunicarte
 
Kunst Mal Anders
Kunst Mal AndersKunst Mal Anders
Kunst Mal Anders
 
บทที่ 3
บทที่ 3บทที่ 3
บทที่ 3
 
Präsentation Knowtech 2008 seto
Präsentation Knowtech 2008 setoPräsentation Knowtech 2008 seto
Präsentation Knowtech 2008 seto
 
Psicologia imprimir
Psicologia imprimirPsicologia imprimir
Psicologia imprimir
 
Nombres
NombresNombres
Nombres
 
OpenVRP (Deutsch)
OpenVRP (Deutsch)OpenVRP (Deutsch)
OpenVRP (Deutsch)
 

Similar to Recursion

Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosluzenith_g
 
Lecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptLecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptZohairMughal1
 
Lecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptZohairMughal1
 
Data structure 8.pptx
Data structure 8.pptxData structure 8.pptx
Data structure 8.pptxSajalFayyaz
 
In three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdfIn three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdffeelinggift
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexityashishtinku
 
Arithmetic sequence in elementary and HS
Arithmetic sequence in elementary and HSArithmetic sequence in elementary and HS
Arithmetic sequence in elementary and HSRoseEdenAbitong2
 
Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.mohanrathod18
 
Time and Space Complexity Analysis.pptx
Time and Space Complexity Analysis.pptxTime and Space Complexity Analysis.pptx
Time and Space Complexity Analysis.pptxdudelover
 

Similar to Recursion (20)

Alg1
Alg1Alg1
Alg1
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmos
 
Array presentation
Array presentationArray presentation
Array presentation
 
Lecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptLecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).ppt
 
Lecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.ppt
 
Task 4
Task 4Task 4
Task 4
 
02 Notes Divide and Conquer
02 Notes Divide and Conquer02 Notes Divide and Conquer
02 Notes Divide and Conquer
 
Data structure 8.pptx
Data structure 8.pptxData structure 8.pptx
Data structure 8.pptx
 
algo_vc_lecture8.ppt
algo_vc_lecture8.pptalgo_vc_lecture8.ppt
algo_vc_lecture8.ppt
 
5 numerical analysis
5 numerical analysis5 numerical analysis
5 numerical analysis
 
Per4 induction
Per4 inductionPer4 induction
Per4 induction
 
Slide2
Slide2Slide2
Slide2
 
In three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdfIn three of the exercises below there is given a code of a method na.pdf
In three of the exercises below there is given a code of a method na.pdf
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexity
 
Arithmetic sequence in elementary and HS
Arithmetic sequence in elementary and HSArithmetic sequence in elementary and HS
Arithmetic sequence in elementary and HS
 
Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.
 
Recursion.pdf
Recursion.pdfRecursion.pdf
Recursion.pdf
 
ch3.ppt
ch3.pptch3.ppt
ch3.ppt
 
Time and Space Complexity Analysis.pptx
Time and Space Complexity Analysis.pptxTime and Space Complexity Analysis.pptx
Time and Space Complexity Analysis.pptx
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 

Recursion

  • 1. Recursive algorithms n!=n*(n-1)*(n-2) (n-3)........... 3*2*1 It can also be written as for n≥0 n!= {1 if n=0 n(n-1)! Else} We will explain recursion with a example. Consider the function for calculating the value of n! Recursively. Here we give the number (of which the factorial is to be found out) to the function “factorial”. int factorial(int n) { if (n == 0) return 1; else return (n * factorial(n-1)); } Consider the case of input 0 and 3 When input is 0 factorial(0)=> 1 When input 3 factorial(3) 3 * factorial(2) 3 * 2 * factorial(1) 3 * 2 * 1 * factorial(0) 3*2*1*1 => 6 In case of input 3 we can see that the function calls itself repeatedly with smaller or simpler input values. It obtains the result for the current input by applying simple operations to the returned value for the smaller (or simpler) input.