Divide and Conquer
Divide and conquer splits a problem into smaller instances of the same form, solves them independently, and combines their results.
Three obligations
- Divide: define subproblems and show their sizes shrink.
- Conquer: solve base cases and recurse on each subproblem.
- Combine: construct the parent solution and account for its cost.
A common runtime recurrence is
where is the number of subproblems, each has size about , and covers partitioning and combination. The recursion tree, substitution, or the Master Theorem can solve suitable recurrences; irregular sizes and dependencies may require other methods.
Representative patterns
- Merge sort: two half-size sorts plus a linear merge, yielding .
- Quicksort: linear partition plus input-dependent subproblem sizes.
- Binary search: one half-size subproblem plus constant combine work.
- Closest pair and Karatsuba multiplication: the combine strategy is the key improvement over direct enumeration.
Simply splitting an algorithm does not improve it. The subproblem solutions and combine step must solve the original problem, and their recurrence must actually have a better bound.
Boundary with dynamic programming
Divide-and-conquer subproblems are usually independent. Heavy overlap causes repeated work and suggests memoization or dynamic programming. Conversely, both styles can use recursion; syntax does not determine the design technique.
Independent branches may run in parallel, but practical speedup is bounded by the critical path, combine work, scheduling, communication, and memory traffic.
A complete recurrence argument
For merge sort on eight elements, the subproblem sizes are one run of 8,
two of 4, four of 2, then eight base cases of 1. Each of the three merge
levels processes eight elements in total. In the simplified model
, , this gives , , .
These are model work units, not exact comparisons or elapsed time.
More generally, for , every merge level costs , there are such levels and leaves: . Correctness is a separate induction: size-zero/one runs are sorted; if the two smaller results are sorted, repeatedly taking the smaller front produces a sorted permutation of their union. Strictly smaller subproblems prove termination. Neither the recurrence alone nor termination alone proves that the output is correct.
When the Master Theorem applies
For with constants , , nonnegative combine cost and constant-cost base cases, compare with , where . A common form gives:
- If for some , then .
- If , then .
- If for some and eventually for some constant , then .
These cases are sufficient, not exhaustive. Merge sort uses the middle case; binary search has , , and gives . It is also called decrease-and-conquer because only one smaller problem is solved. Quicksort with arbitrary pivot positions does not have fixed equal-size branches, so applying the theorem directly to its worst case is invalid. Independent branches enable parallelism but do not eliminate the combine cost.