3.1.7 · D3Complexity Analysis

Worked examples — Master theorem — solving recurrences T(n) = aT(n - b) + f(n)

3,214 words15 min readBack to topic

This page is a shooting range. The parent note on T(n) = aT(n / b) + f(n) gave you the three cases. Here we fire a bullet at every target: each case, the tricky ties, the degenerate inputs (, constant), the log-gap trap that lives between the cases, a real-world word problem, and an exam-style twist that looks like one case but is another.

Before any example, three reminders in plain words so nothing is used before it is built.

Look at the picture below: the same recursion tree drawn three ways. The red shape is whichever pile wins. That single picture is the whole theorem.

Figure — Master theorem — solving recurrences T(n) = aT(n - b) + f(n)
Figure s01 — a horizontal bar chart shown in three side-by-side panels; each panel stacks five bars, one per tree level, with the root at the top and the leaf row at the bottom, and the bar length is the total work done on that level. Left panel (Case 1, leaves win): bars grow longer as you go down, and the longest bar — the bottom leaf row — is drawn in red, so the leaf pile dominates. Middle panel (Case 2, tie): all five bars are the same length and each is outlined in red, showing every floor costs the same, so you pay per floor (). Right panel (Case 3, root wins): bars shrink as you go down, and the longest bar — the top root row — is drawn in red, so the root/combine pile dominates. A red arrow in each panel points at the winning bar with a short label ("leaf pile biggest" / "all floors equal" / "root pile biggest").


The scenario matrix

Every recurrence the basic theorem can eat falls into exactly one of these cells. The examples that follow are each tagged with the cell they hit, so you can see the whole board is covered.

Cell What makes it this cell Answer shape Example #
A — Case 1, leaves win polynomially smaller than 1
A′ — Case 1, degenerate constant combine, 2
B — Case 2, plain tie , no extra log 3
C — Case 2, degenerate tree is a single stick, 4
D — Case 3, root wins polynomially bigger + regularity holds 5
E — Case 3 regularity fails bigger but theorem refuses; must fall back 6
F — the log-gap trap bigger only by a log, not a polynomial extended Case 2, 7
G — real-world word problem translate prose → first whichever case results 8
H — exam twist (looks like X, is Y) disguised leaf cost / hidden trap-aware answer 9

The "signs/quadrants" of this topic are which pile wins (leaves / tie / root); the degenerate inputs are (single stick, cell C) and (constant combine, cell A′). We hit them all.


The worked examples


What every cell taught you

Recall One-line lesson per cell (click to reveal)
  • A: many subproblems, cheap combine → count leaves, .
  • A′: constant with → leaves still win, (Case 1).
  • B: equals the ruler → tie → .
  • C: single stick, ruler is .
  • D: big and regularity → .
  • E: big-looking but oscillating → theorem refuses; use Akra–Bazzi.
  • F: bigger only by a log → extended Case 2, extra .
  • G: word problems = translate to first, then it's routine.
  • H: smaller only by a log → still Case 2 (), .

Connections

  • Parent topic
  • Recursion Trees — the fallback when a cell (like E) breaks the theorem.
  • Akra–Bazzi method — handles the oscillating- Example 6.
  • Big-O, Big-Omega, Big-Theta — the language every comparison used.
  • Geometric Series — why leaves/tie/root correspond to shrinking/flat/growing series.
  • Merge Sort, Binary Search, Karatsuba Multiplication — real algorithms behind cells B, C, A.