1 Divide and Conquer
Divide and conquer splits a problem of size n into a subproblems of size n/b, solves them recursively, and combines results in f(n) time. This yields the recurrence:
T(n) = a · T(n/b) + f(n)
The technique works well when subproblems are independent (no overlapping sub-sub-problems) and combining is cheap. Classic examples: merge sort, quicksort, binary search, Karatsuba multiplication.
- a = number of recursive calls
- b = factor by which input shrinks per call
- f(n) = cost of divide + combine steps
// Generic divide-and-conquer skeleton
function divideAndConquer(arr, lo, hi) {
if (hi - lo <= 0) return solve(arr[lo]); // base case
const mid = Math.floor((lo + hi) / 2);
const left = divideAndConquer(arr, lo, mid);
const right = divideAndConquer(arr, mid + 1, hi);
return combine(left, right); // O(n) combine step
}