Recurrence Relations
Imagine a recipe for cooking a feast that says: "To cook for N people, split the guests in half, cook each half separately, then combine the two meals." The recipe refers to itself! That self-referencing is exactly what a recurrence relation is in algorithms.
When a recursive algorithm solves a problem of size n by breaking it into sub-problems and combining the results, its running time T(n) depends on T(smaller n). A recurrence relation is the equation that captures this dependency — and solving it gives us the final Big-O.
Reading T(n) = aT(n/b) + f(n)
This is the standard template for divide-and-conquer. a = how many sub-problems you create. n/b = the size of each sub-problem. f(n) = the work done outside the recursive calls (splitting, combining).
Merge sort: T(n) = 2T(n/2) + O(n) — two halves (a=2), each half-sized (b=2), plus \(O(n)\) to merge (f(n)=n).
Binary search: T(n) = T(n/2) + O(1) — one sub-problem (a=1), half-sized (b=2), just one comparison (f(n)=1).
The Master Theorem — Your Shortcut
The Master Theorem solves T(n) = aT(n/b) + f(n) by comparing f(n) to the "natural" recursion cost n^(log_b a):
Case 1 — Recursion dominates: f(n) is smaller than n^(log_b a). Then T(n) = \(\Theta(n^(log_b a)\)). Most work happens deep in the recursion tree.
Case 2 — Both match: f(n) = \(\Theta(n^(log_b a)\)). Then T(n) = \(\Theta(n^(log_b a)\) · log n). Every level of the tree does equal work, so we multiply by the number of levels.
Case 3 — Combining dominates: f(n) is larger than n^(log_b a) (with a regularity condition). Then T(n) = \(\Theta(f(n)\)). Most work is at the top level.
The Recursion Tree — Visual Intuition
Draw the recursion as a tree. Each node shows how much non-recursive work is done at that level. For merge sort: level 0 has 1 node doing \(O(n)\); level 1 has 2 nodes each doing \(O(n/2)\) = \(O(n)\) total; level 2 has 4 nodes each doing \(O(n/4)\) = \(O(n)\) total. Every level does \(O(n)\) work, and there are \(O(\log n)\) levels — so total cost is \(O(n \log n)\). The tree makes the multiplication intuitive.