7.3 Divide-and-Conquer Recurrences and Recursion Trees
Section 7.2 related one sequence term to earlier terms. We now return to the algorithmic cost functions from Chapter 5.
A recursive algorithm solves a problem by calling itself on smaller inputs. If its input size is , its operation count is not obtained from one loop alone: it includes the work done by every recursive call.
A recurrence lets us record that entire dependency structure.
From an algorithm to a cost recurrence
A divide-and-conquer algorithm has three conceptual stages:
1. divide the input into smaller subproblems; 2. conquer the subproblems recursively; 3. combine their answers.
Let denote the cost of solving an input of size . A common recurrence is
Every symbol has a specific meaning:
- is the number of recursive subproblems created by one non-base call;
- is the factor by which each subproblem's size shrinks;
- is therefore the size of each subproblem;
- is the nonrecursive divide-and-combine work performed by the current call.
We assume and . To keep the first calculations exact, we often take to be a power of . Floors and ceilings change endpoint details but usually not the asymptotic class.
A recurrence also needs a base cost. We will use
where is a constant.
Example: binary search makes one smaller call
Binary search compares a target with the middle array element and continues in only one half. If the comparison and index updates cost a constant , then
Unfold once:
After unfoldings,
The base case is reached when
Therefore and
Substitution gives
This is the halving-loop behavior from Chapter 5 expressed recursively.
A recursion tree displays every call
Repeated algebra can hide where work occurs. A recursion tree represents:
- one recursive call as one node;
- its recursive subcalls as children;
- the node's nonrecursive work as a cost label.
For
level contains the original call. Level contains its children, and so on.
At level :
- the number of nodes is ;
- each node handles size ;
- each node contributes nonrecursive work;
- the total nonrecursive cost of the level is
The leaves occur when . Solving gives the tree height
The number of leaves is
The identity converts the leaf count into a power of . The exponent measures how quickly recursive demand grows while input size shrinks.
Example: merge sort has equal work per internal level
Merge sort creates two subproblems of size and merges their sorted results in linear time. Its recurrence is
At level :
- there are calls;
- each call handles items;
- each call performs merge work.
Thus the level cost is
The number of internal levels is . Summing their equal costs gives
There are leaves, each costing , so leaf cost is . Therefore
The factor comes from the work across one level; the factor comes from the number of levels.
Direct an animated recursion-tree performance. Expand exactly one level at a time, inspect every call's input and local cost, and watch nodes combine into a level-cost strip. Presets for binary search, merge sort, and four-way recursion make one path, balanced levels, and leaf explosions visibly different.
Three ways recursion-tree cost can be distributed
The total cost is the sum of all level costs plus the leaf costs. Depending on the recurrence, most work may lie near the root, be balanced across levels, or accumulate near the leaves.
Suppose the nonrecursive work is a power
where and . At level ,
The ratio
tells how the cost changes from one level to the next.
Root-heavy:
If , level costs shrink geometrically. The top levels dominate, and
Example:
Here , , and , so .
Balanced:
If , every internal level has the same asymptotic cost. Multiplying by the number of levels gives
Merge sort is the example , , , so .
Leaf-heavy:
If , level costs grow geometrically. The bottom of the tree dominates, and the leaf count determines the order:
For
we have . The number of leaves is
so .
The simplified Master Theorem
The three comparisons above form a useful version of the Master Theorem. For
with , , , and the usual regularity assumptions, compare with :
This version covers polynomial combine costs. More general forms of the theorem handle logarithmic factors and require more precise conditions; we do not need those extensions here.
A disciplined use procedure
For a new recurrence:
1. identify , , and from the algorithm; 2. state the base case; 3. if , compute and ; 4. select the matching case; 5. check the conclusion against a recursion-tree level cost.
The last check matters. A memorized case number is fragile; the tree explains why the answer has that growth rate.
When the Master Theorem does not apply directly
The displayed form does not directly handle every recurrence. Examples include:
because the subproblem is , not , and
because the subproblems have unequal sizes.
Such recurrences may still be analyzed by unfolding, substitution, or a more general recursion-tree argument. A theorem is a tool with hypotheses, not a formula to apply by appearance alone.
Tune branching , shrink factor , and combine exponent in a workload arena. Recursive demand and local work race down synchronized levels; before revealing the result, place your prediction on root-heavy, balanced, or leaf-heavy. The arena then exposes the ratio and the matching asymptotic certificate.
Chapter bridge
Chapter 7 connected construction, counting, proof, and algorithms. Recursive definitions generated legal objects; structural induction followed their constructors; recurrence relations counted smaller cases; and recursion trees summed the work of recursive algorithms.
Chapter 8 turns to integers. Divisibility and prime factorization will provide the structure needed for modular arithmetic and cryptography, while recursive reasoning will reappear in Euclid's algorithm.