What are the three steps of divide-and-conquer, and where does the recursion stop?
Divide the input into disjoint parts, recur by solving each part with the same algorithm, then conquer by combining the partial solutions into the solution for the whole. The recursion stops at subproblems of size 0 or 1, which need no work at all.
Divide-and-conquer is a design pattern, not one particular algorithm. For sorting a sequence $S$ it reads:
- Divide: split $S$ into (usually two) disjoint parts $S_1$ and $S_2$.
- Recur: sort $S_1$ and $S_2$ by calling the same algorithm on each part.
- Conquer: combine the two sorted parts into the sorted $S$.
The recursion needs a floor, the base case: a sequence with 0 or 1 elements is already sorted, so the call returns it unchanged. Every other call hands strictly smaller problems to its recursive calls, so the recursion is guaranteed to reach that floor. Insertion-sort starts from the same fact: its sorted part begins as the first element alone, because a single element is always sorted.
The pattern leaves open where the real work happens, and the two classic sorts answer that in opposite ways: merge-sort splits blindly in the middle and does its comparisons when combining, quick-sort does its comparisons when splitting and combines by simply writing the parts one after the other.
Go deeper:
Divide-and-conquer algorithm โ the paradigm with its classic examples, from binary search to fast multiplication.