Every recursion visualization on this site on one map. The branches are the main ideas. Each leaf is a page; the grey line under it is the one thing to remember about it. Click a branch to focus on it, click a page to open it.
Recall mode hides the page names. Read the hint, say the name, then click the "?" to check.
1. How the map is organized
The map at a glance: 4 branches, 13 pages.
Ask what the recursion does with its calls:
One call per step, down to a base case? That is simple recursion.
Several choices per step, some undone? That is backtracking: it walks a tree of choices.
Is the question about memory? Each call needs a stack frame: the call stack branch, and how tail calls avoid it.
2. The branches side by side
Branch
Calls per step
Time
Stack depth
Simple recursion
one
O(n)
O(n)
Backtracking
one per choice
exponential, e.g. O(n!)
O(n)
Tail calls with TCO
one, in tail position
O(n)
O(1)
3. Five facts to remember
Every recursion needs a base case, or it never stops.
Each call pushes a frame on the call stack; too many frames cause a stack overflow.
Backtracking undoes its last choice when it hits a dead end and tries the next one.
A tail call is the last thing a function does, so its frame can be reused.
Python and most JavaScript engines do not do tail-call optimization.