1 / 39

L11: Recursion, Recurrence, and Induction

Page 1. L11: Recursion, Recurrence, and Induction. Objective Recursion A problem solving technique that reduces big problems into smaller ones Induction Proving correctness of recursive programs Recurrence Running time for recursive programs. Page 2. Outline.

zorion
Télécharger la présentation

L11: Recursion, Recurrence, and Induction

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. Page 1 L11: Recursion, Recurrence, and Induction • Objective • Recursion • A problem solving technique that reduces big problems into smaller ones • Induction • Proving correctness of recursive programs • Recurrence • Running time for recursive programs

  2. Page 2 Outline • Recursive algorithm for Towers of Hanoi • Problem and algorithm • Correctness • Running time • Recurrence in general • Example: Number of subsets • Example: Loan repayment • Solving recurrences • One type of First-Order linear recurrences • Another type of First-Order linear recurrences

  3. Page 3

  4. Page 4

  5. Page 5

  6. Page 6 Recursive Solution of Towers of Hanoi

  7. Page 7 Recursive Solution of Towers of Hanoi

  8. Page 8 Recursive Solution of Towers of Hanoi • Task: • Move n disks from peg i to peg j • Algorithm • Recursion base: • When n=1, move one disk from i to j • Recursion

  9. Page 9 Outline • Recursive algorithm for Towers of Hanoi • Problem and algorithm • Correctness • Running time • Recurrence in general • Example: Number of subsets • Example: Loan repayment • Solving recurrences • Geometric serious • First-Order linear recurrences

  10. Page 10 Correctness of Algorithm

  11. Page 11 Outline • Recursive algorithm for Towers of Hanoi • Problem and algorithm • Correctness • Running time • Recurrence in general • Example: Number of subsets • Example: Loan repayment • Solving recurrences • One type of First-Order linear recurrences • Another type of First-Order linear recurrences

  12. Page 12 Running Time

  13. Page 13 Solving the Recurrence

  14. Page 14

  15. Page 15

  16. Page 16 Outline • Recursive algorithm for Towers of Hanoi • Problem and algorithm • Correctness • Running time • Recurrence in general • Example: Number of subsets • Example: Loan repayment • Solving recurrences • One type of First-Order linear recurrences • Another type of First-Order linear recurrences

  17. Page 17 Recurrence • Recurrence/recurrence equation is a way to specify functions on the set of integers • It tells us how to • get the n-th value f(n) • from the first n-b values: f(b), f(b+1), …, f(n-1) • Need to give the value for the base casef(b) to complete the description

  18. Page 18 Number of subsets • S(n): number of subsets of set {1, 2, 3, …., n} of size n • Question: • How to compute S(n) from S(n-1), S(n-2), …? • Consider the case: n=3 • First row: subsets of {1, 2} • Second: subsets of {1, 2}, each adjoined by 3 • So: S(3) = 2 S(2)

  19. Page 19 Number of Subsets • In general, subsets of set {1, 2, 3, …., n} can be divided into two groups • subsets of set {1, 2, 3, …., n-1} • subsets of set {1, 2, 3, …., n-1}, each adjoined by n. • So: S(n) = 2 S(n-1) • Base case: • S(0) =1

  20. Page 20

  21. Page 21 Monthly Payment for Loan • Initial loan amount: A • Annual interest rate: p • Monthly Payment: M • T(n): total amount still due after n months

  22. Page 22 Outline • Recursive algorithm for Towers of Hanoi • Problem and algorithm • Correctness • Running time • Recurrence in general • Example: Number of subsets • Example: Loan repayment • Solving recurrences • One type of First-Order linear recurrences • Another type of First-Order linear recurrences

  23. Page 23

  24. Page 24 One Type of First-Order Linear Recurrence Examples

  25. Page 25 Iterating the Recurrence/Top-Down

  26. Page 26 Iterating the Recurrence/Bottom-Up

  27. Page 27

  28. Page 28 One Type of First-Order Linear Recurrence

  29. Page 29

  30. Page 30

  31. Page 31 Example

  32. Page 32 An Application of Theorem 4.1 Geometric Series

  33. Page 33 Outline • Recursive algorithm for Towers of Hanoi • Problem and algorithm • Correctness • Running time • Recurrence in general • Example: Number of subsets • Example: Loan repayment • Solving recurrences • One type of First-Order linear recurrence • Another type of First-Order linear recurrence

  34. Another Type of First-Order Linear Recurrence

  35. Page 35

  36. Page 36

  37. Page 37

  38. Page 38

  39. Page 39

More Related