DAA Study Hub

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. T(n)=2T(n/2)+nT(n) = 2T(n/2) + n. 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 f(n)f(n) work personally and hands the rest to aa managers, each handling a 1/b1/b 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 T(n)=a T(n/b)+f(n)T(n) = a\,T(n/b) + f(n):

Level ii# nodesSize of eachCost per nodeLevel total
01nnf(n)f(n)f(n)f(n)
1aan/bn/bf(n/b)f(n/b)a f(n/b)a\,f(n/b)
iiaia^in/bin/b^if(n/bi)f(n/b^i)aif(n/bi)a^i f(n/b^i)
last (i=log⁡bni = \log_b n)alog⁡bn=nlog⁡baa^{\log_b n} = n^{\log_b a}1Θ(1)\Theta(1)Θ(nlog⁡ba)\Theta(n^{\log_b a})

Then look at the level totals:

Level totals…Then T(n)T(n) is…Example
equal on every levellevel cost × number of levels2T(n/2)+n⇒Θ(nlog⁡n)2T(n/2) + n \Rightarrow \Theta(n\log n)
shrinking geometrically going downdominated by the root2T(n/2)+n2⇒Θ(n2)2T(n/2) + n^2 \Rightarrow \Theta(n^2)
growing geometrically going downdominated by the leaves, Θ(nlog⁡ba)\Theta(n^{\log_b a})4T(n/2)+n⇒Θ(n2)4T(n/2) + n \Rightarrow \Theta(n^2)

Other methods

  • Expansion (iteration): substitute the recurrence into itself a few times, spot the pattern, then sum. Best for T(n)=T(n−1)+…T(n) = T(n-1) + \dots
  • 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.

T(n)=2T(n/2)+nT(n) = 2T(n/2) + n (merge sort)

Levelnodessizelevel total
01nnnn
12n/2n/2nn
24n/4n/4nn
log⁡2n\log_2 nnn1nn

Equal levels: n×(log⁡2n+1)n \times (\log_2 n + 1) levels, so Θ(nlog⁡n)\Theta(n\log n).


T(n)=2T(n/2)+n2T(n) = 2T(n/2) + n^2: the root dominates

Levelnodessizelevel total
01nnn2n^2
12n/2n/22⋅n24=n222\cdot\frac{n^2}{4} = \frac{n^2}{2}
24n/4n/4n24\frac{n^2}{4}

The totals halve each level: n2(1+12+14+… )≤2n2n^2(1 + \frac12 + \frac14 + \dots) \le 2n^2, so Θ(n2)\Theta(n^2).


T(n)=4T(n/2)+nT(n) = 4T(n/2) + n: the leaves dominate

Level totals n,2n,4n,…n, 2n, 4n, \dots double going down. The leaves: 4log⁡2n=nlog⁡24=n24^{\log_2 n} = n^{\log_2 4} = n^2, so Θ(n2)\Theta(n^2).


Common mistakes

  • Writing the level total as f(n/bi)f(n/b^i) and forgetting to multiply by the number of nodes aia^i.
  • Wrong number of levels: it's log⁡bn\log_b n (where the size reaches 1), not log⁡an\log_a n.
  • Forgetting the leaves' cost nlog⁡ban^{\log_b a} when levels grow.
  • In substitution: proving T(n)≤cnlog⁡n+nT(n) \le cn\log n + n and calling it done. You must get back to exactly ≤cnlog⁡n\le cn\log n with the same cc.
  • Using log⁡\log rules wrongly: log⁡2(n/2)=log⁡2n−1\log_2(n/2) = \log_2 n - 1, not log⁡2n2\frac{\log_2 n}{2}.

Mastery check

Solve without hints, then explain level by level

(a) Solve T(n)=3T(n/3)+nT(n) = 3T(n/3) + n with a recursion tree (build the full level table).

(b) Solve T(n)=2T(n/2)+n2T(n) = 2T(n/2) + n^2 and say why the root dominates.

(c) Solve T(n)=T(n−1)+2T(n) = T(n-1) + 2, T(1)=0T(1) = 0, by expansion.

Your mastery check
Not started
Solve the problem above with no hints, close the page and explain it out loud. Tick each step honestly.
Mastery checklist

Status

Tick all six steps to unlock “Mastered”.

Which study mode worked for you?

Saved in this browser onlySee all my progress →

See it move

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

On this page