1 / 59

Induction and Recursion

Induction and Recursion. CSC-2259 Discrete Structures. Induction. Induction is a very useful proof technique. In computer science, induction is used to prove properties of algorithms . Induction and recursion are closely related. Recursion is a description method for algorithms

galena
Download Presentation

Induction and Recursion

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. Induction and Recursion CSC-2259 Discrete Structures Konstantin Busch - LSU

  2. Induction Induction is a very useful proof technique In computer science, induction is used to prove properties of algorithms Induction and recursion are closely related • Recursion is a description method for algorithms • Induction is a proof method suitable • for recursive algorithms Konstantin Busch - LSU

  3. Use induction to prove that a proposition is true: Inductive Basis: Prove that is true Inductive Hypothesis: Assume is true (for any positive integer k) Inductive Step: Prove that is true Konstantin Busch - LSU

  4. Inductive Hypothesis: Assume is true (for any positive integer k) Inductive Step: Prove that is true In other words in inductive step we prove: for every positive integer k Konstantin Busch - LSU

  5. Inductive basis Inductive Step True True Proposition true for all positive integers Konstantin Busch - LSU

  6. Induction as a rule of inference: Konstantin Busch - LSU

  7. Theorem: Proof: Inductive Basis: Inductive Hypothesis: assume that it holds Inductive Step: We will prove K. Busch - LSU

  8. Inductive Step: (inductive hypothesis) End of Proof Konstantin Busch - LSU

  9. Harmonic numbers Example: Konstantin Busch - LSU

  10. Theorem: Proof: Inductive Basis: Konstantin Busch - LSU

  11. Inductive Hypothesis: Suppose it holds: Inductive Step: We will show: Konstantin Busch - LSU

  12. from inductive hypothesis End of Proof Konstantin Busch - LSU

  13. Theorem: Proof: Inductive Basis: Konstantin Busch - LSU

  14. Inductive Hypothesis: Suppose it holds: Inductive Step: We will show: Konstantin Busch - LSU

  15. from inductive hypothesis End of Proof Konstantin Busch - LSU

  16. We have shown: It holds that: Konstantin Busch - LSU

  17. Triominos hole hole hole Konstantin Busch - LSU

  18. Theorem: Every checkerboard with one square removed can be tiled with triominoes Proof: Inductive Basis: hole Konstantin Busch - LSU

  19. Inductive Hypothesis: Assume that a checkerboard can be tiled with the hole anywhere Hole can be anywhere Konstantin Busch - LSU

  20. Inductive Step: Konstantin Busch - LSU

  21. By inductive hypothesis squares with a hole can be tiled add three artificial holes Konstantin Busch - LSU

  22. For example: Konstantin Busch - LSU

  23. Replace the three holes with a triomino Now, the whole area can be tiled Konstantin Busch - LSU

  24. For example: End of Proof Konstantin Busch - LSU

  25. Strong Induction To prove : Inductive Basis: Prove that is true Inductive Hypothesis: Assume is true Inductive Step: Prove that is true Konstantin Busch - LSU

  26. Theorem: Every integer is a product of primes (at least one prime in the product) Proof: (Strong Induction) Inductive Basis: Number 2 is a prime Inductive Hypothesis: Suppose that every integer between and is a product of primes Konstantin Busch - LSU

  27. Inductive Step: If is prime then the proof is finished If is not a prime then it is composite: Konstantin Busch - LSU

  28. By the inductive hypothesis: primes primes End of Proof Konstantin Busch - LSU

  29. Theorem: Every postage amount can be generated by using 4-cent and 5-cent stamps Proof: (Strong Induction) Inductive Basis: We examine four cases (because of the inductive step) Konstantin Busch - LSU

  30. Inductive Hypothesis: Assume that every postage amount between and can be generated by using 4-cent and 5-cent stamps Inductive Step: If then the inductive step follows directly from inductive basis Konstantin Busch - LSU

  31. Consider: Inductive hypothesis End of Proof Konstantin Busch - LSU

  32. Recursion Recursion is used to describe functions, sets, algorithms Example: Factorial function Recursive Basis: Recursive Step: Konstantin Busch - LSU

  33. Recursive algorithm for factorial factorial( ) { if then return else return } //recursive basis //recursive step Konstantin Busch - LSU

  34. Fibonacci numbers Recursive Basis: Recursive Step: Konstantin Busch - LSU

  35. Konstantin Busch - LSU

  36. Recursive algorithm for Fibonacci function fibonacci( ) { if then return else return } //recursive basis //recursive step Konstantin Busch - LSU

  37. Iterative algorithm for Fibonacci function fibonacci( ) { if then else { for to do { } return } Konstantin Busch - LSU

  38. Theorem: for (golden ratio) Proof: Proof by (strong) induction Inductive Basis: Konstantin Busch - LSU

  39. Inductive Hypothesis: Suppose it holds Inductive Step: We will prove for Konstantin Busch - LSU

  40. is the solution to equation End of Proof Konstantin Busch - LSU

  41. Greatest common divisor Recursive Basis: Recursive Step: Konstantin Busch - LSU

  42. Recursive algorithm for greatest common divisor gcd( ) { if then return else return } //assume a>b //recursive basis //recursive step Konstantin Busch - LSU

  43. Lames Theorem: The Euclidian algorithm for , uses at most divisions (iterations) Proof: We show that there is a Fibonacci relation in the divisions of the algorithm Konstantin Busch - LSU

  44. remainder divisions first zero result Konstantin Busch - LSU

  45. This holds since and is integer Konstantin Busch - LSU

  46. This holds since Konstantin Busch - LSU

  47. End of Proof Konstantin Busch - LSU

  48. Algorithm Mergesort 8 2 4 6 9 7 10 1 5 3 split 8 2 4 6 9 7 10 1 5 3 sort sort 1 3 5 7 10 2 4 6 8 9 merge 1 2 3 4 5 6 7 8 9 10 Konstantin Busch - LSU

  49. sort( ) { if then { return } else return } Konstantin Busch - LSU

  50. Input values of recursive calls 8 2 4 6 9 7 10 1 5 3 8 2 4 6 9 7 10 1 5 3 8 2 4 6 9 7 10 1 5 3 8 2 6 9 7 10 1 5 3 4 8 2 7 10 Konstantin Busch - LSU

More Related