3.1.9 · D4Complexity Analysis

Exercises — Recursion tree method

2,722 words12 min readBack to topic

Before we start, one fact we will lean on constantly, drawn once so you never have to re-picture it:

Figure — Recursion tree method

We use this verdict directly in Ex 2.1–2.2 below: s01 is the picture you match each new recurrence against — plot , see which of the three curves it is, read off the winner.


L1 — Recognition

Goal: read the recurrence, name , , , and the three "knobs" (Depth, Width, Work) without solving.

Exercise 1.1

For , state , , , the depth, the number of nodes at level , and the number of leaves.

Recall Solution
  • (four children), (size halves), .
  • Depth: size at level is ; set . So levels (exactly integer since we assume ; otherwise ).
  • Nodes at level : .
  • Leaves: at the bottom level , count .

WHAT this looks like: a tree that gets very bushy — doubling the depth quadruples the width. That leaf count is a red flag that the leaves may dominate (we confirm this in L2).

Exercise 1.2

For (this is Binary Search), give the depth, nodes per level, and total leaves.

Recall Solution
  • , , .
  • Depth: (i.e. for general ).
  • Nodes at level : . The "tree" is a single chain — one node per level.
  • Leaves: . Exactly one leaf.

WHAT this looks like: not a bush at all — a straight vertical stick nodes tall. Total work = nodes .


L2 — Application

Goal: plug into the level-sum, form the ratio , read off the case.

Exercise 2.1

Solve (the Ex 1.1 recurrence). Give a tight bound.

Recall Solution

Here so . Level- work: Ratio increasing geometric series (the rising red curve in s01) → leaves dominate. By the verdict, the sum is of its last term (level ), and positivity of all terms makes that bound tight: Cross-check with Master Theorem: vs ; since grows faster, Case 1 → . ✓

Exercise 2.2

Solve .

Recall Solution

so . Level work: Ratio decreasing (the falling black curve in s01) → root dominates. Sum , and (first term), so it is pinned: The root's sets the answer; everything below adds only a bounded fraction more.

Exercise 2.3

Solve (this is Merge Sort again — confirm the balanced case).

Recall Solution

. Level work for every → ratio (the flat dashed curve in s01). Equal work per level levels:


L3 — Analysis

Goal: recurrences where is not a clean power, or the tree is lopsided — you must reason about level sums directly.

Exercise 3.1

Solve .

Recall Solution

is not a pure , so the plain ratio rule doesn't apply. Compute level work honestly. At level , subproblem size is , so (We used in base 2.) Sum over levels to : The inner sum is — the numbers from up to , which total . Therefore WHAT this looks like: per-level work decreases linearly (not geometrically) as we go down, so we can't just take the first term — we sum an arithmetic-style series, which gives the extra .

Exercise 3.2

Solve the lopsided recurrence . Give a tight bound.

Recall Solution

The two branches shrink at different rates, so there is no single . We use the height range + per-level bound technique. (This is the same idea the parent note applies to : for a lopsided tree, cap the work summed across each level, then bracket the number of levels between the shortest and the longest root-to-leaf path.)

Look at the tree (figure below): at any level, the subproblem sizes add up to at most (since , and this stays deeper down). Because is linear, each level's total work is .

Figure — Recursion tree method
  • Shortest root-to-leaf path: always take the branch → size .
  • Longest root-to-leaf path: always take the branch → size .

So height is between and both are (they differ only by constant factors, since ).


L4 — Synthesis

Goal: combine ideas — non-integer branching, square-root shrink, or a change of variable.

Exercise 4.1

Solve (assume , base case ).

Recall Solution

Size doesn't divide by a constant — it square-roots. The trick: figure out how many square-roots turn into .

After square-roots, the size is . Take twice. Let . Then . We stop when the size reaches the base ( of it ), i.e. when .

The tree is a single chain (branching ), one node per level, each costing . Total nodes = number of levels: WHAT this looks like: the substitution converted "square-root each step" into "halve each step," which we already know gives . Applying to the outside once more gives . See Substitution Method.

Exercise 4.2

Solve and separately identify which of the three cases it is.

Recall Solution

so . Ratio: Level work ; sum . Sanity: leaf count is , which is smaller than , confirming the root (not the leaves) does the heavy lifting. See Divide and Conquer.


L5 — Mastery

Goal: recognise a wrong claim, repair it, and handle degenerate inputs.

Exercise 5.1

A classmate claims: " has per-level work everywhere, and levels, so ." Find and fix the flaw, then give the correct answer.

Recall Solution

The flaw: they used at every level, but must be evaluated at each level's size , not at .

Level- work (writing ): The denominator stays positive only while ; the last valid level is (below that the size hits the constant base case). So the precise summation range is : where is the harmonic number and . With , The classmate's under-counts: the per-level work actually grows as we descend (the denominator shrinks), and the harmonic sum contributes an extra factor.

Exercise 5.2

Handle the degenerate case: what does the recursion tree say about , and about ? Why are these ill-posed?

Recall Solution
  • : the subproblem is the same size ( effectively). Setting size gives , which is never true for — the depth is undefined ( base doesn't exist). Every level adds more unit of work to a problem that never shrinks, so the tree is an infinite chain and the total diverges. No finite solution.
  • : dividing by leaves the size unchanged, so this is the same disease with . Every level has size and costs , giving an infinite chain of 's that never bottoms out. The sum diverges → no finite solution.

LESSON: the recurrence requires . If the problem doesn't shrink, the depth formula blows up, and the tree method (and Master Theorem) simply do not apply. Always check before drawing.

Exercise 5.3

Solve — a case where the ratio is exactly but .

Recall Solution

. Ratio . Balanced! Level work: Equal work per level levels: This is the "" balanced case — same mechanism as merge sort, just with per level instead of .


Self-check ladder

Pure power , clean
Compute ratio ; read the case (root / balanced / leaves).
= or (log factor)
Sum directly; you'll get an arithmetic or harmonic series → extra or factor.
Lopsided (two different fractions)
Bound per-level work ; find shortest and longest path for the height range; sandwich.
Size square-roots ()
Substitute to linearise, count levels, then re-log.
(size doesn't shrink)
Ill-posed — the problem never gets smaller, depth is undefined, so the tree never terminates and the method does not apply.

Connections