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: nn-bit intergers xx and yy

Output: the product xyxy

procedure multiply(x,yx,y)

if n=1n=1 then

return xyxy

xL,xRx_L, x_R and yL,yRy_L, y_R are the left-most and right-most n/2n/2 bits of xx and yy respectively

P1P_1 = multiply(xL,yLx_L, y_L)

P2P_2 = multiply(xL,yRx_L, y_R)

P3P_3 = multiply(xR,yLx_R, y_L)

P4P_4 = multiply(xR,yRx_R, y_R)

return P1×2n+(P2+P3)×2n/2+P4P_1 \times 2^n + (P_2 + P_3) \times 2^{n/2} + P_4

  • 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: nn-bit integers xx and yy

Output: the product xyxy

procedure multiplyKS(x,yx,y)

if n=1n=1 then

return xyxy

xL,xRx_L, x_R and yL,yRy_L, y_R are the left-most and right-most n/2n/2 bits of xx and yy respectively

R1R_1 = multiplyKS(xL,yLx_L, y_L)

R2R_2 = multiplyKS(xR,yRx_R, y_R)

R3R_3 = multiplyKS((xL+xR)(yL+yR)(x_L + x_R)(y_L + y_R))//(xL+xR)(yL+yR)=xLyL+xLyR+xRyL+xRyR(x_L + x_R)(y_L + y_R) = x_Ly_L + x_Ly_R + x_Ry_L + x_Ry_R

return R1×2n+(R3R1R2)×2n/2+R2R_1 \times 2^n + (R_3 - R_1 - R_2) \times 2^{n/2} + R_2

  • 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:

DeterministicRandomized
SortingComputer Science Introduction/Algorithms/Divide and Conquer/Merge SortQuick Sort — Best: , Worst: , Average:
SelectionDeterministic Selection (Median of Medians) — QuickSelect — Best: , Worst: , Average:

Quick Reference Table

AlgorithmRecurrenceMaster Theorem CaseClosed-Form Runtime
Classic Multiply ()
Karatsuba (Multiply KS) ()

Notes in This Section

NoteOne-line description
Computer Science Introduction/Algorithms/Divide and Conquer/Binary SearchHalves the search space each comparison on a sorted array;
Cook-Toom-k AlgorithmGeneralizes Karatsuba’s trick to split into parts instead of 2, trading extra combine-step overhead for fewer recursive multiplications
Deterministic SelectionMedian-of-medians (BFPRT) — splits into groups of 5 to construct a provably-good pivot, guaranteeing worst case without randomization
SortingFoundational note for this family ― the decision tree argument for the comparison-sort lower bound
Computer Science Introduction/Algorithms/Divide and Conquer/Merge SortSplits the array in half, recursively sorts each half, merges the two sorted halves;
Quick SortPartitions around a pivot, recursively sorts each side; expected, worst case
QuickSelectQuick Sort-style partitioning used to find the smallest element directly, via a random pivot; expected, worst case
SelectionThe 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 RunnersBinary search for the “turning point” where a slower-starting runner overtakes a faster one — a discrete analogue of the Intermediate Value Theorem;

References / Links