1 / 34

Recurrence Relations

Recurrence Relations. Recurrence Relations. A recurrence relation is an equation which is defined in terms of itself. Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally modeled by recurrence relations. Example Merge Sort.

wilsonlinda
Download Presentation

Recurrence Relations

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. Recurrence Relations

  2. Recurrence Relations • A recurrence relation is an equation which is defined in terms of itself. • Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally modeled by recurrence relations

  3. Example Merge Sort Merge-Sort(A, p, r): if p < r then q¬(p+r)/2 Merge-Sort(A, p, q) Merge-Sort(A, q+1, r) Merge(A, p, q, r)

  4. Solving Recurrences • We will show 3 ways of solving recurrences: • Substitution method - Guess and prove • Use mathematical induction to solve your recursion • Iteration method • Break the sums into a mathematical series • Master theorem • Check for an instant solution

  5. n 0 1 2 3 4 5 6 7 0 1 3 7 15 31 63 127 Substitution method • Guess a solution and them prove it using mathematical induction. • To guess the solution, play around with small values for insight

  6. Prove by induction • Claim • Show that the basis is true: • Now assume true for T(n-1 ) • Using this assumption show:

  7. Iteration method • Example • How many terms until we reach T(1) ?

  8. Iteration method

  9. Recursion Trees

  10. Recursion Trees

  11. Recursion Trees

  12. Recursion Trees

  13. Master Theorem • A powerful theorem allowing to solve a large class of recursion relations of the form where • There are 3 cases to remember: • If for some constant then

  14. Master Theorem • If then • If for some constant and for some c < 1 then for all sufficiently large n

  15. Using Master Theorem • T(n) = 4 T(n/2) + n • Case 1 of master theorem

  16. Using Master Theorem

  17. Using Master Theorem • Use case 2 of Master theorem

  18. Using Iteration

  19. Using Master theorem

  20. Examples • Use Master theorem case 1 where є = 1/6

  21. Master theorem

  22. Examples • Use case 2 of Master Theorem

  23. Examples • Use Master Theorem – case 3

  24. Example • Fits case 3 of Master theorem ?

  25. Examples

  26. Examples • Master Theorem – does not fit • Substitution method – too complicated • Recursion tree

  27. T(n) is at least the price for a complete tree of height T(n) is at most the price for a complete tree of height

  28. i=0 n • i=1 (3/4)n • i=2 (9/16)n • i=3 (27/64)n • i=k (3/4)^k * n

  29. Regularity of Case 3

  30. Example

More Related