Memra

Solving recurrences I: recursion-tree & substitution

◈ 4 cards

Draw 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 .

1/32/3cnsize ncn/3size n/3cn/92cn/92cn/3size 2n/32cn/94cn/9
Unequal splits, equal levels: cn/3 + 2cn/3 = cn, and cn/9 + 2cn/9 + 2cn/9 + 4cn/9 = cn. The longest root-to-leaf path is log(3/2) n = Θ(lg n) levels, so T(n) = Θ(n lg n).
levelnodescost eachlevel total01cn²cn²13c(n/4)²(3/16)cn²29c(n/16)²(3/16)²cn²i3ⁱc(n/4ⁱ)²(3/16)ⁱcn²Ratio 3/16 < 1, so Σ (3/16)ⁱ cn² ≤ (16/13)cn². The root alone already costs Θ(n²) — the root dominatesand T(n) = Θ(n²).
The other shape of per-level sum: a geometric decay. Compare it with the tree above, where every level was equal.
NORMAL ~/memra/learn/comp-372/recurrences-tree-and-substitution utf-8 LF