3.1.9 · D3Complexity Analysis

Worked examples — Recursion tree method

3,822 words17 min readBack to topic
Figure — Recursion tree method

The scenario matrix

Every recurrence you can throw at a recursion tree lands in exactly one of these cells. The examples below are labelled with the cell they cover.

In cell C4 below, and are just the two shrink fractions of an unbalanced split: one child gets a fraction of the work (size ) and the other gets a fraction (size ), with . For instance in Ex 4.

# Cell (scenario class) Signature Verdict Example
C1 Ratio decreasing levels root wins: Ex 2, Ex 5
C2 Ratio balanced levels tie + : Ex 1
C3 Ratio increasing levels leaves win: Ex 3
C4 Unbalanced tree (two shrink fractions ) bound by height range Ex 4
C5 Degenerate branching one child, no widening chain, not a tree Ex 5
C6 Subtract, don't divide linear-depth tree Ex 6
C7 Limiting / boundary tiny vs leaves or edge case Ex 7
C8 Real-world word problem must extract from prose any of above Ex 8
C9 Exam twist — sneaky hidden looks like C1/C3, is C2 catch the tie Ex 9

Related tools you will see leaning on this: Master Theorem (the shortcut), Geometric Series (the summing engine), Big-O Notation (the bounding language), and Divide and Conquer (where these recurrences come from).


Worked Example 1 — Cell C2 (balanced):

Here , , so .

Figure — Recursion tree method
  1. Compute the ratio . Why this step? tells us instantly whether we are in C1, C2, or C3 without drawing anything — it is the growth factor of the per-level work.
  2. Read the picture: every level costs the same . Level has nodes each of size , so its work is . Look at the coral bars in the figure — they are all the same height. Why this step? literally means "next level's total = this level's total", so the work is a flat stack.
  3. Count the levels. Size halves until it hits : . Including level that is levels. Why this step? Total = (per-level work) (number of levels) only when levels are equal.
  4. Multiply.

Worked Example 2 — Cell C1 (root wins):

Here , , so .

  1. Ratio. . Why this step? is Cell C1 — the level sums form a decreasing geometric series.
  2. Write the level sum. . Why this step? Confirms the ratio symbolically; the makes each level smaller than the last.
  3. Sum the geometric series — and why the infinite bound is legal. The exact answer is the finite sum . Because every term is positive, adding more terms only makes the sum larger; so the finite sum is the infinite sum: Since the sum is also its first term , we get — trapped between two constants. So is . Why this step? Replacing a finite sum by the infinite one is only valid when terms are positive (so the infinite sum is a genuine upper bound) and the ratio is (so that upper bound is finite). Both hold here.
  4. Verdict. . The root dominates.

Worked Example 3 — Cell C3 (leaves win):

Here , , so .

Figure — Recursion tree method
  1. Ratio. . Why this step? is Cell C3 — level sums grow going down; the bottom is fattest.
  2. Level sum. . Look at the figure: bars double each level. Why this step? Confirms growth; now the last term dominates, not the first.
  3. Sum an increasing geometric series. Its total is dominated by its last term. Number of levels , so the last level's work is . Why this step? For , sum last term, which equals the leaf cost .
  4. Verdict. Leaves count . So , leaves win.

Worked Example 4 — Cell C4 (unbalanced):

Figure — Recursion tree method
  1. Per-level work — upper bound. At each full level the child sizes sum to at most the parent size, because . Since is linear, the sum of costs across that level is . Why this step? When is linear, "sum of sizes" "sum of costs", so lopsidedness doesn't change the per-level total — it stays capped at .
  2. Per-level work — lower bound (near the top). For the first levels the fast branch has not yet bottomed out, so all subproblems on that level are still alive and their sizes still add up to exactly . Hence each of those top levels costs (a constant times) too. So per level the work is for those levels, not merely . Why this step? Without a lower bound we could only prove ; to also get we must show many levels each genuinely cost about .
  3. Shortest path (fastest shrink). Follow the branch: . This is the shallow side. Why this step? Gives a lower bound on total depth, and (with step 2) at least full-cost levels.
  4. Longest path (slowest shrink). Follow the branch: . This is the deep side (see the long butter-colored path in the figure). Why this step? Gives an upper bound on depth; the deepest path sets the tree height.
  5. Combine. Total is at least (step 2: levels each costing about ) and at most (step 1: levels each costing ). All these logs differ only by constant factors (, etc.), so both bounds are in the class : Why this step? An upper bound alone gives ; a lower bound alone gives ; squeezing between two bounds of the same class is exactly what proves the tight . Steps 1–2 supplied the per-level costs, steps 3–4 supplied the two level counts, and here we multiply and combine.

