DSATime ComplexityCases 1–3

Master Theorem Visualizer

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

compare n^{log_b a} vs f(n)

current_action

Set a, b and the exponent of f(n) = n^c.

classifier.py

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

decision log

Ready

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))

complexity.md

OperationTime
Classify a,b,fO(1) arithmetic
Merge sort a=2,b=2,c=1Case 2 → O(n log n)
Binary search a=1,b=2,c=0Case 2 → O(log n)
Space—