The recurrence
Towers of Hanoi: move a stack of n disks to another peg, one disk at a time, never putting a big disk on a smaller one. Call the fewest moves T(n). The table will hold T(1) to T(5).
To move n disks, move the top n−1 aside, move the biggest disk, then move the n−1 back on top. So T(n) = 2T(n−1) + 1. A rule that defines a value from smaller cases of itself is a recurrence.
The rule alone never stops: T(5) needs T(4), which needs T(3), and so on forever. A base case ends the chain. One disk takes one move, so T(1) = 1. Line 2 of the code is that base case.
Unroll it
Now build upward. Feed T(1) into the rule: T(2) = 2 × 1 + 1 = 3. Feed that in: T(3) = 2 × 3 + 1 = 7. Each new value needs only the one before it.
T(4) = 2 × 7 + 1 = 15 and T(5) = 2 × 15 + 1 = 31. The table now reads 1, 3, 7, 15, 31. This "plug and chug" works, but reaching T(64) takes 63 rounds of the rule.
Add 1 to each value: 2, 4, 8, 16, 32. Those are the powers of 2. So we guess T(n) = 2ⁿ − 1. A formula with no T on its right side is called a closed form.
Prove it
A pattern in five values is only a guess. Proof by induction has two parts. Part one, the base case: the formula gives 2¹ − 1 = 1, and T(1) = 1. They agree.
Part two: assume T(n−1) = 2ⁿ⁻¹ − 1. The rule gives T(n) = 2(2ⁿ⁻¹ − 1) + 1 = 2ⁿ − 2 + 1 = 2ⁿ − 1. Each case passes the formula to the next, so it holds for every n ≥ 1.
The closed form answers at once. 64 disks need 2⁶⁴ − 1, about 1.8 × 10¹⁹ moves. At one move per second that is about 585 billion years. Each extra disk doubles the work: exponential growth.
Divide and conquer
Merge sort splits n items into two halves, sorts each half, then merges them. Count n units of work per merge: M(n) = 2M(n/2) + n. One item is already sorted, so the base case is M(1) = 0.
Use sizes that halve cleanly: 2, 4, 8, 16. M(2) = 2 × 0 + 2 = 2, M(4) = 2 × 2 + 4 = 8, M(8) = 2 × 8 + 8 = 24, M(16) = 2 × 24 + 16 = 64.
Halving 16 reaches 1 after log₂ 16 = 4 levels, and each level does 16 work in total. So M(n) = n log₂ n: 16 × 4 = 64. That grows far slower than Hanoi's 2ⁿ − 1.
Try it in the Python prompt
;; step 1/12 · A puzzle that repeats >>> def T(n): ... if n == 1: return 1 ... return 2*T(n-1) + 1 ... >>> [T(n) for n in range(1, 6)] [1, 3, 7, 15, 31]
Checking many values with a computer is evidence, not proof. Induction proves a formula for every n: the base case starts the chain, and the step shows that each case hands the truth to the next.