Recursion Chapter 16 S. Dandamudi
Outline Introduction Recursion Recursion vs. Iteration
Introduction A recursive procedure calls itself Directly, or Indirectly Some applications can be naturally expressed using recursion factorial(0) = 1 factorial (n) = n * factorial(n  1) for n > 0 From implementation viewpoint Very similar to any other procedure call Activation records are stored on the stack
Introduction (cont’d)
Recursion Two examples in Pentium and MIPS assembly languages Factorial  Quicksort Example 1 Factorial factorial(0) = 1 factorial (n) = n * factorial(n  1) for n > 0 Activation record Consists of the return address pushed onto the stack by the call instruction
Recursion (cont’d) Example 2 Quicksort  Sort an N-element array Basic algorithm Selects a partition element  x Assume that the final position of  x  is array[ i ] Moves elements less than  x  into array[0]…array[ i  1] Moves elements greater than  x  into array[ i +1]…array[ N  1] Applies quicksort recursively to sort these two subarrays
Recursion vs. Iteration Recursion Concise Better program maintenance Natural choice for some problems Potential problems Inefficiency Call invocation and return overheads Duplicate computation Increased memory requirements Last slide

More Related Content

PPTX
Performance analysis(Time & Space Complexity)
PPTX
Asymptotic Analysis in Data Structure using C
PPT
Parallel algorithms
PDF
Algorithm Analyzing
PPTX
Recursion
PPTX
Computational Complexity
PDF
A calculus of mobile Real-Time processes
PPTX
Introduction to datastructure and algorithm
Performance analysis(Time & Space Complexity)
Asymptotic Analysis in Data Structure using C
Parallel algorithms
Algorithm Analyzing
Recursion
Computational Complexity
A calculus of mobile Real-Time processes
Introduction to datastructure and algorithm

What's hot (20)

PPT
Analysis of algo
PPT
how to calclute time complexity of algortihm
PPTX
Time space trade off
PPT
Time andspacecomplexity
PDF
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
PPT
Recursion - Algorithms and Data Structures
PPTX
Asymptotics 140510003721-phpapp02
PPTX
Lecture 2 data structures and algorithms
PPT
PPTX
Analysis of algorithn class 2
PPT
DIT-Radix-2-FFT in SPED
PDF
Data Structure: Algorithm and analysis
PPT
Complexity of Algorithm
PPTX
Algorithm Analysis
PPT
Fundamentals of the Analysis of Algorithm Efficiency
PPTX
Machine learning session 9
PPTX
fft using labview
PPT
Algorithm analysis
PDF
(chapter 8) A Concise and Practical Introduction to Programming Algorithms in...
Analysis of algo
how to calclute time complexity of algortihm
Time space trade off
Time andspacecomplexity
Computer Science Engineering : Data structure & algorithm, THE GATE ACADEMY
Recursion - Algorithms and Data Structures
Asymptotics 140510003721-phpapp02
Lecture 2 data structures and algorithms
Analysis of algorithn class 2
DIT-Radix-2-FFT in SPED
Data Structure: Algorithm and analysis
Complexity of Algorithm
Algorithm Analysis
Fundamentals of the Analysis of Algorithm Efficiency
Machine learning session 9
fft using labview
Algorithm analysis
(chapter 8) A Concise and Practical Introduction to Programming Algorithms in...
Ad

Similar to Al2ed chapter16 (20)

