This is a comprehensive question about the Master Theorem for analyzing recurrence relations. Let me provide a thorough explanation with multiple examples to illustrate all three cases.
First, let me recall the Master Theorem:
The Master Theorem applies to recurrence relations of the form:
T(n) = a·T(n/b) + f(n)
where:
- a ≥ 1 and b > 1 are constants
- f(n) is an asymptotically positive function
- T(n) is defined for positive integers
The theorem has three cases:
Case 1: If f(n) = O(n^log_b(a) - ε) for some constant ε > 0, then T(n) = Θ(n^log_b(a))
Case 2: If f(n) = Θ(n^log_b(a) · log^k(n)) for some constant k ≥ 0, then T(n) = Θ(n^log_b(a) · log^(k+1)(n))
Case 3: If f(n) = Ω(n^log_b(a) + ε) for some constant ε > 0, and if a·f(n/b) ≤ c·f(n) for some constant c < 1 and sufficiently large n (regularity condition), then T(n) = Θ(f(n))
Let me work through several examples:
Example 1: T(n) = 2T(n/2) + n
-
a = 2, b = 2, f(n) = n
-
n^log_b(a) = n^log_2(2) = n^1 = n
-
Compare: f(n) = n and n^log_b(a) = n
-
f(n) = Θ(n^log_b(a) · log^0(n)), so this is Case 2 with k = 0
-
T(n) = Θ(n · log(n))
Example 2: T(n) = 2T(n/2) + 1
- a = 2, b = 2, f(n) = 1
- n^log_b(a) = n
- Since f(n) = 1 is polynomially smaller than n, this falls under Case 1
- T(n) = Θ(n)
Example 3: T(n) = 3T(n/2) + n^2
- a = 3, b = 2, f(n) = n^2
- n^log_b(a) = n^log_2(3) ≈ n^1.585
- Since f(n) = n^2 dominates n^1.585, this is Case 3
- Checking the regularity condition: 3·(n/2)^2 ≤ c·n^2 gives 3/4 < 1, so it holds
- T(n) = Θ(n^2)
Example 4: T(n) = 3T(n/4) + n
- a = 3, b = 4, f(n) = n
- n^log_b(a) ≈ n^0.792
- f(n) = n grows faster than n^0.792, and the regularity condition is satisfied
- T(n) = Θ(n)
Example 5: T(n) = 2T(n/2) + n·log(n)
- a = 2, b = 2, f(n) = n·log(n)
- n^log_b(a) = n
- f(n) = n·log(n) is larger than n but not polynomially so, matching Case 2
- T(n) = Θ(n · log^2(n))
Master Theorem: Complete Analysis Guide
Master Theorem Framework
For recurrence relations of the form:
T(n)=a⋅T(n/b)+f(n)
Where:
- a ≥ 1, b > 1 (constants)
- f(n) = asymptotically positive function
- n^log_b(a) = dividing-and-conquering term
Three Cases
| Case | Condition | Result |
|---|
| 1 | f(n) = O(n^(log_b(a) - ε)) | T(n) = Θ(n^log_b(a)) |
| 2 | f(n) = Θ(n^log_b(a) · log^k(n)), k≥0 | T(n) = Θ(n^log_b(a) · log^(k+1)(n)) |
| 3 | f(n) = Ω(n^(log_b(a) + ε)) + regularity | T(n) = Θ(f(n)) |
Example 1: Merge Sort - Case 2
T(n) = 2T(n/2) + n
Step 1: Identify Parameters
a = 2 (two recursive calls)
b = 2 (each call processes n/2)
f(n) = n (merge operation)
Step 2: Calculate n^log_b(a)
n^log_2(2) = n^1 = n
Step 3: Compare f(n) with n^log_b(a)
f(n) = n
n^log_b(a) = n
f(n) = Θ(n · log^0(n)) ✓ Matches Case 2 with k=0
Step 4: Apply Case 2 Formula
T(n) = Θ(n^log_b(a) · log^(k+1)(n))
T(n) = Θ(n · log^(0+1)(n))
Result: T(n) = Θ(n log n) ✓
Example 2: Binary Search - Case 1
T(n) = 1·T(n/2) + 1
Step 1: Identify Parameters
a = 1
b = 2
f(n) = 1
Step 2: Calculate n^log_b(a)
n^log_2(1) = n^0 = 1
Step 3: Compare
f(n) = 1
n^log_b(a) = 1
Is f(n) = O(1 - ε) for some ε > 0?
No, they're equal → Check if Case 2 applies
f(n) = Θ(1 · log^0(n)) = Θ(log^0(n))
Actually, this is Case 2 with k=0, where n^log_b(a) = 1
Result: T(n) = Θ(log n) ✓
Example 3: Strassen Matrix Multiplication - Case 1
T(n) = 7·T(n/2) + n^2
Step 1: Identify Parameters
a = 7
b = 2
f(n) = n^2
Step 2: Calculate n^log_b(a)
n^log_2(7) = n^2.807...
Step 3: Compare
f(n) = n^2
n^log_b(a) = n^2.807
Is n^2 = O(n^(2.807 - ε))?
YES ✓ for ε = 0.807
This is Case 1
Result: T(n) = Θ(n^2.807) ✓
Example 4: Dividing Problem - Case 3
T(n) = 3·T(n/4) + n^2
Step 1: Identify Parameters
a = 3
b = 4
f(n) = n^2
Step 2: Calculate n^log_b(a)
n^log_4(3) = n^0.792...
Step 3: Compare
f(n) = n^2
n^log_b(a) = n^0.792
Is n^2 = Ω(n^(0.792 + ε))?
YES ✓ for ε = 1.208
Check REGULARITY CONDITION:
a·f(n/b) ≤ c·f(n)?
3·(n/4)^2 ≤ c·n^2?
3n^2/16 ≤ c·n^2?
c = 3/16 < 1 ✓
This is Case 3
Result: T(n) = Θ(n^2) ✓
Example 5: With Logarithmic Factor - Case 2
T(n) = 2·T(n/2) + n·log(n)
Step 1: Identify Parameters
a = 2
b = 2
f(n) = n·log(n)
Step 2: Calculate n^log_b(a)
n^log_2(2) = n
Step 3: Compare
f(n) = n·log(n) = Θ(n · log^1(n))
n^log_b(a) = n = Θ(n · log^0(n))
Matches Case 2 with k = 1
Step 4: Apply Formula
T(n) = Θ(n · log^(1+1)(n))
Result: T(n) = Θ(n log² n) ✓
Decision Tree
┌─ Identify a, b, f(n) from T(n) = a·T(n/b) + f(n)
│
├─ Calculate c = log_b(a)
│
├── Is f(n) = O(n^(c-ε)) for some ε > 0?
│ ├─ YES → CASE 1: T(n) = Θ(n^c)
│ │
│ ├─ NO: Is f(n) = Θ(n^c · log^k(n)) for some k≥0?
│ ├─ YES → CASE 2: T(n) = Θ(n^c · log^(k+1)(n))
│ │
│ ├─ NO: Is f(n) = Ω(n^(c+ε)) for some ε > 0?
│ ├─ YES: Check regularity condition
│ │ ├─ If satisfied → CASE 3: T(n) = Θ(f(n))
│ │ └─ If not → Master Theorem doesn't apply
│ └─ NO → Master Theorem doesn't apply
Summary Table
| Problem | Recurrence | Parameters | Case | Result |
|---|
| Merge Sort | 2T(n/2)+n | a=2,b=2 | 2 | Θ(n log n) |
| Binary Search | T(n/2)+1 | a=1,b=2 | 2 | Θ(log n) |
| Strassen | 7T(n/2)+n² | a=7,b=2 | 1 | Θ(n^2.807) |
| Example | 3T(n/4)+n² | a=3,b=4 | 3 | Θ(n²) |
| Heap Sort | 2T(n/2)+n log n | a=2,b=2 | 2 | Θ(n log² n) |
This comprehensive approach ensures accurate analysis of divide-and-conquer algorithms!