The master theorem
The master theorem gives the running time of divide-and-conquer algorithms directly.
Rules
- T(n) = a · T(n/b) + n^k
- k < log_b(a): Θ(n^log_b a)
- k = log_b(a): Θ(n^k log n)
- k > log_b(a): Θ(n^k)
Your turn
Three problems on this topic. Separate lists with commas.
- 1 · Master theorem
- 2
- 3
Use the master theorem to find the running time.
T(n) = 4 · T(n/2) + 1
Running time
Worked example
Use the master theorem to find the running time.
T(n) = 1 · T(n/3) + 1
Worked solution
- 1log₃(1) = 0
- 2Compare with k = 0: equal, case 2.
- 3Θ(log n)
Typical mistake: What matters is comparing log_b(a) with the exponent k of f(n) = nᵏ.
Common questions
When does it not apply?
When the subproblems are not of equal size or a < 1.
