3.1.7 · D2Complexity Analysis

Visual walkthrough — Master theorem — solving recurrences T(n) = aT(n - b) + f(n)

2,801 words13 min readBack to topic

Step 0 — Reading the equation out loud (nothing assumed)

We will use the running example throughout, so you can watch the abstract tree fill in with real numbers.


Step 1 — Draw the recursion tree and count its DEPTH

WHAT. We expand once: it becomes boxes of plus one box of glue . Then we expand each of those, and so on, until the size hits the base.

WHY. The total cost is just the sum of glue-work over every box in the tree plus the cost of the bottom row. To add them we must first know how tall the tree is and how wide each row is. Height comes first because it decides how many rows we sum.

WHAT IT LOOKS LIKE. Look at the figure: the size label drops by at every level — — a straight staircase, not a plunge. It reaches the base size (a constant ) after


Step 2 — Count the NODES on each level (the width explodes)

WHAT. Each box spawns children. So one root box becomes boxes, then , then

WHY. The bottom-row cost = (number of leaves) (cost of one leaf). If , the number of boxes multiplies every level, and after levels this is an astronomically large number. We need its exact size to know whether the leaves dominate.

WHAT IT LOOKS LIKE. In the figure the row widths are — a widening funnel. The red bottom row is by far the widest.


Step 3 — The two rival costs (the race)

WHAT. As before, two costs fight: the leaf cost (bottom row, ) versus the root-glue cost ( at the top).

WHY. We compare them to see who dominates the sum. But here the shapes of the two contestants are wildly different, so the comparison rule is not the same as the divide theorem.

WHAT IT LOOKS LIKE. Two curves in the figure: leaf cost (a steep exponential, when ) versus (a polynomial, e.g. , ). Since we assumed is polynomial (Step 0), the exponential eventually crushes it — so if the leaves always win. If , there is exactly one box per level and the race becomes a simple sum.


Step 4 — Case : the leaves win (exponential blow-up)

WHAT. With and polynomial , we claim — the leaf row, full stop, with no extra factor.

WHY. Sum the glue over all levels and add the leaf row: Each summand is (nodes on level ) (glue per node). Because grows exponentially while the polynomial can only shrink, the summands increase toward the bottom — a growing Geometric Series, which is dominated by its last summand. That last summand and the leaf row are both . So the whole sum is : the polynomial contributes only lower-order terms and does not multiply the answer.

WHAT IT LOOKS LIKE. In the figure the bar heights climb steeply toward the bottom; the tallest bar (the leaves) is essentially the whole area.


Step 5 — Case : no fan-out, just add up the chain

WHAT. With every box has exactly one child. The tree is a single vertical chain of boxes. So

WHY. There is no multiplication of nodes ( per level), so the total is a plain sum of the glue values as the size steps down , plus one constant base cost. There is no "leaves vs root" race — there is only the sum. Its size depends entirely on the shape of .

WHAT IT LOOKS LIKE. The figure is a single column of boxes; the glue values are like the heights of a staircase, and we are measuring the area under that staircase.


Step 6 — The full case table (cover every input)


The one-picture summary

This final figure stacks the two worlds side by side: on the left, the chain whose cost is the shaded triangle ; on the right, the funnel whose cost is the exploding red leaf-row . The single decision — does the tree fan out? — routes you to one side or the other.

Recall Feynman: tell it to a 12-year-old (click to reveal)

You have a chore for a pile of size . Each round you shave off a fixed slice (say one item), do a little tidy-up , and hand out copies of the slightly-smaller chore to friends. When a chore is tiny enough it's done in one fixed instant (that's the base case, a constant).

If each round makes exactly one new chore (), it's just one long line: chore of size , then , then , all the way down. You add up the tidy-up work on each of the steps. If each tidy-up costs about , the total is roughly a triangle: steps times up to each .

If each round makes new chores, the pile of chores doubles (or triples) every round, and there are hundreds of rounds because you only shave off one item at a time. The number of tiny chores at the bottom is multiplied by itself times — a colossal exponential . Each of those tiny bottom chores costs only a fixed instant, but there are so many that they bury everything else — so the total is that count , with no leftover tidy-up factor. That's exactly why calling fib(n) the naive recursive way is painfully slow: it forks in two every step and never divides the work.

The one question that decides your fate: does the chore fork () or just march down a line ()? Fork → exponential. Line → sum a polynomial.


Connections

  • Recursion Trees — every figure on this page is a recursion tree; this is the visual engine.
  • Geometric Series — Step 4's "last term dominates" is the growing-geometric-series fact.
  • Big-O, Big-Omega, Big-Theta — the comparison machinery used throughout.
  • Akra–Bazzi method — the general tool when subproblem sizes are mixed or non-constant.
  • Merge Sort, Karatsuba Multiplication, Binary Search — the divide cousins (parent note); contrast their depth with this page's depth.
  • Return to the parent topic.

Flashcards

In , how deep is the recursion tree?
levels — size drops by each level, a linear staircase (not ).
How many leaves does a subtractive tree have when ?
— exponential in .
What is the leaf-row cost, and does multiply the answer in Case ?
Leaf row ; no, is lower-order (leaves cost , not ).
Solve .
(full binary tree of depth ).
Solve .
, so .
When and , what is ?
— sum a polynomial down the chain of length (triangle area).
What two assumptions make the clean subtractive theorem hold?
Base cost and polynomial (); if outgrows the leaves, instead .
Why can't you use for the subtract form?
There is no ratio , only a difference ; is meaningless and gives wrong (polynomial) answers for exponential recurrences.
What single question decides the subtractive case?
Does the tree fan out? exponential; polynomial.