3.1.7 · D4Complexity Analysis

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

2,557 words12 min readBack to topic

Reminder of the three cases (the referee's rulebook):

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

Level 1 — Recognition

Goal: read off , , compute , and name the case. No algebra beyond a logarithm.

L1.1 . Find and the answer.

Recall Solution L1.1
  • . Leaf cost .
  • . Since , is polynomially smaller (, e.g. ).
  • Case 1 → leaves win. .

L1.2 . Name the case and give the answer.

Recall Solution L1.2
  • . Leaf cost .
  • — exactly equal, . Case 2 (tie).
  • (this is Merge Sort).

L1.3 . Name the case and give the answer.

Recall Solution L1.3
  • . Leaf cost .
  • — tie with . Case 2.
  • (this is Binary Search).

Level 2 — Application

Goal: verify a regularity condition, handle a Case 3, and a Case 1 with fractional .

L2.1 . Solve, showing the regularity check.

Recall Solution L2.1
  • . Leaf cost .
  • with — polynomially bigger. Candidate Case 3.
  • Regularity: with . ✓
  • Case 3 → root wins. .

L2.2 . Solve. (This is Karatsuba Multiplication.)

Recall Solution L2.2
  • . Leaf cost .
  • , and , so . Polynomially smaller.
  • Case 1 → leaves win. — beats schoolbook .

L2.3 . Solve, showing the regularity check.

Recall Solution L2.3
  • . Leaf cost .
  • — exactly equal, . Case 2.
  • (No regularity check needed — that is only for Case 3.)
  • .

Level 3 — Analysis

Goal: spot the log-factor gap, and cases where the naive exponent comparison misleads you.

L3.1 . Solve carefully.

Recall Solution L3.1
  • . Leaf cost .
  • Is polynomially bigger than ? For Case 3 we'd need for some . But grows slower than any , so no such exists. Case 3 fails — there is only a log gap, not a polynomial gap.
  • Rewrite , i.e. Case 2 with .
  • .

L3.2 . Solve.

Recall Solution L3.2
  • . Leaf cost .
  • Case 2 with (equal up to a log factor).
  • .

L3.3 . Solve.

Recall Solution L3.3
  • , leaf cost . Here .
  • Case 2 requires ; here the exponent on is , so basic Case 2 does not apply.
  • is slightly smaller than , but not by a polynomial factor, so Case 1 also fails. This falls in the gap below the tie. (Recognition point: not solvable by the three cases as stated.)
  • Show the WHY with a recursion tree. Level has nodes, each of size , so its cost is =4^i\cdot\frac{n^2/4^i}{\log n - i}=\frac{n^2}{\log n - i}.$$ The $4^i$ cancels — **every level costs $\dfrac{n^2}{\log n-i}$**, so we add these up.
  • Summing over levels : =n^2\!\!\sum_{j=1}^{\log_2 n}\frac1{j}\qquad(\text{substitute } j=\log n-i).$$ That inner sum $1+\tfrac12+\tfrac13+\cdots+\tfrac1{\log_2 n}$ is a **harmonic sum**, which grows like $\ln(\text{number of terms})=\Theta(\log\log n)$ (the log of $\log_2 n$).
  • Therefore . The extra is exactly that harmonic sum — Recursion Trees shows it directly; Akra–Bazzi method gives the same via its integral.

Level 4 — Synthesis

Goal: recognize when the theorem does NOT apply, and translate a real algorithm into a recurrence.

L4.1 Can the Master Theorem solve ? If not, what do you use and what is the answer?

Recall Solution L4.1
  • The two subproblems have different sizes ( and ). The theorem's form assumes all subproblems are the same size . Master Theorem does not apply.
  • Use Recursion Trees or Akra–Bazzi method. Every level does combine work (the child sizes sum to ), and the tree has levels (longest path shrinks by the branch each time).
  • .

L4.2 A function processes an array of size by making 7 recursive calls on subarrays of size , then does combine work. Write the recurrence and solve it. (This mirrors naive -way matrix ideas.)

Recall Solution L4.2
  • Recurrence: .
  • . Leaf cost .
  • , and , so — polynomially smaller.
  • Case 1 → leaves win. .

L4.3 Strassen-style: . Which case, and why is it a borderline?

Recall Solution L4.3
  • . Leaf cost .
  • is exactly (same exponent) — Case 2 with .
  • .
  • Borderline because 's exponent equals ; a hair smaller and it would be Case 1, a hair larger (polynomially) and it would be Case 3.

Level 5 — Mastery

Goal: full derivations from the geometric series, boundary reasoning, and building intuition from Geometric Series.

L5.1 For with , the sum of per-level costs is a geometric series with ratio . Show how the sign of decides which case you're in, using the ratio .

Recall Solution L5.1
  • First, how many levels are there? Sizes shrink and bottom out at when , i.e. . So , the number of levels, is .
  • Level cost with .
  • The total is where — a Geometric Series. Its behaviour depends on :
    • ⟹ series converges to a constant ⟹ root dominatesCase 3.
    • ⟹ every term equal, terms ⟹ Case 2.
    • ⟹ series dominated by its last term (leaves), Case 1.
  • Now translate : , so
    • : bigger than leaf cost → Case 3. ✓
    • : tie → Case 2. ✓
    • : smaller → Case 1. ✓
  • This is why the three cases exist: they are the three regimes of a geometric series.
Figure — Master theorem — solving recurrences T(n) = aT(n - b) + f(n)

L5.2 Solve from the geometric series directly (don't just quote the case).

Recall Solution L5.2
  • , and , so exponent .
  • Number of levels: .
  • Level cost . Every level costs (ratio ).
  • Sum the equal level-costs over all levels:
  • So directly from the series, — matching Case 2 with .

L5.3 Solve . Which case, and what makes "polynomially bigger"?

Recall Solution L5.3
  • . Leaf cost .
  • grows faster than any polynomial , so certainly . Candidate Case 3.
  • Regularity: . Since is astronomically smaller than (ratio ), for large we have with easily. ✓
  • Case 3 → root wins. .

L5.4 Boundary probe: solve . Explain why neither Case 1 nor basic Case 2 fits.

Recall Solution L5.4
  • , leaf cost . Here , i.e. .
  • Basic Case 2 needs ; is outside it. And is smaller than only by a log factor, not a polynomial one, so Case 1 fails too. Gap below the tie.
  • Direct sum: level cost ; summing gives
  • The inner sum is a harmonic sum (the sum of reciprocals ), which grows like the natural log of its number of terms, i.e. .
  • Therefore — provable by recursion tree, not by the three-case theorem.


Connections

  • Recursion Trees — the derivation behind L5, and the fallback for L3.3, L4.1, L5.4.
  • Akra–Bazzi method — solves the unequal-split cases the theorem can't (L4.1).
  • Geometric Series — the engine of L5.1 that produces the three cases.
  • Big-O, Big-Omega, Big-Theta — the "polynomially smaller/bigger" comparisons.
  • Merge Sort, Binary Search, Karatsuba Multiplication — appear as L1/L2 problems.

Flashcards

Solve .
, → Case 1 → .
In Case 2, what does the exponent mean?
is the power of already sitting in when written as ; the answer gains one more log: .
Solve .
Only a log gap, so it is Case 2 with (here ) → .
Why can't Master Theorem solve ?
Subproblems differ in size; the form needs identical sizes. Use recursion tree / Akra–Bazzi → .
What ratio governs which case you're in, and its formula?
where is 's exponent; Case 1, Case 2, Case 3.
Solve .
, every level costs , and there are levels → .