Download presentation

Presentation is loading. Please wait.

Published byCaleb Goslee Modified over 3 years ago

1
Recurrences 2008. 1. 11 : 1 Chapter 3. Growth of function Chapter 4. Recurrences

2
Contents of Table 1.Review 2.Asymptotic notation 3.The substitution method 4.The recursion-tree method 5.The master theorem method 6.Proof of the master theorem 2

3
1. Review 3 Insertion SortMerge Sort Best, Worst, Average case draw and understandrecursion tree Address logically to audience

4
Theta[θ]-notation - [Theta] : f(n) = θ(g(n)) - for all n, n n 0, If there exist positive constant c 1, c 2 and n 0 such that c 1 g(n) f(n) c 2 g(n) then, f(n) = θ(g(n)). - if g(n) is both an upper and lower bound on f(n) then, f(n) = g(n). 4 2. Asymptotic notation

5
Big Oh[O]-notation - [Big Oh] : f(n) = O(g(n)) - for all n, n n 0, If there exist positive constant c and n 0 such that f(n) c g(n) then, f(n) = O(g(n)). 5 2. Asymptotic notation

6
Omega [ Ω ]-notation - [Omega] : f(n) = Ω (g(n)) - for all n, n n 0, If there exist positive constant c and n 0 such that c g(n) f(n) then, f(n) = Ω(g(n)). 6 2. Asymptotic notation

7
Recurrences 7 Recurrence - Definition Equation or inequality that describes a function in terms of its value on smaller inputs. - Recurrence Solution Method substitution method recursion-tree method master method if n=1 if n>1

8
Recurrences Technicalities - Omit Technical Details assumption of integer floors ceilings boundary condition - Example (Merge Sort) if n=1 if n>1 if n=1 if n>1 Assumption of integer Boundary condition Floors and ceilings

9
3. The substitution method 9 Substitution Method - Two steps - It can be used to establish either upper or lower bounds on a recurrence. 1. Guess the form of the solution 2. Use mathematical induction to find the constant and show that the solution works. 1. Guess the form of the solution 2. Use mathematical induction to find the constant and show that the solution works.

10
3. The substitution method 10 Example Step for substitution method 1. guess that the solution is 2. prove that ( c >0 ) 1. guess that the solution is 2. prove that ( c >0 )

11
3. The substitution method 11 - Assume that this bound holds for n/2, that is, T ( n/2 ) c n/2 lg( n/2 ). T(n) 2(c n/2 lg( n/2 )) + n cn lg(n/2) + n ( because, n/2 < n/2 ) = cn lg n - cn lg 2 + n = cn lg n - cn + n cn lg n (as long as c 1 )

12
3. The substitution method Find the constant n 0 - we can take advantage of asymptotic notation, we can replace base case T(1) cn lg n T(1) = 1 but, c1 lg1 = 0 - So, we only have to prove T (n) = cn lg n for n n 0 for n (n 0 =2) 12 Replace T(1) by T(2) and T(3) as the base cases by letting n 0 =2.

13
3. The substitution method Find the constant c -choosing c large enough T (2) = 4 and T (3) = 5. T (2) = 4 c 2 lg 2 T (3) = 5 c 3 lg 3. 13 Any choice of c 2 suffices for base case of n n 0, n 0 =2

14
4. The recursion-tree method Recursion-tree - Definition Each node represents the cost of a single subprogram somewhere in t he set of recursive function invocation - The reason why we use this method A recursion-tree is best used to generate a good guess Use directly to prove the master theorem - Total Cost We sum the cost each level of the tree to obtain a set of per-level costs, and then we sum all the per-level costs to determine the total cost of all levels of the recursion 14

15
4. The recursion-tree method Example Draw recursion tree 15 cn 2 T(n)T(n) T (n) = 3T ( n/4 ) + Θ(n 2 ) < 3T (n/4) + cn 2 T (n) = 3T ( n/4 ) + Θ(n 2 ) < 3T (n/4) + cn 2

16
4. The recursion-tree method Recursion-tree 16 cn 2 c(n/4) 2 T(1) … Depth Sub problem size 0 n 1 n/4 2 n/16.............. i n/4 i = 1 log 4 n

17
4. The recursion-tree method 17 Total Cost - When depth i then subprogram size is n/4 i = 1 so, i = log 4 n and it means trees height and tree has log 4 n + 1 levels. - The number of nodes at depth i is 3 i and finally - Total Cost is Sum of cost for root to i-1 depth Sum of cost for i depth

18
4. The recursion-tree method 18 Total Cost is..

19
4. The recursion-tree method 19 Prove T (n) = O(n 2 ) by the substitution method - Problem - Step for substitution method T (n) = 3T ( n/4 ) + Θ(n 2 ) 1. guess that the solution is T (n) = O(n 2 ) 2. prove that T (n) dn 2 (for some d > 0 and for the same c > 0 ) 1. guess that the solution is T (n) = O(n 2 ) 2. prove that T (n) dn 2 (for some d > 0 and for the same c > 0 )

20
4. The recursion-tree method 20 Prove.. Find constant d T(n) 3T( n/4 ) + cn 2 3d n/4 2 + cn 2 3d(n/4) 2 + cn 2 = 3/16 dn 2 + cn 2 dn 2 ( where the last step holds as long as d (16/13)c )

21
5. The master theorem method Master theorem - Definition method for solving recurrences of the form where a 1 and b > 1 ar e constant and f (n) is an asymptotically positive function 21 The cost of dividing the program and combining Subprograms are solved recursively

22
5. The master theorem method Master theorem 22 if n=1 if n>1 By Assumption of integer and Boundary condition By Draw recursion tree

23
5. The master theorem method 23 Three case of master theorem The three case of master theorem correspond to cases in which th e total cost of the tree. - Case 1 : dominated by the costs in the leaves. < - Case 2 : distributed across the levels of the tree. = - Case 3 : dominated by the cost of the root. >

24
5. The master theorem method Master theorem 24 Let a 1 and b > 1 are constants, let f (n) be a function, and let T (n) be defined on the nonnegative integers by the recurrence where we interpret n/b to mean either or. Then T (n) can be bounded asymptotically as follows. 1. If for some constant ε > 0, then. 2. If, then. 3. If for some constant ε > 0, and if af (n/b) cf (n) for some constant c < 1 and all sufficiently large n, then.

25
5. The master theorem method 25 Exception in case of master theorem - Exception A : Gap between cases 1 and 2 when < but not polynomially smaller. - Exception B : Gap between cases 2 and 3 when > but not polynomially larger.

26
5. The master theorem method 26 Exception in case of master theorem a=2, b=2, f (n) = n lg n, and it might be case 3? Asymptotically larger f (n) = n lg n > (asymptotically larger) But not Polynomially larger The ratio is asymptotically less than for any positive constant k (polynomially smaller) Recurrence falls into gap between cases 2 and 3.

27
6. The proof of master theorem 27 Case 1 : dominated by the costs in the leaves. we have for some constant,then so,,which implies that..

28
6. The proof of master theorem 28 Case 1 : dominated by the costs in the leaves. Constant value

29
6. The proof of master theorem 29 Case 2 : distributed across the levels of the tree.

30
6. The proof of master theorem 30 Case 3 : dominated by the cost of the root. We assume that af (n/b) cf (n) for some constant and c < 1, all n b, ( Iterating j times )

31
Thank you Q & A 31

Similar presentations

OK

October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

October 17, 2005 Copyright©2001-5 Erik D. Demaine and Charles E. Leiserson L2.1 Introduction to Algorithms 6.046J/18.401J LECTURE9 Randomly built binary.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google