3.1.7 · D1Complexity Analysis

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

1,881 words9 min readBack to topic

Before you can trust the formula, you must be able to point at a picture for every letter in . This page builds each one from nothing, in the order they depend on each other.


0. What is ? (the size of the problem)

Picture a row of boxes. If you have 8 numbers to sort, . Everything in this topic asks: as grows huge, how does the running time grow? We never care about small ; we care about the trend.

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

1. What is ? (the running-time function)

The word recurrence below just means: defined in terms of smaller copies of itself. That is the shape of every divide-and-conquer cost.


2. The recurrence — reading it left to right

This one line is the entire topic. Read it as a sentence:

"The time to solve size equals ( copies of the time to solve a shrunken problem of size ) plus the extra work I do myself at this level."

Three new symbols live here. We define each with its picture.

2a. — how many subproblems you make

Picture one box that splits into arrows pointing down to smaller boxes.

2b. — how fast the problem shrinks

2c. — the work you do yourself at this level

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

3. Powers and — counting down the tree

To read the tree we need (" multiplied by itself times").

Why do we need it? Because at level of the recursion tree, each subproblem has size and there are of them. Powers are simply the bookkeeping for "how deep are we, and how many boxes are there."


4. Logarithms — the height of the tree

Here is the tool that scares people. We introduce it because we must answer one specific question: how many times can I divide by before I hit size 1?

The stopping condition of the tree: size . That is the height — the number of floors in the building.

Figure — Master theorem — solving recurrences T(n) = aT(n - b) + f(n)
Recall Why is the tree's height only

and not ? (click) Because we divide each step, not subtract. Dividing 1,000,000 by 2 reaches 1 in ~20 steps, not a million. Shrinking is exponentially fast → the height is a logarithm. :::


5. The two log identities you'll actually use

Plain-words proof of the swap: write , so We just reshuffled the exponents (multiplication of exponents commutes) and used .


6. — the critical exponent

Picture: the bottom row of the tree has tiny boxes. That is the "pile of chores at the bottom." The entire Master Theorem is one comparison — race against .

  • big (many branches) → more leaves → big → leaf pile heavy.
  • big (fast shrink) → shorter tree → fewer leaves → smaller.

7. Asymptotic symbols — the comparison ruler

The three cases say " is smaller", "equal", "bigger". Those words need a precise meaning that ignores constants and only cares about the growth trend.


8. Geometric series — why there are exactly three cases

See Geometric Series. When we add up the work across all levels of the tree, level- cost divided by level- cost is a constant ratio . Those three behaviours of are exactly Case 1, Case 2, Case 3 — leaves win, tie (multiply by height), root wins. The three cases are not arbitrary; they are the three moods of a geometric series.

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

Prerequisite map

n = input size

T(n) = running-time function

recurrence T(n) = a T(n/b) + f(n)

a = branch count

b = shrink factor

f(n) = combine work

powers b^i

logarithm log_b n = tree height

c_crit = log_b a

Big-O Omega Theta ruler

compare f(n) vs n^c_crit

geometric series moods

three cases

Master Theorem answer


Equipment checklist

means
the size / count of the input, and we only care how things grow as .
is
a function returning the number of steps to solve a size- problem.
In , what is ?
the number of subproblems you split into (branching factor).
What is ?
the factor the input shrinks by each level; subproblems have size , and .
What is ?
the split + combine work done at the current level, outside the recursive calls.
Are and constants or variables?
constants — fixed by the algorithm; only changes.
What does count?
how many times you divide by to reach 1 — the height of the recursion tree.
Why is the tree height a logarithm, not ?
because you divide (not subtract) each step, so size collapses exponentially fast.
State the identity that rewrites the leaf count.
.
What does represent physically?
the total cost of all the leaves at the bottom of the tree.
Difference between , , ?
= upper bound (), = lower bound (), = tight (), all ignoring constants.
Why must the gap between and be a power of (the )?
a mere gap isn't enough for Case 1 or 3; it lands in extended Case 2 instead.
Which three moods of a geometric series map to the three cases?
leaves win, tie (×height), root wins.