title: "Master Theorem Guide"
description: "Complete reference for applying the Master Theorem to solve divide-and-conquer recurrence relations with detailed examples and case analysis."
category: "algorithm-analysis"
difficulty: "intermediate"
tags: ["master-theorem", "recurrence-relations", "divide-conquer", "complexity-analysis", "mathematical-analysis"]
estimatedTime: "15 minutes"
lastUpdated: "2025-01-10"
Enhanced SEO fields
seo_title: "Master Theorem Cheat Sheet: Solve Recurrence Relations"
seo_description: "Master the Master Theorem with this comprehensive reference covering all three cases, examples, and step-by-step solutions for divide-and-conquer algorithms."
seo_keywords: ["master theorem cheat sheet", "recurrence relations", "divide and conquer", "complexity analysis", "algorithm analysis", "mathematical solutions"]
canonical_url: "https://clelandco.com/cheat-sheets/algorithm-analysis/master-theorem"
cover_image: "/images/cheat-sheets/algorithm-analysis/master-theorem-cover.jpg"
target_audience: "Computer Science Students, Algorithm Analysts, Software Engineers"
content_type: "reference-guide"
prerequisites: ["Basic calculus", "Logarithm properties", "Asymptotic notation"]
sectionCount: 6
downloadCount: 0
Master Theorem
📋 The Setup
Form: T(n)=aT(n/b)+f(n)
- a ≥ 1 = number of recursive subproblems
- b > 1 = factor by which problem size shrinks
- f(n) = work done outside recursive calls (divide + combine)
Key Insight: Compare f(n) with n^(log_b a) to determine which dominates
🧮 Essential Logarithm Rules
logb(bx)=xExample: log2(23)=3
logb(a)=log(b)log(a)Example: log2(4)=log(2)log(4)=2
logb(xy)=logb(x)+logb(y)Example: log2(8⋅4)=log2(8)+log2(4)=3+2=5
logb(xk)=k⋅logb(x)Example: log2(n3)=3⋅log2(n)
Most Critical: n^(log_b a) represents the "breakeven point"
🎯 The Three Cases
Case 1: Recursion Dominates 🔴
When: f(n)=O(nlogba−ε) for some ε>0
Result: T(n)=Θ(nlogba)
Memory Trick: "Recursion wins" → Answer is just nlogba
Case 2: Perfect Balance 🟡
When: f(n)=Θ(nlogba⋅logkn) for some k≥0
Result: T(n)=Θ(nlogba⋅logk+1n)
Memory Trick: "Tied game" → Answer gets an extra log factor
Case 3: Outside Work Dominates 🟢
When: f(n)=Ω(nlogba+ε) AND regularity condition holds
Result: T(n)=Θ(f(n))
Memory Trick: "Outside work wins" → Answer is just f(n)
Regularity Condition: a⋅f(n/b)≤c⋅f(n) for some c<1
🔍 Step-by-Step Process
Step 0: Preprocessing - Combine Identical Terms ⚠️
CRITICAL: Before applying Master Theorem, check if you can combine identical recursive terms:
T(n)=T(n/3)+T(n/3)+n=2T(n/3)+n✓ Can combine
T(n)=T(n/2)+T(n/3)+nCannot combine - different sizes×
Step 1: Identify Components
- Extract a, b, and f(n) from T(n)=aT(n/b)+f(n)
Step 2: Calculate Critical Exponent
- Compute c=logba
- This gives you nc=nlogba
Step 3: Compare and Classify
- Compare f(n) with nc
- Determine which case applies
Step 4: Apply Formula
- Use the corresponding case formula
📊 Common Examples
Recurrence | a | b | f(n) | logba | Case | Solution |
---|
T(n)=2T(n/2)+n | 2 | 2 | n | log22=1 | Case 2 | Θ(nlogn) |
T(n)=4T(n/2)+n | 4 | 2 | n | log24=2 | Case 1 | Θ(n2) |
T(n)=2T(n/2)+n2 | 2 | 2 | n2 | log22=1 | Case 3 | Θ(n2) |
T(n)=3T(n/3)+n | 3 | 3 | n | log33=1 | Case 2 | Θ(nlogn) |
T(n)=9T(n/3)+n | 9 | 3 | n | log39=2 | Case 1 | Θ(n2) |
T(n)=T(n/2)+1 | 1 | 2 | 1 | log21=0 | Case 2 | Θ(logn) |
💡 Worked Examples
Example 1: Merge Sort
T(n)=2T(n/2)+n
- Identify: a=2, b=2, f(n)=n
- Calculate: logba=log22=1, so nlogba=n1=n
- Compare: f(n)=n=Θ(n1log0n)
- Case: Case 2 with k=0
- Solution: T(n)=Θ(n1log0+1n)=Θ(nlogn)
Example 2: Binary Search
T(n)=T(n/2)+1
- Identify: a=1, b=2, f(n)=1
- Calculate: logba=log21=0, so nlogba=n0=1
- Compare: f(n)=1=Θ(1⋅log0n)
- Case: Case 2 with k=0
- Solution: T(n)=Θ(1⋅log0+1n)=Θ(logn)
Example 3: Matrix Multiplication (Strassen)
T(n)=7T(n/2)+n2
- Identify: a=7, b=2, f(n)=n2
- Calculate: logba=log27≈2.807, so nlogba=n2.807
- Compare: f(n)=n2=O(n2.807−ε) for ε=0.8
- Case: Case 1
- Solution: T(n)=Θ(nlog27)=Θ(n2.807)
🚫 Common Mistakes
❌ Wrong: Forgetting to combine identical terms
T(n) = T(n/2) + T(n/2) + n
→ "This doesn't fit Master Theorem form"
✅ Correct: T(n)=2T(n/2)+n → Apply Master Theorem
❌ Wrong: Misidentifying f(n)
T(n) = 2T(n/2) + 3n + 5
→ f(n) = 3n (ignoring the constant)
✅ Correct: f(n)=3n+5=Θ(n)
❌ Wrong: Incorrect logarithm calculation
T(n) = 4T(n/2) + n
→ log₂(4) = 4 ❌
✅ Correct: log2(4)=2
🎯 Quick Reference Card
When you see: T(n)=aT(n/b)+f(n)
- Calculate: c=logba
- Compare f(n) with nc:
- If f(n)<nc → Case 1 → Θ(nc)
- If f(n)=nclogkn → Case 2 → Θ(nclogk+1n)
- If f(n)>nc → Case 3 → Θ(f(n))
Most Common Results:
- Binary Search: Θ(logn)
- Merge Sort: Θ(nlogn)
- Matrix Multiplication: Θ(n3) (naive) or Θ(n2.807) (Strassen)