Professional Documents
Culture Documents
Lecture # 09-10
Muhammad Umair
10/3/2012
Previous Lecture
Substitution Method
Muhammad Umair
10/3/2012
Todays Lecture
Merge Sort Recurrence Steps Involve in Recursion Tree Method Tree Construction of Merge Sort More Examples Master Theorem Method
Muhammad Umair
10/3/2012
Merge Sort
Muhammad Umair
10/3/2012
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Merge Procedure
Muhammad Umair
10/3/2012
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Muhammad Umair
10/3/2012
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Muhammad Umair
10/3/2012
Construct the Tree Find the problem size on each level Determine the cost for each node Find no. of nodes on each Level Determine the cost of each level Determine the total no. of levels Determine the last level and its cost Sum the cost of each level Verify the results with help of Substitution Method
Muhammad Umair
10/3/2012
Recursion Tree
Muhammad Umair
10/3/2012
T(n)
= 3 T (floor(n/4)) +
2 n
10
Muhammad Umair
10/3/2012
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
11
Muhammad Umair
10/3/2012
T(n)
= T(n/3) + T (2n/3) +
O(n)
12
Muhammad Umair
10/3/2012
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
13
Muhammad Umair
10/3/2012
Master Method
Master Theorem
T(n) = a T(n/b) + f (n) where a >= 1 and b > 1 and T(n) can be bounded asymptotically as follows If f(n) = O(n logb a-), for > 0 then T(n)=(n logb a) If f(n) = (n logb a), then T(n)=(n logb a lg n) If f(n) = (n logb a+), for > 0 and if a f (n/b) <= c f(n) for c<1 then T(n)=(f(n))
14
Muhammad Umair
10/3/2012
Examples
T(n) = 3T(n/4) + n lg n
15
Muhammad Umair
10/3/2012
Summary
Merge Sort Recurrence Steps Involve in Recursion Tree Method Tree Construction of Merge Sort More Examples Master Theorem Method
16
Muhammad Umair
10/3/2012