8 · Recurrences: recursion trees & guess-and-verify
Solve T(n) by expansion, recursion trees and substitution.
In one sentence
A recurrence describes running time in terms of smaller inputs, e.g. . Solve it by drawing the recursion tree, adding up the cost of each level, and, when asked, proving the guess by induction (the substitution method).
Everyday analogy
A company org chart. The CEO does work personally and hands the rest to managers, each handling a share. They do the same with their teams, and so on down to the interns (the base cases). The company's total work = the sum over every level of the chart. Ask yourself: is most of the work done at the top, at the bottom, or spread evenly?
Key tools
Recursion-tree level table for :
| Level | # nodes | Size of each | Cost per node | Level total |
|---|---|---|---|---|
| 0 | 1 | |||
| 1 | ||||
| last () | 1 |
Then look at the level totals:
| Level totals… | Then is… | Example |
|---|---|---|
| equal on every level | level cost × number of levels | |
| shrinking geometrically going down | dominated by the root | |
| growing geometrically going down | dominated by the leaves, |
Other methods
- Expansion (iteration): substitute the recurrence into itself a few times, spot the pattern, then sum. Best for
- Substitution (guess and verify): guess the answer (often from the tree), then prove it by induction (Topic 2).
- Master theorem (CLRS §4.5): a shortcut for the three rows above. Not in the slides yet, so use it to check answers unless your instructor allows it.
(merge sort)
| Level | nodes | size | level total |
|---|---|---|---|
| 0 | 1 | ||
| 1 | 2 | ||
| 2 | 4 | ||
| 1 |
Equal levels: levels, so .
: the root dominates
| Level | nodes | size | level total |
|---|---|---|---|
| 0 | 1 | ||
| 1 | 2 | ||
| 2 | 4 |
The totals halve each level: , so .
: the leaves dominate
Level totals double going down. The leaves: , so .
Common mistakes
- Writing the level total as and forgetting to multiply by the number of nodes .
- Wrong number of levels: it's (where the size reaches 1), not .
- Forgetting the leaves' cost when levels grow.
- In substitution: proving and calling it done. You must get back to exactly with the same .
- Using rules wrongly: , not .
Mastery check
Solve without hints, then explain level by level
(a) Solve with a recursion tree (build the full level table).
(b) Solve and say why the root dominates.
(c) Solve , , by expansion.
(a) nodes × = per level over levels, so .
(b) Level totals form a shrinking series, sum , so .
(c) , so .
Status
Tick all six steps to unlock “Mastered”.
Which study mode worked for you?
See it move
- VisuAlgo: Recursion tree: enter a recursive function and watch the tree.
References
- 08 Divide & Conquer, Recurrences: Slides 25–29 (merge sort recurrence and full recursion tree), 30–33 (techniques, recursion-tree method), 34–42 (worked recursion-tree examples, including an uneven split).
- Supplementary Notes: Proof techniques p. 6 (verifying a recurrence's closed form by induction).
- CLRS 4e §4.3 (substitution method), §4.4 (recursion-tree method), §4.5 (master method, a preview), Appendix A (geometric series).