Recursion Tree
Recursion Tree
Like Master’s Theorem, Recursion Tree is another method for solving the recurrence
relations.
A recursion tree is a tree where each node represents the cost of a certain recursive sub-
problem.
We sum up the values in each node to get the cost of the entire algorithm.
Step-01:
Step-02:
Determine-
Cost of each level
Total number of levels in the recursion tree
Number of nodes in the last level
Cost of the last level
Step-03:
Add cost of all the levels of the recursion tree and simplify the expression so obtained in
terms of asymptotic notation.
Solution-
Step-01:
This is illustrated through following recursion tree where each node represents the cost of
the corresponding sub-problem-
Step-02:
Step-03:
Determine total number of levels in the recursion tree-
Size of sub-problem at level-0 = n/20
Size of sub-problem at level-1 = n/21
Size of sub-problem at level-2 = n/22
Step-04:
Step-06:
Add costs of all the levels of the recursion tree and simplify the expression so obtained in
terms of asymptotic notation-
= n x log2n + θ (n)
= nlog2n + θ (n)
= θ (nlog2n)
Problem-02:
Solution-
Step-01:
This is illustrated through following recursion tree where each node represents the cost of
the corresponding sub-problem-
Step-02:
Step-03:
Determine total number of levels in the recursion tree. We will consider the rightmost sub
tree as it goes down to the deepest level-
Size of sub-problem at level-0 = (4/5)0n
Size of sub-problem at level-1 =(4/5)1n
Size of sub-problem at level-2 =(4/5)2n
Step-04:
Step-05:
Step-06:
Add costs of all the levels of the recursion tree and simplify the expression so obtained in
terms of asymptotic notation-
= nlog5/4n + θ(nlog5/42)
= θ(nlog5/4n)
Problem-03:
Solution-
Step-01:
Step-02:
Step-03:
Step-04:
Step-05:
Step-06:
Add costs of all the levels of the recursion tree and simplify the expression so obtained in
terms of asymptotic notation-
On solving, we get-
= (16/13)cn2 { 1 – (3/16)log4n } + θ(nlog43)
= (16/13)cn2 – (16/13)cn2 (3/16)log4n + θ(nlog43)
= O(n2)
To gain better understanding about Recursion Tree,