TheoremComplete

Recurrence Relations - Applications

The Master Theorem is a powerful tool for analyzing divide-and-conquer algorithms, providing asymptotic solutions to a broad class of recurrence relations without requiring detailed calculation.

DefinitionMaster Theorem

Let a1a \geq 1 and b>1b > 1 be constants, and let f(n)f(n) be a function. Consider the recurrence: T(n)=aT(n/b)+f(n)T(n) = aT(n/b) + f(n)

where we interpret n/bn/b as either n/b\lfloor n/b \rfloor or n/b\lceil n/b \rceil. Then:

Case 1: If f(n)=O(nc)f(n) = O(n^c) where c<logbac < \log_b a, then T(n)=Θ(nlogba)T(n) = \Theta(n^{\log_b a}).

Case 2: If f(n)=Θ(nclogkn)f(n) = \Theta(n^c \log^k n) where c=logbac = \log_b a and k0k \geq 0, then T(n)=Θ(nclogk+1n)T(n) = \Theta(n^c \log^{k+1} n).

Case 3: If f(n)=Ω(nc)f(n) = \Omega(n^c) where c>logbac > \log_b a, and if af(n/b)kf(n)af(n/b) \leq kf(n) for some constant k<1k < 1 and sufficiently large nn (regularity condition), then T(n)=Θ(f(n))T(n) = \Theta(f(n)).

Intuition:

The recurrence T(n)=aT(n/b)+f(n)T(n) = aT(n/b) + f(n) describes an algorithm that:

  • Divides a problem of size nn into aa subproblems of size n/bn/b
  • Performs f(n)f(n) work to divide and combine

The recursion tree has height logbn\log_b n (depth of recursion) and aia^i nodes at level ii, each with work f(n/bi)f(n/b^i).

Total work: i=0logbn1aif(n/bi)+Θ(nlogba)\sum_{i=0}^{\log_b n - 1} a^i f(n/b^i) + \Theta(n^{\log_b a})

The three cases compare f(n)f(n) with nlogban^{\log_b a} (the number of leaves):

  • Case 1: Leaf-dominated: most work is in base cases
  • Case 2: Balanced: work is evenly distributed across levels
  • Case 3: Root-dominated: most work is in dividing/combining

Proof Sketch (Case 1):

Assume f(n)=O(nc)f(n) = O(n^c) where c<logbac < \log_b a. Let ϵ=logbac>0\epsilon = \log_b a - c > 0.

At level ii of the recursion tree, there are aia^i nodes, each doing f(n/bi)C(n/bi)cf(n/b^i) \leq C(n/b^i)^c work.

Total work at level ii: aiC(n/bi)c=Cnc(a/bc)ia^i \cdot C(n/b^i)^c = Cn^c \cdot (a/b^c)^i

Since c<logbac < \log_b a, we have a/bc>1a/b^c > 1, so work increases geometrically with depth.

Summing over all logbn\log_b n levels: T(n)=i=0logbn1Cnc(a/bc)i+Θ(nlogba)T(n) = \sum_{i=0}^{\log_b n - 1} Cn^c(a/b^c)^i + \Theta(n^{\log_b a})

The geometric series is dominated by its last term, which is O(nc(a/bc)logbn)=O(nlogba)O(n^c \cdot (a/b^c)^{\log_b n}) = O(n^{\log_b a}).

Therefore, T(n)=Θ(nlogba)T(n) = \Theta(n^{\log_b a}). \square

ExampleCommon Applications

Merge Sort: T(n)=2T(n/2)+Θ(n)T(n) = 2T(n/2) + \Theta(n)

  • Here a=2a = 2, b=2b = 2, f(n)=Θ(n)f(n) = \Theta(n), so logba=1\log_b a = 1
  • Case 2 with k=0k = 0: T(n)=Θ(nlogn)T(n) = \Theta(n \log n)

Binary Search: T(n)=T(n/2)+Θ(1)T(n) = T(n/2) + \Theta(1)

  • Here a=1a = 1, b=2b = 2, f(n)=Θ(1)f(n) = \Theta(1), so logba=0\log_b a = 0
  • Case 2 with k=0k = 0: T(n)=Θ(logn)T(n) = \Theta(\log n)

Strassen's Matrix Multiplication: T(n)=7T(n/2)+Θ(n2)T(n) = 7T(n/2) + \Theta(n^2)

  • Here a=7a = 7, b=2b = 2, f(n)=Θ(n2)f(n) = \Theta(n^2), so logba=log272.807\log_b a = \log_2 7 \approx 2.807
  • Case 1 since 2<2.8072 < 2.807: T(n)=Θ(nlog27)Θ(n2.807)T(n) = \Theta(n^{\log_2 7}) \approx \Theta(n^{2.807})
Remark

The Master Theorem doesn't cover all recurrences. For instance, T(n)=2T(n/2)+nlognT(n) = 2T(n/2) + n \log n falls in the gap between Cases 2 and 3. The Akra-Bazzi method generalizes to handle variable partition sizes and more complex combining costs. For recurrences with multiple recursive calls of different sizes (like T(n)=T(n/3)+T(2n/3)+nT(n) = T(n/3) + T(2n/3) + n), more sophisticated analysis or the Akra-Bazzi method is required.