1 / 48

Proof by Induction

Proof by Induction. CSC 172 SPRING 2002 LECTURE 7. Lectures on Line. http://www.cs.rochester.edu/u/pawlicki/lectures/CSC172. Proof by induction. If I know “something is true for the value 1” And I know that “if it is true for x, then it must also be true for x+1” Is it true for 7? Why?.

randi
Download Presentation

Proof by 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. Proof by Induction CSC 172 SPRING 2002 LECTURE 7

  2. Lectures on Line http://www.cs.rochester.edu/u/pawlicki/lectures/CSC172

  3. Proof by induction • If I know “something is true for the value 1” • And I know that “if it is true for x, then it must also be true for x+1” • Is it true for 7? • Why?

  4. Review : Sorting an array • Write a Java method that takes an array of ints and sorts it in place • Describe this algorithm in “words” • Describe “selection sort”

  5. Selection Sort public static void selsort(int [] a){ for (j=0;j<a.length;j++){ int maxIndex = j; for (int k = j;k<a.length;k++) if (a[k]>a[maxIndex]) maxIndex = k; int temp = a[j]; a[j] = a[maxIndex]; a[maxIndex] = temp; } }// How many comparisons, as a function of a.length?

  6. Selection Sort

  7. Total number of comparisons N + (N-1) + (N-2) + . . . + 1 Reversing 1 + 2 + 3 + . . . + N =

  8. In order to calculate work • Prove

  9. Simple Induction • Three Pieces • A statementS(n) to be proved • The statement must be about an integer parameter n • A basis for the proof • The statement S(b) for some specific integer b • Often b==0 or b==1 • An inductive step for the proof • Show that “If S(n) is true, then S(n+1) must also be true” • Prove the statement “S(n) implies S(n+1)” for any n. • For this part, you get to “suppose” S(n) is true • “For the sake of argument” • Aka the inductive hypothesis

  10. Prove: 1. Statement: S(n) : For any n>=1

  11. Prove: 2. Basis Select n == 1

  12. Prove: 2. Alternate Basis Select n == 2

  13. Prove: 2. Alternate Basis Select n == 3

  14. Prove: 3. Inductive Step Assume: To show:

  15. Inductive Step We know, by definition: Rewrite it:

  16. Inductive Step “By the Induction hypothesis” (we can make the following substitution)

  17. Inductive Step • The rest is just algebra

  18. Which, of course, is what we set out to prove!

  19. So, what did we do • We showed that it worked for 1 • And that if it worked for n, it must work for n+1 • So, is it true for n==7? • Why? • Is it true for n==984375984237598437594373457?

  20. Template for Simple Induction • State what S(n) is. • Explain what n represents. “any positive integer” or “length of the string” • Tell what the value of n is for the basis case n==b • Prove S(b) • State that you are assuming n>=b and S(n) • Prove S(n+1) using the assumptions (say: “B.T.I.H.”) • State that due to (4) and (6) you conclude S(n) for all n>=b

  21. Interesting Aside: Visual Proof • Proof is “convincing prose” • Not all proof is “mathematical”

  22. Visual Proof n 3 2 1 0 1 2 3 . . n

  23. Visual Proof n 3 2 1 0 1 .. n/2 . . n

  24. Visual Proof n 3 2 1 0 1 .. n/2

  25. Visual Proof n 3 2 1 0 1 .. n/2

  26. Visual Proof n 3 2 1 0 1 .. n/2

  27. Visual Proof n+1 n 3 2 1 0 1 .. n/2

  28. More General Induction • More than one basis case • Complete (Strong) indcution • Proof that S(n+1) is true uses any of S(b),S(b+1),…,S(n) • Where b is the lowest basis case

  29. Example • Multiple Basis cases & Strong Induction • Every integer >= 24 can be written as 5a+7b for non-negative integers a and b . • Is this true for 16? For 19? For 23?

  30. Statement • S(n): n ==5a+7b for some a>=0, and b>=0

  31. Basis We need 5 24 == 5x2+7x2 25 == 5x5+7x0 26 == 5x1+7x3 27 == 5x4+7x1 28 == 5x0+7x4

  32. Inductive Step Let (n+1) >= 29 Then (n-4) >= 24, which is the lowest basis case So, assume S(n-4) is true We can write: n-4 == 5a+7b for some a and b Thus: n+1 == 5(a+1)+7b, proving S(n+1)

  33. An Interesting Sequence 1 + 2 + 4 + 8 + . . . + n What is the pattern? What is it’s value? Why is it interesting?

  34. Why is it interesting? • How many nodes at each level of a binary tree? So, how many nodes, all told? 0 1 2 4 8

  35. Why is it interesting? What does 11112 “really mean?” 1×23 + 1×22 + 1×21 + 1×20 == 23 + 22 + 21 + 20 == 8 + 4 + 2 + 1 == 1 + 2 + 4 + 8

  36. Binary numbers How much is 100002 ? How does a=100002 relate to b=11112? Consider the relationship between the binary number formed by n 1’s to the binary number formed by one 1 followed by n 0’s Describe a & b, mathematically

  37. Proof S(n)

  38. Basis S(0)

  39. Inductive Step S(n+1)

  40. B.T.I.H S(n+1)

  41. So S(n+1)

  42. Visual Proof n 3 2 1 0 1 (n+1)/2 .. . n .

  43. Visual Proof n+1 n 3 2 1 0 1 (n+1)/2 .. . n .

  44. Visual Proof n/2 n+1 n 3 2 1 0 1 (n+1)/2 .. . n .

  45. Visual Proof n+1 n 3 2 1 0 1 (n+1)/2 .. . n .

  46. Visual Proof n+1 n 3 2 1 0 1 (n+1)/2 .. . n .

  47. Visual Proof n+1 n 3 2 1 0 1 (n+1)/2 .. . n .

More Related