Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
34 views25 pages

L07 Recurrence II

Uploaded by

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

L07 Recurrence II

Uploaded by

Akash Sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Recurrence Relation - II

Instructor: Ashok Singh Sairam


Lecture Plan
• What is a recurrence relation?
• Methods for solving recurrences
§ Substitution method
§ Recursion tree method

§ Master method

MA512: Data Structures and Algorithms


2
Master Method

MA512: Data Structures and Algorithms


3
Master Method: Three cases

MA512: Data Structures and Algorithms


4
Master Method: Three cases – contd.

MA512: Data Structures and Algorithms


5
Example - 1
• T(n) = 4T(n/2)+n

MA512: Data Structures and Algorithms


6
Example - 1

MA512: Data Structures and Algorithms


7
Example - 2
• T(n) = 4T(n/2)+n2

MA512: Data Structures and Algorithms


8
Example - 2

MA512: Data Structures and Algorithms


9
Example - 3
• T(n) = 4T(n/2)+n3

MA512: Data Structures and Algorithms


10
Example - 3

MA512: Data Structures and Algorithms


11
Idea of Master Theorem
• Recall the theorem only applies to recurrence of
the form
• Its recurrence tree will be

• Height: ??
MA512: Data Structures and Algorithms
12
Idea of Master Theorem (2)

• #leaves : ?

MA512: Data Structures and Algorithms


13
Idea of Master Theorem (3)

MA512: Data Structures and Algorithms


14
Idea of Master Theorem (4)

• Case 1: Weight increases geometrically from root to the


leaves. Leaves hold a constant fraction of total weight
MA512: Data Structures and Algorithms
15
Idea of Master Theorem (5)

• Case 2: Weight is approximately the same in all the levels

MA512: Data Structures and Algorithms


16
Idea of Master Theorem (6)

• Case 3: Weight decreases geometrically from root to the


leaves. Root holds a constant fraction of total weight
MA512: Data Structures and Algorithms
17
Practice Exercise
• Give asymptotic upper and lower bounds for T(n) in each
of the following recurrences. Assume that T(n) is constant
for n ≤ 3. Make your bounds as tight as possible, and
justify your answers.
(a)

MA512: Data Structures and Algorithms


18
Practice Exercise
• Give asymptotic upper and lower bounds for T(n) in each
of the following recurrences. Assume that T(n) is constant
for n ≤ 3. Make your bounds as tight as possible, and
justify your answers.
(b)

MA512: Data Structures and Algorithms


19
Practice Exercise
• Give asymptotic upper and lower bounds for T(n) in each
of the following recurrences. Assume that T(n) is constant
for n ≤ 3. Make your bounds as tight as possible, and
justify your answers.
(c)

MA512: Data Structures and Algorithms


20
Practice Exercise

MA512: Data Structures and Algorithms


21
Practice Exercise

MA512: Data Structures and Algorithms


22
Use Recursion Tree

MA512: Data Structures and Algorithms


23

MA512: Data Structures and Algorithms


24
MA512: Data Structures and Algorithms
25

You might also like