Lecture 17 Flashcards
What is recursion
Recursion is the idea of solving a problem in terms of itself.
The two main elements to recursive solutions are?
–The base case: the form (or forms) of the problem for which an exact solution is provided.
–The recursive step: the reduction of one version the problem to a simpler form.
N factorial Code
int factorial(int n) { if(n == 0 || n == 1) return 1; else return n * factorial(n-1); }
how can the program keep track of its state?
Stacks
Each individual method call within a recursive process can be called a
Frame
Proof by induction involves three main parts:
A base case with a known solution.
A proposed, closed-form solution for any value , which the base case matches.
A proof that shows that if the proposed solution works for time step k, it works for time step k+1.