Chapter 2 - Asymptotic Notation (Recursion Tree)
Chapter 2 - Asymptotic Notation (Recursion Tree)
4. It is sometimes difficult to come up with a good guess. In Recursion tree, each root
and child represents the cost of a single subproblem.
5. We sum the costs within each of the levels of the tree to obtain a set of pre-level costs
and then sum all pre-level costs to determine the total cost of all levels of the recursion.
6. A Recursion Tree is best used to generate a good guess, which can be verified by the
Substitution Method.
Example 1
Consider T (n) = 2T + n2
(n2)
So, the amount of work done is lg n ==> (n/2i)2 = 1 (base case) i = lg n
𝑛
∑lg 𝑛
𝑖=0(2𝑖 ) = (n )
2 2
T (n) = 4T + n
(n2)
Example 3: Consider the following recurrence
(n logn)
Each level does work of size n; if we just know the height of the tree , i, the total work is ni.
The tree stops when the lead is of size 1. The hard part is to figüre out the formula based on
the height:
When we add the values across the levels of the recursion trees, we get a value of n for
every level. The longest path from the root to leaf is