Divide and Conquer and Recurrences

Algorithms · Advanced Placement

Divide and Conquer and Recurrences: the big picture

Divide and conquer solves a problem by splitting it into smaller instances of the same problem, solving those recursively and combining the results. Merge sort is the canonical example: divide the array in half, sort each half recursively and merge the two sorted halves in linear time, giving a recurrence whose solution is linearithmic. Binary search divides the problem in half but discards one half rather than recursing on both, giving a logarithmic recurrence. The cost of such an algorithm is captured by a recurrence relation, and three methods solve them. The substitution method guesses a bound and proves it by induction, which is reliable but requires the guess. The recursion-tree method draws the tree of recursive calls, computes the cost at each level and sums the levels, which both yields the answer and suggests the guess for a substitution proof. The master theorem covers recurrences of the standard divide-and-conquer form, comparing the work done in the recursive calls against the work done in dividing and combining, and gives the solution in three cases according to which dominates. Changing variables handles some non-standard forms, and the Akra–Bazzi method generalises the master theorem to unequal subproblem sizes.

Merge Sort, Binary Search & Recursion Trees

Divide and conquer splits a problem into smaller copies of itself, solves those, and combines. Merge sort is the clean example: halve, sort each half, merge in linear time. Drawing the recursion tree makes the analysis almost visual — there are log n levels, each costing linear work in total, giving n log n. Binary search looks similar but is fundamentally different: it recurses on only one half, so there is one node per level rather than a doubling, and the total is logarithmic.

{{illustration:algos-l03-f1}}

{{illustration:algos-l03-f2}}

Key relations

- Divide-and-conquer recurrences. T(n) = 2T(n/2) + Θ(n) = Θ(nlog n) ; T(n) = T(n/2) + Θ(1) = Θ(log n)

The Master Theorem, Substitution & Changing Variables

The master theorem solves the standard divide-and-conquer recurrence by comparing two quantities: the work the recursive calls do and the work spent dividing and combining. Whichever dominates determines the answer, and when they balance you get an extra log factor. It covers most recurrences you meet, but not all — unequal subproblem sizes need Akra–Bazzi, and some forms yield to a change of variables. When the master theorem does not apply, substitution always works, provided you can guess the answer first.

{{illustration:algos-l03-f3}}

{{illustration:algos-l03-f4}}

Key relations

- The master theorem. T(n) = aT(n/b) + f(n), a ≥ 1, b > 1 ; compare f(n) with n^(log_b a)