About

Framework and the Master Theorem

Divide-and-Conquer and the Master Theorem

Divide-and-conquer solves a problem instance by dividing it into several smaller subproblems of the same type, solving each subproblem recursively, and then combining their solutions to form a solution to the original instance.

Diagram loads as you scroll.


The General Divide-and-Conquer Recurrence

If an algorithm divides a problem of size nn into aa subproblems of size n/bn/b, with f(n)f(n) effort spent on dividing and combining:

T(n)=a⋅T(n/b)+f(n)T(n) = a \cdot T(n / b) + f(n)

where:


The Master Theorem

The Master Theorem provides an immediate asymptotic solution for standard divide-and-conquer recurrences.

Theorem Statement

If T(n)=aT(n/b)+f(n)T(n) = a T(n / b) + f(n) where f(n)∈Θ(nd)f(n) \in \Theta(n^d) with d≥0d \ge 0:

T(n)∈{Θ(nd)if a<bdΘ(ndlog⁡n)if a=bdΘ(nlog⁡ba)if a>bdT(n) \in \begin{cases} \Theta(n^d) & \text{if } a < b^d \\ \Theta(n^d \log n) & \text{if } a = b^d \\ \Theta(n^{\log_b a}) & \text{if } a > b^d \end{cases}

Intuitive Interpretation

Compare the rate of subproblem branching (aa) with the rate of shrinkage (bdb^d):

  1. a<bda < b^d (Root-dominated): The combining work at the root f(n)=Θ(nd)f(n) = \Theta(n^d) dominates the work done by recursive leaves. Result is Θ(nd)\Theta(n^d).
  2. a=bda = b^d (Balanced work): Work is evenly distributed across all log⁡bn\log_b n levels of the recursion tree. Result is Θ(ndlog⁡n)\Theta(n^d \log n).
  3. a>bda > b^d (Leaf-dominated): Subproblems multiply so rapidly that the vast majority of work is done at the leaves (nlog⁡ban^{\log_b a} base instances). Result is Θ(nlog⁡ba)\Theta(n^{\log_b a}).

Master Theorem Examples & Lookup Reference

Recurrenceaabbf(n)f(n)ddComparisonComplexityTypical Algorithm
T(n)=T(n/2)+1T(n) = T(n/2) + 112Θ(1)\Theta(1)01=201 = 2^0Θ(log⁡n)\Theta(\log n)Binary Search
T(n)=2T(n/2)+nT(n) = 2T(n/2) + n22Θ(n)\Theta(n)12=212 = 2^1Θ(nlog⁡n)\Theta(n \log n)Merge Sort
T(n)=3T(n/2)+nT(n) = 3T(n/2) + n32Θ(n)\Theta(n)13>213 > 2^1Θ(nlog⁡23)≈Θ(n1.585)\Theta(n^{\log_2 3}) \approx \Theta(n^{1.585})Karatsuba Multiplication
T(n)=4T(n/2)+nT(n) = 4T(n/2) + n42Θ(n)\Theta(n)14>214 > 2^1Θ(nlog⁡24)=Θ(n2)\Theta(n^{\log_2 4}) = \Theta(n^2)Naive D&C Multiplication
T(n)=7T(n/2)+n2T(n) = 7T(n/2) + n^272Θ(n2)\Theta(n^2)27>22=47 > 2^2=4Θ(nlog⁡27)≈Θ(n2.807)\Theta(n^{\log_2 7}) \approx \Theta(n^{2.807})Strassen’s Matrix Mult
T(n)=2T(n/2)+n2T(n) = 2T(n/2) + n^222Θ(n2)\Theta(n^2)22<22=42 < 2^2=4Θ(n2)\Theta(n^2)Root-dominated D&C

Exercises

Exercise 1

Apply the Master Theorem to solve:

T(n)=8T(n/2)+1000n2T(n) = 8 T(n / 2) + 1000 n^2

State the values of a,b,da, b, d, the case condition, and the final complexity.

Show solution ↓
Solution
  • a=8a = 8
  • b=2b = 2
  • f(n)=1000n2  ⟹  f(n)∈Θ(n2)  ⟹  d=2f(n) = 1000 n^2 \implies f(n) \in \Theta(n^2) \implies d = 2

Compute bd=22=4b^d = 2^2 = 4. Since a=8>bd=4a = 8 > b^d = 4, this falls under Case 3 (Leaf-dominated):

T(n)∈Θ(nlog⁡ba)=Θ(nlog⁡28)=Θ(n3)T(n) \in \Theta(n^{\log_b a}) = \Theta(n^{\log_2 8}) = \Theta(n^3)
Exercise 2

Can the standard Master Theorem formula be directly applied to T(n)=2T(n/2)+nlog⁡nT(n) = 2T(n/2) + n \log n? Explain why or why not.

Show solution ↓
Solution

The standard version of the Master Theorem requires f(n)∈Θ(nd)f(n) \in \Theta(n^d) for a constant polynomial exponent dd. Here, f(n)=nlog⁡nf(n) = n \log n, which contains an extra logarithmic factor not expressible as a single ndn^d.

Using the extended Master Theorem (Case 2 with k=1k = 1):

T(n)=aT(n/b)+Θ(nlog⁡balog⁡kn)T(n) = a T(n/b) + \Theta(n^{\log_b a} \log^k n)

Since a=2,b=2  ⟹  nlog⁡22=n1a = 2, b = 2 \implies n^{\log_2 2} = n^1, this evaluates to:

T(n)∈Θ(nlog⁡k+1n)=Θ(nlog⁡2n)T(n) \in \Theta(n \log^{k+1} n) = \Theta(n \log^2 n)