What is the Master Theorem
Master Theorem is a shortcut for the same divide-and-conquer recurrences the tree method solves by hand. Compare the root work f(n) with the leaf work nlogb a. Whichever is polynomially larger decides the bound; if they match, a log n factor appears.
- Case 1: leaves dominate → Θ(n^{log_b a})
- Case 2: levels are even → Θ(n^{log_b a} log n)
- Case 3: root dominates, plus regularity → Θ(f(n))
How this visualizer works
Set a, b and the exponent c of f(n)=n^c. Step through: compute the critical exponent, compare, highlight the case, and read T(n).
Interactive Master Theorem
Set a, b and the exponent of f(n) = n^c.
1Read a, b, f(n) = n^c
2crit = log_b(a)
3if c < crit − ε: Case 1 T = Θ(n^{crit})
4if c == crit: Case 2 T = Θ(n^{crit} log n)
5if c > crit + ε: Case 3 T = Θ(f(n))
6Case 3 also needs the regularity check
The three cases
Case 1 — leaves win.
f(n) = O(n^{crit−ε}) → T(n)=Θ(n^{log_b a})
Case 2 — every level equal.
f(n)=Θ(n^{crit}) → T(n)=Θ(n^{log_b a} log n)
Case 3 — root wins.
f(n)=Ω(n^{crit+ε}) and regularity → T(n)=Θ(f(n))
| Operation | Time |
| Classify a,b,f | O(1) arithmetic |
| Merge sort a=2,b=2,c=1 | Case 2 → O(n log n) |
| Binary search a=1,b=2,c=0 | Case 2 → O(log n) |
| Space | — |