Divide and conquer is a fundamental algorithm design paradigm that recursively breaks a problem into independent subproblems, solves each, and combines their solutions. It underpins the most efficient known algorithms for sorting, searching, matrix multiplication, polynomial multiplication, and geometric problems — and its performance is analyzed through recurrence relations solved by the Master Theorem, recursion tree method, or substitution method.
What This Cheat Sheet Covers
This topic spans 13 focused tables and 78 indexed concepts, 74 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Core Paradigm and Design Principles
The three-phase structure (divide → conquer → combine) defines every divide-and-conquer algorithm. Understanding these phases and their cost contributions is the foundation for analyzing any D&C algorithm via its recurrence relation.
| Technique | Example | Description | |
|---|---|---|---|
Merge sort: split array at midpoint $mid = \lfloor (lo + hi)/2 \rfloor$ | • Splits the problem into $a$ subproblems each of size $n/b$ • ideally $O(1)$ or $O(n)$ work | ||
Recursively sort left half and right half | • Solves each subproblem recursively • base case handles $n \leq$ threshold directly | ||
Merge two sorted halves in $O(n)$ | • Merges subproblem solutions • this cost appears as $f(n)$ in the recurrence $T(n) = aT(n/b) + f(n)$. | ||
if n <= 1: return (sort trivially sorted list) | • Smallest subproblem solved directly • must be reached to prevent infinite recursion | ||
$T(n) = aT(n/b) + f(n)$ | Mathematical model capturing total work: $a$ = subproblems, $b$ = size reduction factor, $f(n)$ = non-recursive work. | ||
Merge sort left and right halves share no elements | • D&C requires subproblems to be independent (no shared state) • overlapping subproblems → use dynamic programming instead | ||
Merge sort depth $= \log_2 n$ levels | • Depth $= \log_b n$ • determines stack space usage $O(\log_b n)$ and total number of recursive calls $a^{\log_b n} = n^{\log_b a}$. | ||
Binary search: $T(n) = T(n/2) + O(1)$ | • Special case with $a = 1$: only one subproblem per level • reduces rather than divides | ||
Merge sort on arrays achieves good cache behavior without explicit tile sizes | D&C recursion naturally produces cache-friendly access patterns at all cache levels without tuning. |