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.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy