DAA Module 4 Divide & Conquer

11 β€” Master Theorem

Solve recurrences like T(n)=aT(n/b)+f(n) by comparing f(n) with n^(log_b a).

← Back

Quick Rule β€” Master Theorem

Concept First

Master Theorem is used to solve recurrences of the form T(n) = aT(n/b) + f(n). The key idea is to compare the extra work f(n) with the boundary function nlogb(a).

3-Step Recipe
  1. Identify: a = number of subproblems, b = input shrink factor, f(n) = non-recursive work
  2. Compute boundary: p = logb(a), boundary = np
  3. Compare: Compare f(n) with np
What is k ? (Very Important)
k is the power of log n already present in f(n).

Examples:
  • f(n) = n β†’ no log term β†’ k = 0
  • f(n) = n log n β†’ one log β†’ k = 1
  • f(n) = n log2 n β†’ two logs β†’ k = 2
🟒 Case 1 β€” f(n) is smaller than boundary
If f(n) = O( np βˆ’ Ξ΅ ) for some Ξ΅ > 0
T(n) = Θ( np )
πŸ‘‰ Smaller work per level, leaves dominate
🟑 Case 2 β€” f(n) matches the boundary
If f(n) = Θ( np · logk n )
(k = number of log factors already in f(n))
T(n) = Θ( np · logk+1 n )
πŸ‘‰ Each recursion level contributes equally β†’ one extra log
πŸ”΄ Case 3 β€” f(n) is bigger than boundary
If f(n) = Ξ©( np + Ξ΅ ) for some Ξ΅ > 0
T(n) = Θ( f(n) )
πŸ‘‰ Root work dominates (regularity condition required)

Interactive Solver

Auto Case
p = log_b(a)
β€”
n^p
β€”
Detected Case
β€”
Final Result
β€”

Examples (Click to Load)

Practice
Recurrence
T(n)=2T(n/2)+n
Answer
Θ(n log n)

Recursion Tree Intuition

Why it works
LevelCost(i) = a^i Β· f(n / b^i)
Height is about log_b(n). Total cost depends on which levels dominate.
Case intuition
  • Case 1: leaves dominate β†’ Θ(n^p)
  • Case 2: each level same β†’ extra log factor
  • Case 3: root dominates β†’ Θ(f(n))

Mini Quiz

Auto-check
1) T(n)=2T(n/2)+n
2) T(n)=T(n/2)+1
3) Case for T(n)=4T(n/2)+n