Recursion Trees
Explore the various properties of recursion trees, such as height and the number of nodes.
We'll cover the following...
What are recursion trees?
Recursion trees are a simple, general, pictorial tool for solving divide-and-conquer recurrences. A recursion tree is a rooted tree with one node for each recursive subproblem. The value of each node is the amount of time spent on the corresponding subproblem, excluding recursive calls. Thus, the overall running time of the algorithm is the sum of the values of all nodes in the tree.
To make this idea more concrete, imagine a divide-and-conquer algorithm that spends time on non-recursive work and then makes recursive calls, each on a problem of size . Up to constant factors (which we can hide in the notation), the running time of this algorithm is governed by the recurrence
The root of the recursion tree for has value and children, each of which is the root of a (recursively defined) recursion tree for . Equivalently, a recursion tree is a complete -ary tree where each node at depth contains the value . (Feel free to assume that is an integer power of c so that is always an integer, although, in fact, this doesn’t matter.)
In practice, we recommend drawing out the first two or three levels of the tree, as in the figure below.
The leaves of the recursion tree correspond to the base case(s) of the recurrence. Because we’re only looking for asymptotic bounds, the precise base case doesn’t actually matter; we can safely assume for all , where is an arbitrary positive constant. In particular, we can choose whatever value of is most convenient for our analysis. For this example, we’ll choose .
Now is the sum of all values in the recursion tree; we can evaluate this sum by considering the tree level by level. For each integer , the th level of the tree has exactly nodes, each with value ...