1 / 31

Recurrences

Recurrences. Chapter 3. Growth of function Chapter 4. Recurrences. 한양대학교 정보보호 및 알고리즘 연구실 2008. 1. 11 이재준 담당교수님 : 박희진 교수님. Contents of Table. Review Asymptotic notation The substitution method The recursion-tree method The master theorem method Proof of the master theorem.

mauve
Download Presentation

Recurrences

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recurrences Chapter 3. Growth of function Chapter 4. Recurrences 한양대학교 정보보호 및 알고리즘 연구실 2008. 1. 11 이재준 담당교수님 : 박희진 교수님

  2. Contents of Table • Review • Asymptotic notation • The substitution method • The recursion-tree method • The master theorem method • Proof of the master theorem

  3. 1. Review Insertion Sort Merge Sort Asymptotic Complexity

  4. 2. Asymptotic notation • Theta[θ]-notation - [Theta] : f(n) = θ(g(n)) - for alln, n ≥ n0, If there exist positive constant c1 , c2 and n0 such that c1 g(n) ≤ f(n) ≤ c2 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).

  5. 2. Asymptotic notation • Big Oh[O]-notation - [Big Oh] : f(n) = O(g(n)) - for alln, n ≥ n0, If there exist positive constant cand n0such that f(n) ≤ cg(n)then, f(n) = O(g(n)).

  6. 2. Asymptotic notation • Omega [Ω]-notation - [Omega] : f(n) = Ω(g(n)) - for alln, n ≥ n0, If there exist positive constant cand n0such that cg(n) ≥f(n) then, f(n) = Ω(g(n)).

  7. Recurrences • Recurrence - Definition Equation or inequality that describes a function in terms of its value on smaller inputs. - RecurrenceSolution 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 Floors and ceilings Assumption of integer Boundary condition

  9. 3. The substitution method • 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.

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

  11. 3. The substitution method - 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 ≤ cnlg(n/2) + n ( because, ⌊n/2⌋ < n/2 ) = cnlgn - cnlg 2 + n = cnlgn - cn+ n ≤ cnlgn (as long as c ≥ 1)

  12. 3. The substitution method • Find the constant n0 - we can take advantage of asymptotic notation, we can replace base case T(1) ≤ cnlgn T(1) = 1 but, c1 lg1 = 0 - So, we only have to prove T (n) = cnlgn for n ≥ n0 for n (n0 =2) Replace T(1) byT(2) andT(3) as the base cases by letting n0 =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. Any choice of c ≥ 2 suffices for base case of n ≥ n0 , n0 =2

  14. 4. The recursion-tree method • Recursion-tree - Definition Each node represents the cost of a single subprogram somewhere in the 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

  15. 4. The recursion-tree method • Example • Draw recursion tree T (n) = 3T (⌊n/4⌋) + Θ(n2) < 3T (n/4) + cn2 cn2 cn2 T(n)

  16. 4. The recursion-tree method • Recursion-tree cn2 c(n/4)2 c(n/4)2 c(n/4)2 log4n … T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1) T(1)

  17. 4. The recursion-tree method • Total Cost - When depth ithen subprogram size is n/4i= 1so, i= log4n and it means tree’s height and tree has log4n + 1 levels. - The number of nodes at depth iis3iand finally - Total Cost is Sum of cost for idepth Sum of cost for root to i-1 depth

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

  19. 4. The recursion-tree method • ProveT (n) = O(n2) by the substitution method - Problem - Step for substitution method T (n) = 3T (⌊n/4⌋) + Θ(n2) 1. guess that the solution is T (n) = O(n2) 2. prove that T (n) ≤ dn2(for somed > 0 and for the samec > 0)

  20. 4. The recursion-tree method • Prove.. Find constant d T(n) ≤ 3T(⌊n/4⌋) + cn2 ≤ 3d⌊n/4⌋2 + cn2 ≤ 3d(n/4)2 + cn2 = 3/16 dn2 + cn2 ≤ dn2( 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 andb > 1 are constant and f (n) is an asymptotically positive function Subprograms are solved recursively The cost of dividing the program and combining

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

  23. 5. The master theorem method • Three case of master theorem The three case of master theorem correspond to cases in which the 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 • 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 • 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 • Exception in case of master theorem • a=2, b=2, f (n) = n lg n, andit 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 • 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 • Case 1 : dominated by the costs in the leaves. Constant value

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

  30. 6. The proof of master theorem • Case 3 : dominated by the cost of the root. We assume thataf(n/b) ≤ cf(n) for some constant and c < 1, all n ≥ b, ( Iterating jtimes )

  31. Thank you Q & A

More Related