PPT
Data Structures- Part5 recursion
PPT
Recursion.ppt
PPT
algo_vc_lecture8.ppt
PDF
12200224070_Adnan_Ahmed_DAAbhbhbh_63.pdf
PPTX
Unit-I Recursion.pptx
PPTX
lecture4-recursion.pptx
PPTX
slides.07.pptx
PPT
Parallel Computing 2007: Bring your own parallel application
PPTX
RECURSIONcpppleasestudyitasapwhoshould.pptx
PPTX
Reacting with ReactiveUI
DOC
ALGORITHMS - SHORT NOTES
PPT
3-Recursion.ppt
PPT
3 recursion
PPTX
sorting.pptx
PPTX
Recursion in Data Structure
PPT
Lecture 12 - Recursion
PPT
PPT
Ch4-recursion.ppt
PPT
Tower of Hanoi.ppt
PPT
Introducción al Análisis y diseño de algoritmos
Data Structures- Part5 recursion
Recursion.ppt
algo_vc_lecture8.ppt
12200224070_Adnan_Ahmed_DAAbhbhbh_63.pdf
Unit-I Recursion.pptx
lecture4-recursion.pptx
slides.07.pptx
Parallel Computing 2007: Bring your own parallel application
RECURSIONcpppleasestudyitasapwhoshould.pptx
Reacting with ReactiveUI
ALGORITHMS - SHORT NOTES
3-Recursion.ppt
3 recursion
sorting.pptx
Recursion in Data Structure
Lecture 12 - Recursion
Ch4-recursion.ppt
Tower of Hanoi.ppt
Introducción al Análisis y diseño de algoritmos
Ad

More from Abdullelah Al-Fahad (17)

PPT
Al2ed chapter17
PPT
Al2ed chapter15
PPT
Al2ed chapter14
PPT
Al2ed chapter13
PPT
Al2ed chapter12
PPT
Al2ed chapter11
PPT
Al2ed chapter10
PPT
Al2ed chapter9
PPT
Al2ed chapter8
PPT
Al2ed chapter7
PPT
Al2ed chapter6
PPT
Al2ed chapter5
PPT
Al2ed chapter4
PPT
Al2ed chapter3
PPT
Al2ed chapter2
PPT
Al2ed chapter1
PPT
Al2ed chapter18
Al2ed chapter17
Al2ed chapter15
Al2ed chapter14
Al2ed chapter13
Al2ed chapter12
Al2ed chapter11
Al2ed chapter10
Al2ed chapter9
Al2ed chapter8
Al2ed chapter7
Al2ed chapter6
Al2ed chapter5
Al2ed chapter4
Al2ed chapter3
Al2ed chapter2
Al2ed chapter1
Al2ed chapter18

Recently uploaded (20)

PPTX
History, Philosophy and sociology of education (1).pptx
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Computer Architecture Input Output Memory.pptx
PDF
What if we spent less time fighting change, and more time building what’s rig...
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PPTX
Virtual and Augmented Reality in Current Scenario
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Trump Administration's workforce development strategy
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
Complications of Minimal Access-Surgery.pdf
History, Philosophy and sociology of education (1).pptx
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Environmental Education MCQ BD2EE - Share Source.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Computer Architecture Input Output Memory.pptx
What if we spent less time fighting change, and more time building what’s rig...
Cambridge-Practice-Tests-for-IELTS-12.docx
B.Sc. DS Unit 2 Software Engineering.pptx
Virtual and Augmented Reality in Current Scenario
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Uderstanding digital marketing and marketing stratergie for engaging the digi...
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Trump Administration's workforce development strategy
Weekly quiz Compilation Jan -July 25.pdf
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
LDMMIA Reiki Yoga Finals Review Spring Summer
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
Complications of Minimal Access-Surgery.pdf

Al2ed chapter16

  • 1. Recursion Chapter 16 S. Dandamudi
  • 2. Outline Introduction Recursion Recursion vs. Iteration
  • 3. Introduction A recursive procedure calls itself Directly, or Indirectly Some applications can be naturally expressed using recursion factorial(0) = 1 factorial (n) = n * factorial(n  1) for n > 0 From implementation viewpoint Very similar to any other procedure call Activation records are stored on the stack
  • 5. Recursion Two examples in Pentium and MIPS assembly languages Factorial Quicksort Example 1 Factorial factorial(0) = 1 factorial (n) = n * factorial(n  1) for n > 0 Activation record Consists of the return address pushed onto the stack by the call instruction
  • 6. Recursion (cont’d) Example 2 Quicksort Sort an N-element array Basic algorithm Selects a partition element x Assume that the final position of x is array[ i ] Moves elements less than x into array[0]…array[ i  1] Moves elements greater than x into array[ i +1]…array[ N  1] Applies quicksort recursively to sort these two subarrays
  • 7. Recursion vs. Iteration Recursion Concise Better program maintenance Natural choice for some problems Potential problems Inefficiency Call invocation and return overheads Duplicate computation Increased memory requirements Last slide