Recursion Mind Map

Algorithm & Systems Visualizations

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

Overview of the recursion mind map: Simple recursion, Backtracking, The call stack, Divide and conquer.
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

BranchCalls per stepTimeStack depth
Simple recursiononeO(n)O(n)
Backtrackingone per choiceexponential, e.g. O(n!)O(n)
Tail calls with TCOone, in tail positionO(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.

See all recursion pages in the index, or the other mind maps.