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 n into a subproblems of size n/b, with f(n) effort spent on dividing and combining:
T(n)=a⋅T(n/b)+f(n)
where:
a≥1: number of subproblems.
b>1: factor by which subproblem size is reduced.
f(n): non-recursive work to divide the input and combine the sub-results (often f(n)∈Θ(nd) for d≥0).
The Master Theorem
The Master Theorem provides an immediate asymptotic solution for standard divide-and-conquer recurrences.
Compare the rate of subproblem branching (a) with the rate of shrinkage (bd):
a<bd (Root-dominated): The combining work at the root f(n)=Θ(nd) dominates the work done by recursive leaves. Result is Θ(nd).
a=bd (Balanced work): Work is evenly distributed across all logbn levels of the recursion tree. Result is Θ(ndlogn).
a>bd (Leaf-dominated): Subproblems multiply so rapidly that the vast majority of work is done at the leaves (nlogba base instances). Result is Θ(nlogba).
Master Theorem Examples & Lookup Reference
Recurrence
a
b
f(n)
d
Comparison
Complexity
Typical Algorithm
T(n)=T(n/2)+1
1
2
Θ(1)
0
1=20
Θ(logn)
Binary Search
T(n)=2T(n/2)+n
2
2
Θ(n)
1
2=21
Θ(nlogn)
Merge Sort
T(n)=3T(n/2)+n
3
2
Θ(n)
1
3>21
Θ(nlog23)≈Θ(n1.585)
Karatsuba Multiplication
T(n)=4T(n/2)+n
4
2
Θ(n)
1
4>21
Θ(nlog24)=Θ(n2)
Naive D&C Multiplication
T(n)=7T(n/2)+n2
7
2
Θ(n2)
2
7>22=4
Θ(nlog27)≈Θ(n2.807)
Strassen’s Matrix Mult
T(n)=2T(n/2)+n2
2
2
Θ(n2)
2
2<22=4
Θ(n2)
Root-dominated D&C
Exercises
Exercise 1
Apply the Master Theorem to solve:
T(n)=8T(n/2)+1000n2
State the values of a,b,d, the case condition, and the final complexity.
Show solution ↓Hide solution ↑
Solution
a=8
b=2
f(n)=1000n2⟹f(n)∈Θ(n2)⟹d=2
Compute bd=22=4.
Since a=8>bd=4, this falls under Case 3 (Leaf-dominated):
T(n)∈Θ(nlogba)=Θ(nlog28)=Θ(n3)
Exercise 2
Can the standard Master Theorem formula be directly applied to T(n)=2T(n/2)+nlogn? Explain why or why not.
Show solution ↓Hide solution ↑
Solution
The standard version of the Master Theorem requires f(n)∈Θ(nd) for a constant polynomial exponent d.
Here, f(n)=nlogn, which contains an extra logarithmic factor not expressible as a single nd.
Using the extended Master Theorem (Case 2 with k=1):