Recursion I
Solve a big problem by trusting a smaller copy of the same problem to do most of the work: the idea behind trees, backtracking and dynamic programming.
After this lesson you will be able to
- Write a recursive function with a correct base case and a recursive case that moves toward it.
- Trace a recursive call using the call stack, including what happens as calls return.
- Decide when a problem has the self-similar shape recursion fits (nesting, halving, choices).
- Explain why naive recursion can be exponential (repeated subproblems) and what it costs in stack space.
- Avoid the classic failures: missing base case, no progress, and runaway depth.
Before you start. You should be comfortable writing functions with parameters and return values, and with if statements.