Solving recurrences II: the master theorem
◈ 6 cardsThe three cases around the watershed n^(log_b a), the regularity condition, the gap case, and an empirical demonstration that merge sort is Θ(n lg n).
The cookbook for divide-and-conquer recurrences
The master theorem solves any master recurrence
in one of three cases. The whole method turns on comparing the driving function to the watershed function . That watershed counts the leaves of the recursion tree: the tree has of them.
The three cases
Let .
- Case 1 — leaves win. If for some (i.e. is polynomially smaller than ), then .
- Case 2 — tie. If for some , then — the cost is shared across all levels, and one extra log factor is tacked on. The common subcase : gives .
- Case 3 — root wins. If for some and the regularity condition holds for some and all large , then .
The in cases 1 and 3 demands polynomial separation: a mere logarithmic gap between and falls outside the theorem.
Worked classifications
- (merge sort): , ⟶ case 2, ⟶ .
- : , so ; ⟶ case 1 (leaves dominate) ⟶ .
- (binary-search shape): , , ⟶ case 2, ⟶ .
- : , , and regularity holds with ⟶ case 3 ⟶ .
- : , ⟶ case 2 with ⟶ . (Common slip: this is not .)
The gap case — when no case applies
: here and , pointing toward case 1 — but is not for any (it trails only by a log factor, not a polynomial one). Case 2 also fails (). The recurrence falls in the gap between cases 1 and 2 and needs another tool (Akra–Bazzi gives ).
Empirical check
You can't time wall-clock deterministically, but you can count the exact work merge sort does. On a reverse-sorted input each merge does moves per level over levels, so total moves exactly — and the ratio moves is a flat constant as grows. The exercise below shows that constant.