0% found this document useful (0 votes)
30 views8 pages

Data Structures and Algorithms (AT70.02)

This document discusses data structures and algorithms. It covers solving recurrences by iterative expansion and using the recursion tree and master's theorem methods. It provides examples of applying these methods to solve recurrences like T(n) = 2T(n/2) + n and T(n) = 3T(n/4) + cn^2.

Uploaded by

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

Data Structures and Algorithms (AT70.02)

This document discusses data structures and algorithms. It covers solving recurrences by iterative expansion and using the recursion tree and master's theorem methods. It provides examples of applying these methods to solve recurrences like T(n) = 2T(n/2) + n and T(n) = 3T(n/4) + cn^2.

Uploaded by

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

Data Structures and

Algorithms (AT70.02)
Comp. Sc. and Inf. Mgmt.
Asian Institute of Technology
Instructor: Prof. Sumanta Guha
Slide Sources: CLRS “Intro. To
Algorithms” book website
(copyright McGraw Hill)
adapted and supplemented
CLRS “Intro. To Algorithms”
Ch. 4: Recurrences
Solving a Recurrence by Iterative
Expansion
Solve T(n) = 2T(n/2) + n.
Assume n = 2k (so k = log n).

T(n) = 2T(n/2) + n
= 2( 2T(n/22) + n/2 ) + n T(n/2) = 2T(n/22) + n/2
= 22T(n/22) + 2n
= 22 ( 2T(n/23) + n/22 ) + 2n T(n/22) = 2T(n/23) + n/22
= 23T(n/23) + 3n
=…
= 2kT(n/2k) + kn
= nT(1) + nlog n
= (nlog n)
Recursion-Tree = Diagrammatic
Way of Doing Iterative Expansion
Solve T(n) = 3T(n/4) + cn2 by iterative expansion.
Assume n = 4k.
Master Theorem
T(n) = aT(n/b) + f(n), where a ≥ 1 and b > 1:

1. If f(n) = O(nlogba - ) for some constant  > 0, then


T(n) = (nlogba).

2. If f(n) = (nlogba), then T(n) = (nlogba log n)

3. If f(n) = (nlogba + ) for some constant  > 0, and if


af(n/b) ≤ cf(n) for some constant c < 1 and
sufficiently large n, then T(n) = (f(n))
Problems
 Use the master method to solve
 T(n) = 2T(n/2) + n
 T(n) = 3T(n/4) + cn2
 Ex. 4.3-1
 Ex. 4.3-3
 Prob. 4-5
 Prob. 4-6

You might also like