Divide and Conquer

College Depth 64 in the knowledge graph I know this Set as goal
Unlocks 35 downstream topics
divide-and-conquer recursion algorithm-design master-theorem

Core Idea

Divide and conquer solves problems by recursively splitting them into smaller subproblems of the same type, solving each independently, and combining results. The paradigm has three phases: divide (split the problem), conquer (solve recursively), and combine (merge results). The Master Theorem provides a closed-form solution for recurrences of the form T(n) = aT(n/b) + f(n), covering most divide-and-conquer algorithms. Classic applications include merge sort, quicksort, and Strassen's matrix multiplication.

How It's Best Learned

Use merge sort as the canonical example. Explicitly draw the recursion tree for small inputs and verify that the work at each level sums to the predicted total. Practice applying the Master Theorem to derive complexity from recurrences.

Common Misconceptions

Explainer

You know recursion: a function that solves a problem by calling itself on smaller inputs until hitting a base case. Divide and conquer is a specific pattern of recursion with three distinct phases. First, divide the problem into smaller subproblems of the same type. Second, conquer each subproblem by solving it recursively (or directly if it's small enough). Third, combine the subproblem solutions into a solution for the original problem. The key requirement is that the subproblems are *independent* — solving one does not depend on the result of another. This independence is what distinguishes divide and conquer from dynamic programming, where subproblems overlap and share dependencies.

Merge sort is the clearest example to build intuition from. Given an unsorted array, divide it into two halves. Recursively sort each half (conquer). Then merge the two sorted halves into a single sorted array (combine). The merge step walks through both halves simultaneously, always picking the smaller element, producing a sorted result in O(n) time. The key insight is that the hard work happens in the *combine* step, not the divide step — splitting an array in half is trivial, but merging two sorted arrays is where the useful computation occurs. This is common in divide-and-conquer algorithms: the divide step is often simple, and the algorithm's character is defined by how it combines results.

Binary search, which you already know, is actually a degenerate case of divide and conquer where you only recurse on *one* subproblem (the half that might contain your target) and the combine step is trivial (just return the result). This is called decrease and conquer by some authors. True divide and conquer recurses on *all* subproblems. This distinction matters for understanding time complexity: binary search does O(1) work per level with one branch (giving O(log n) total), while merge sort does O(n) work per level with two branches (giving O(n log n) total).

The Master Theorem gives you a shortcut for analyzing divide-and-conquer recurrences of the form T(n) = aT(n/b) + f(n), where *a* is the number of subproblems, *n/b* is each subproblem's size, and f(n) is the cost of dividing and combining. The theorem compares f(n) to n^(log_b(a)): if the divide/combine work grows slower than the recursive branching, the leaves dominate; if it grows faster, the root dominates; if they match, you get a log factor. For merge sort, a = 2, b = 2, f(n) = O(n), and n^(log₂2) = n, so T(n) = O(n log n). Once you internalize this framework, you can analyze any divide-and-conquer algorithm's complexity by simply identifying a, b, and f(n) and checking which case applies.

Practice Questions 5 questions

Prerequisite Chain

Counting to 10Counting to 20Understanding ZeroThe Number ZeroCounting to FiveOne-to-One CorrespondenceCombining Small Groups Within 5Addition Within 10Addition Within 20Two-Digit Addition Without RegroupingTwo-Digit Addition with RegroupingAddition Within 100Repeated Addition as MultiplicationMultiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Two-Digit by One-Digit DivisionDivision with RemaindersRemainders and Quotients in DivisionDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueReading and Writing DecimalsComparing and Ordering DecimalsAdding and Subtracting DecimalsMultiplying DecimalsDividing DecimalsDividing FractionsMixed Number ArithmeticOrder of OperationsInteger Order of OperationsVariable ExpressionsCombining Like TermsOne-Step EquationsTwo-Step EquationsSolving Multi-Step EquationsEquations with Variables on Both SidesLiteral EquationsSlope-Intercept FormPoint-Slope FormWriting Linear EquationsParallel and Perpendicular Line SlopesGraphing Linear EquationsPiecewise FunctionsStep FunctionsComposition of FunctionsInverse FunctionsRadical Functions and GraphsRational ExponentsExponential Functions and GraphsLogarithms IntroductionBig-O Notation and Asymptotic AnalysisAlgorithm Analysis and Complexity ClassesDivide-and-Conquer and the Master TheoremDivide and Conquer

Longest path: 65 steps · 348 total prerequisite topics

Prerequisites (5)

Leads To (5)