Divide and Conquer
Overview
Divide and conquer is an algorithm design paradigm with three steps:
- Divide the problem into smaller subproblems of the same type.
- Conquer the subproblems by solving them recursively. If a subproblem is small enough, solve it directly (base case).
- Combine the solutions to the subproblems into a solution for the original problem.
The paradigm works best when subproblems are independent (no overlap) and the combine step is cheap relative to the recursive work.
Canonical Examples
| Algorithm | Divide | Conquer | Combine |
|---|---|---|---|
| Mergesort | Split array into two halves | Recursively sort each half | Merge the two sorted halves () |
| Quicksort | Partition around a pivot | Recursively sort left and right partitions | Nothing (trivial concatenation) |
| Binary search | Compare with midpoint | Recurse on left or right half | Nothing (answer propagated up) |
Recurrence Relations
Divide-and-conquer algorithms naturally lead to recurrences of the form:
where subproblems of size are solved recursively, and is the cost of dividing and combining.
Solving Recurrences
Recurrences of the form are solved using the Master Theorem, which has three cases based on comparing against . The detailed statement, worked examples, the recursion-tree method, and guidance on when the theorem does not apply are covered there.
When Divide-and-Conquer Works Well
- Subproblems are independent — no overlapping work.
- The division yields subproblems of roughly equal size (ratio splits, not constant-sized subproblems). Even a 25%-75% split yields for quicksort.
- The combine step is efficient — ideally or less.
Warning: splitting off a constant-sized subproblem (e.g. ) leads to behaviour. This is the degenerate case of quicksort with a bad pivot.
Summary
| Property | Value |
|---|---|
| Paradigm | Divide, conquer, combine |
| Recurrence form | |
| Solving tool | Master Theorem (3 cases) |
| Optimal split | Equal-sized subproblems |
| Worst split | Constant-sized subproblem leads to |
| Key examples | Mergesort, quicksort, binary search, Strassen’s algorithm |