Courses / Computer Science I
Algorithmics

Divide-and-Conquer Reasoning

Computer Science I 265 words Free to read

Split, Solve, Combine

Divide-and-conquer is a powerful algorithmic pattern with three steps: divide the problem into smaller subproblems of the same kind, conquer each subproblem (recursively, until they are trivially small), and combine their solutions into a solution for the whole.

Merge sort is the model example: divide the list into two halves, recursively sort each (conquer), and merge the sorted halves (combine). Binary search is a degenerate divide-and-conquer that discards one half and recurses on the other. Many fast algorithms — fast exponentiation, closest-pair-of-points, fast Fourier transform, Karatsuba multiplication — follow the same shape.

The efficiency comes from the shrinking. When each step splits the problem into halves, the recursion has depth about logn\log n, and if the combine step is cheap enough, the whole runs far faster than a linear scan repeated. The cost is captured by a recurrence like T(n)=2T(n/2)+O(n)T(n) = 2\,T(n/2) + O(n), which solves to O(nlogn)O(n \log n) (this is merge sort's cost: two half-size subproblems plus a linear merge). The Master Theorem is a shortcut for solving such recurrences.

The pattern works when a problem has two features: it decomposes into independent subproblems of the same type, and their solutions combine cheaply into the whole answer. When both hold, divide-and-conquer often turns a quadratic brute force into an O(nlogn)O(n \log n) method.

Common pitfall: applying divide-and-conquer when the combine step is expensive, or the subproblems overlap (solve the same thing repeatedly). If subproblems overlap, plain divide-and-conquer redoes work exponentially — that is exactly the situation where dynamic programming (which stores subproblem answers) is the right tool instead.

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

10practice questions
2interactive scenes
Start Computer Science I free

Algorithmics