0% found this document useful (0 votes)
285 views11 pages

Recursion Tree Method Explained

This document discusses using the recursion tree method to solve recurrence relations of the form T(n) = aT(n/b) + f(n), where a is a decreasing function and b is a dividing function. It explains that a recursion tree visually represents the recursion by showing each subproblem as a node. The cost at each level is summed to get the total cost. As an example, it walks through solving the recurrence T(n) = T(n/4) + n using a recursion tree by drawing out the tree, finding the per-level costs, and summing the levels to get the final solution of O(nlogn).

Uploaded by

aditya b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
285 views11 pages

Recursion Tree Method Explained

This document discusses using the recursion tree method to solve recurrence relations of the form T(n) = aT(n/b) + f(n), where a is a decreasing function and b is a dividing function. It explains that a recursion tree visually represents the recursion by showing each subproblem as a node. The cost at each level is summed to get the total cost. As an example, it walks through solving the recurrence T(n) = T(n/4) + n using a recursion tree by drawing out the tree, finding the per-level costs, and summing the levels to get the final solution of O(nlogn).

Uploaded by

aditya b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Amity School of Engineering & Technology (CSE)

Analysis and Design of Algorithm(ADA)

Module-1[Lecture-6]
Recursion tree method

1
Amity School of Engineering & Technology (CSE)

OBJECTIVES
After completing this section, you will be able to
 Understand recursion tree method to solve Recurrence of the form:

 [Decreasing function]

 [Dividing Function]

2
Amity School of Engineering & Technology (CSE)

Recursion Tree method:


A recursion tree is a convenient way to visualize what happens when a
recurrence is iterated.
It is a pictorial representation of a given recurrence relation, which shows
how Recurrence is divided till Boundary conditions.

Recursion tree method is especially used to solve a recurrence of the form:

 [Decreasing function]

 where [Dividing Function]

3
Amity School of Engineering & Technology (CSE)

Recursion Tree method…

In a recursion tree ,each node represents the cost of a single sub-problem


somewhere in the set of recursive problems invocations .
 we sum the cost within each level of the tree to obtain a set of
per level cost, and
 then we sum all the per level cost to determine the total cost of all levels
of recursion. That gives us a solution of given recurrence

Let us see how to solve recurrence of the form

 where [Dividing Function]

4
Amity School of Engineering & Technology (CSE)

Solve the following recurrence using recurrence tree method:


…..(1)
Step1: First you make a recursion tree of a given recurrence.
(i) To make a recursion tree, we need to compare the given recurrence (1)
with Then we write the value of at root node. The number of child of a
Root Node is equal to the value of (here in recurrence (1)). So initially,
recursion tree be looks like as:

Fig (a)
Fig (b)

5
Amity School of Engineering & Technology (CSE)

Solve the following recurrence using recurrence tree method:


…..(1)
b) Now we have to find the value of T(n/4) in figure (b) by putting (n/4) in place of n in
equation (1).That is

From equation (2), now will be the value of node having 3 branch (child nodes) each
of size T(n/16). Now each in figure-b will be replaced as follows:

6
Amity School of Engineering & Technology (CSE)

Solve the following recurrence using recurrence tree method:


…..(1)
c) In this way, you can extend a tree up to Boundary condition (when
problem size becomes 1). So the final tree will be looks like as:

7
Amity School of Engineering & Technology (CSE)

Solve the following recurrence using recurrence tree method:


…..(1)
d) Now we find the per level cost of a tree, Per-level cost is the sum of the
costs of each nodes within each level (called row sum). Here per level cost
is shown in figure-d.

Fig-(d) 8
Amity School of Engineering & Technology (CSE)

Solve the following recurrence using recurrence tree method:


…..(1)

e) Finally, the total cost is the sum of the costs of all levels (called column
sum), which gives the solution of a given Recurrence. Thus,
Total cost=

Fig-(d) 9
Amity School of Engineering & Technology (CSE)

Solve the following recurrence using recurrence tree method:


…..(1)
e) Finally, the total cost is the sum of the costs of all levels (called column
sum), which gives the solution of a given Recurrence. Thus,
Total cost=
=

It’s a G.P series (r<1):


=

(using property of log: )

10
Amity School of Engineering & Technology (CSE)

Thank You!

11

You might also like