Solving recurrences I: recursion-tree & substitution
◈ 4 cardsDraw the tree and sum per level; guess-and-prove by induction; the subtract-a-lower-order-term trick; the inductive-hypothesis O() fallacy.
Two general methods
A recurrence describes in terms of on smaller arguments. Before the master-theorem shortcut, two methods solve recurrences the master theorem can't reach (unequal splits, gap cases): the recursion-tree method (to guess the answer) and the substitution method (to prove it).
Recursion trees: sum the cost per level
Draw a node per subproblem, labelled with its non-recursive (divide+combine) cost. Sum within each level, then across levels. The shape of those per-level sums tells you which term wins:
- per-level cost grows toward the leaves ⟶ the leaves dominate;
- per-level cost is constant ⟶ each level contributes equally, and the number of levels matters;
- per-level cost shrinks toward the leaves ⟶ the root dominates.
Worked tree — . At depth there are nodes, each of size , costing . The level total is . Summing the geometric series with ratio gives at most . The root alone already costs , so — the root dominates.
Worked tree — unbalanced . Branches shrink at different rates, but every level still sums to at most of work, and the longest root-to-leaf path is levels. So total cost , and it is . (The master theorem can't touch this one — the two subproblems have different sizes.)
Substitution: guess, then prove by induction
Two steps: (1) guess the form of the bound with a symbolic constant; (2) prove it by induction, solving for the constant.
Worked proof — . Guess . Inductive hypothesis: . Then
where the last step holds once is large enough that the term swallows the term. The key algebra is , which produces the crucial .
The subtract-a-lower-order-term trick
Sometimes the naive guess almost works but leaves a stubborn additive term. For , guessing yields — which is not . Strengthen the guess to :
as long as dominates the . Counterintuitively, a stronger (smaller) hypothesis is easier to push through, because each recursive call contributes its own .