CS 240 – Lecture 13 Recursion, Tail Recursion

CS 240 – Lecture 13 Recursion, Tail Recursion
1 / 1
CS 240 – Lecture 13 Recursion, Tail Recursion - slide 1 of 10 CS 240 – Lecture 13 Recursion, Tail Recursion - slide 2 of 10 CS 240 – Lecture 13 Recursion, Tail Recursion - slide 3 of 10 CS 240 – Lecture 13 Recursion, Tail Recursion - slide 4 of 10 CS 240 – Lecture 13 Recursion, Tail Recursion - slide 5 of 10 CS 240 – Lecture 13 Recursion, Tail Recursion - slide 6 of 10 CS 240 – Lecture 13 Recursion, Tail Recursion - slide 7 of 10 CS 240 – Lecture 13 Recursion, Tail Recursion - slide 8 of 10 CS 240 – Lecture 13 Recursion, Tail Recursion - slide 9 of 10 CS 240 – Lecture 13 Recursion, Tail Recursion - slide 10 of 10
CS 240 Lecture 13 Recursion, Tail Recursion Recursion Recursive Calls to a Function To review a topic you should have covered, recursion in programming is the act of a function or procedure calling itself or otherwise making use of

Related Topics

Download this presentation From Below

"CS 240 – Lecture 13 Recursion, Tail Recursion" is the property of its rightful owner. Permission is granted to download and print the materials on this website for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

Presentation Transcript

01
CS 240 – Lecture 13 Recursion, Tail Recursion<br>
02
Recursion – Recursive Calls to a Function To review a topic you should have covered, recursion in programming is the act of a function or procedure calling itself or otherwise making use of itself in its definition.
int factorial(int n) {
return (n > 1) ? n * factorial(n-1) : 1;
}
Above we have an example, the canonical example of the factorial function.
factorial makes calls to itself as part of its function body, which is recursion.<br>
03
Recursion – Anatomy of Recursive Functions In programming, single recursion is the act of a function directly calling itself.
factorial calls factorial.
There is also multiple recursion in which a function f calls some other function which, before terminating, eventually leads to another call to f.
No good practical examples of this to talk about just yet, but it’s very common in parsing programs and compilers.
In the end, a recursive function must have a stopping condition or it will infinitely loop.<br>