Section Overview
- Divide and Conquer: break a problem into similar subproblems, solve each subproblem recursively, then combine the results.
- Every algorithm in this section produces a recurrence of the form , which the Master Theorem below solves in closed form — it’s the one tool that ties this whole section together.
Divide and Conquer (The Paradigm)
-
Break a problem into similar subproblems.
-
Solve each subproblem recursively.
-
Combine the subproblem results into a solution for the original problem.
-
Key detail: subproblems must be smaller instances of the same problem — that’s what makes the recursion terminate and what makes Master Theorem-style analysis applicable in the first place.
Multiplying n-bit Numbers (Classic Recursive Approach)
Suppose we want to multiply two -bit numbers, a power of 2. Split each into left/right halves of bits each:
The boxed terms are recursive calls at half the size.
Algorithm 14 Algorithm Multiply
Input: -bit intergers and
Output: the product
procedure multiply()
if then
return
and are the left-most and right-most bits of and respectively
= multiply()
= multiply()
= multiply()
= multiply()
return
- Time Complexity: (3 additions + 2 bit shifts of -bit integers, plus 4 recursive calls) → Master Theorem with : since (), .
- Key detail: this is asymptotically no better than grade-school multiplication — the 4-way recursive split doesn’t actually help until you reduce the number of subproblems (see Karatsuba below).
Karatsuba’s Algorithm (Multiply KS)
Algorithm 15 Multiply KS
Input: -bit integers and
Output: the product
procedure multiplyKS()
if then
return
and are the left-most and right-most bits of and respectively
= multiplyKS()
= multiplyKS()
= multiplyKS()//
return
- Time Complexity: → Master Theorem with : since (), .
- Key detail: the trick is computing once and subtracting off to recover the two cross terms — turning 4 recursive multiplications into 3, which is what drops the exponent below 2.
Master Theorem
If for constants , then
Solving the Recurrence
After levels of recursion, there are subproblems, each of size . Work at level :
After levels, subproblem size shrinks to 1 (the base case), so the total is the sum over all levels:
This is a geometric series with ratio .
Proof (Three Cases)
Case 1 — (): the series converges to a constant, so .
Case 2 — (): every term equals 1, so the sum is just the number of terms:
Case 3 — (): the sum is exponential and grows proportional to its last term:
Recall
Deterministic vs. Randomized Approaches
Sorting and Selection each have a deterministic and a randomized solution, trading a worse worst-case bound for a simpler algorithm and better typical-case performance:
| Deterministic | Randomized | |
|---|---|---|
| Sorting | Computer Science Introduction/Algorithms/Divide and Conquer/Merge Sort — | Quick Sort — Best: , Worst: , Average: |
| Selection | Deterministic Selection (Median of Medians) — | QuickSelect — Best: , Worst: , Average: |
Quick Reference Table
| Algorithm | Recurrence | Master Theorem Case | Closed-Form Runtime |
|---|---|---|---|
| Classic Multiply | () | ||
| Karatsuba (Multiply KS) | () |
Notes in This Section
| Note | One-line description |
|---|---|
| Computer Science Introduction/Algorithms/Divide and Conquer/Binary Search | Halves the search space each comparison on a sorted array; |
| Cook-Toom-k Algorithm | Generalizes Karatsuba’s trick to split into parts instead of 2, trading extra combine-step overhead for fewer recursive multiplications |
| Deterministic Selection | Median-of-medians (BFPRT) — splits into groups of 5 to construct a provably-good pivot, guaranteeing worst case without randomization |
| Sorting | Foundational note for this family ― the decision tree argument for the comparison-sort lower bound |
| Computer Science Introduction/Algorithms/Divide and Conquer/Merge Sort | Splits the array in half, recursively sorts each half, merges the two sorted halves; |
| Quick Sort | Partitions around a pivot, recursively sorts each side; expected, worst case |
| QuickSelect | Quick Sort-style partitioning used to find the smallest element directly, via a random pivot; expected, worst case |
| Selection | The general “find the smallest element” problem, plus the shared in-place Partition with Pivot subroutine; QuickSelect and Deterministic Selection are the two algorithms solving it |
| Two Runners | Binary search for the “turning point” where a slower-starting runner overtakes a faster one — a discrete analogue of the Intermediate Value Theorem; |