Recursive Functions
Definition
- A function which contains a call to itself
- Should include at least one terminal case – a case that contains no further calls to the recursive subprogram so that it will not continue indefinitely
- Used when the original task can be reduced to a simpler version of itself
Recursive vs. Iterative Functions
Convergence
- Iterative solution is a loop which converges to a solution
- Recursive solution is a procedure which keeps calling itself until a solution is found
Local Variables
- Iterative solution have successive values of its local variables are overwritten
- Recursive solution have successive values of its local variables are all preserved