Recurrences & the Master Theorem

the recursion-tree method

If you trace a recursive algorithm on paper, the calls naturally fan out into a tree: the original problem at the root, its subproblems as children, their subproblems as grandchildren, and so on down to the base cases at the leaves. The recursion-tree method just draws this tree, labels each node with the work it does locally, and adds everything up.

Here is the procedure on T(n) = 2 T(n/2) + n. Write n at the root: that is the combine cost at the top level. The root has two children, each a problem of size n/2, each costing n/2 locally, so the next level's total is 2 * (n/2) = n. Each of those splits into two of size n/4 costing n/4, so that level totals 4 * (n/4) = n again. Every level sums to n. The tree has 1 + log2(n) levels (halving n down to 1), so the grand total is about n * (1 + log2 n) = Theta(n log n). The trick is to find the per-level sum and the number of levels, then multiply (or sum a series when the per-level totals are not constant).

The recursion tree is the best tool for forming a guess, especially when the per-level work changes. If each level's total grows geometrically (gets bigger toward the leaves), the leaves dominate and the total is Theta(leaves); if it shrinks geometrically toward the leaves, the root dominates and the total is Theta(f(n)); if it stays flat, you get a logarithmic factor. Its honest limitation: a hand-drawn tree is a heuristic. Floors, ceilings, and uneven splits make it approximate, so for a rigorous result you confirm the guessed bound with the substitution method or invoke the Master Theorem.

For T(n) = T(n/2) + T(n/4) + n the levels do NOT all sum to the same thing: level totals shrink geometrically (n, then 3n/4, then 9n/16, ...), a series that sums to 4n, so the root dominates and T(n) = Theta(n). The tree exposes this at a glance.

Sum each level, then sum the levels; geometric growth means leaves win, geometric decay means the root wins.

A recursion tree gives a guess, not a proof — the leaf count and level totals are easy to miscount with floors or unequal splits. Confirm with substitution before claiming the bound is exact.

Also called
recursion treetree of recursive calls遞迴樹