Worked Example 5 — Cell C1 & C5 (single child):

Here , , so .

  1. Ratio. . Cell C1 (and C5, since means no widening — a straight line of nodes). Why this step? collapses the tree to a chain; the sum is still geometric.
  2. Level sum. . Why this step? Each node is alone, so per-level work is just the single node's cost, halving each step.
  3. Sum. . Why this step? Decreasing geometric → bounded by twice the first term.
  4. Verdict. . Root (the ) dominates.

Worked Example 6 — Cell C6 (subtract, not divide):

  1. Height. Size drops . That is levels — linear depth, not log. Why this step? Subtraction gives a long thin chain; there is no to take a log with.
  2. Per-level work. One node per level (branching ), of size , costing . Why this step? Establishes each row's contribution.
  3. Sum. Add every level's cost: Why this step? This is an arithmetic (not geometric) series — the classic triangle; its closed form is .
  4. Verdict. , whose top-order term is , so The Master Theorem does not apply here (it needs division); the tree method still works.

Worked Example 7 — Cell C7 (limiting, tiny ):

Here , , so .

  1. Ratio. . A limiting case: the local work is so tiny () that branching always wins. Why this step? Constant () makes , so automatically — the boundary where is as small as it can be.
  2. Level sum. — pure doubling, driven only by node count. Why this step? With no size-dependent work, cost = number of nodes.
  3. Sum. . Why this step? Geometric with ; total last term = leaf count.
  4. Verdict. . Leaves win; total = number of nodes .

Worked Example 8 — Cell C8 (real-world word problem)

  1. Extract . "three sub-piles" → ; "size " → ; "scan the whole pile once, steps" → , so . Why this step? Turn prose into the three knobs before any math.
  2. Ratio. . Cell C2 (balanced). Why this step? Ties the word problem to a matrix cell.
  3. Per-level & depth. Each level costs . The size hits when , and counting the root level as well gives levels. Why this step? Balanced levels → total = per-level × levels, so we need the exact level count including the top row (the "" for level ).
  4. Total. . Why this step? Because step 2 showed every level costs the same (the flat-stack case), the total is simply (per-level cost ) (number of levels ); the constant and the base of the log are swallowed by (a base change is only a constant factor).

Worked Example 9 — Cell C9 (exam twist, hidden tie):

Here , , and so .

  1. Rewrite as a clean power. , so . Why this step? You cannot compute the ratio until the local work is written as ; leaving it as "" hides the exponent and invites the trap.
  2. Compute honestly — this is where the trap lives. , which is exactly . So Why this step? The reflex is to eyeball "small , big shrink → root wins (C1)". But equals , making a tie (C2), not a root case. Doing the exponent by hand is the only safeguard.
  3. Confirm the tie by direct cancellation. Level has nodes each of size , so its work is The cancels — every level costs the same , the flat-stack signature of . Why this step? Re-deriving the per-level work from scratch double-checks the ratio verdict; if the had not cancelled, we'd know we mislabelled the cell.
  4. Count levels and multiply. Size hits at ; including level that is levels. Since levels are equal, Why this step? Balanced levels mean total = (per-level cost ) (number of levels); the and the log base vanish inside .

Recall Master checklist for ANY recurrence

Compute (or find the height if there's no clean ): Cell C1 () ::: Root wins, — decreasing geometric. Cell C2 () ::: Balanced, — flat levels. Cell C3 () ::: Leaves win, — increasing geometric. Cell C4 (two shrink rates ) ::: Bound by height range . Cell C6 (subtract ) ::: Linear depth, use arithmetic series, Master Theorem does NOT apply.


Connections