Presentation is loading. Please wait.

Presentation is loading. Please wait.

Proof by Induction CSC 172 SPRING 2002 LECTURE 7.

Similar presentations


Presentation on theme: "Proof by Induction CSC 172 SPRING 2002 LECTURE 7."— Presentation transcript:

1

2 Proof by Induction CSC 172 SPRING 2002 LECTURE 7

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

4 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?

5 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”

6 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?

7 Selection Sort jk 0N 1N-1 2N-2... N-11

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

9  Prove In order to calculate work

10 Simple Induction  Three Pieces 1. A statement S(n) to be proved  The statement must be about an integer parameter n 2. A basis for the proof  The statement S(b) for some specific integer b  Often b==0 or b==1 3. 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

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

12 Prove: 2. Basis Select n == 1

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

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

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

16 Inductive Step We know, by definition: Rewrite it:

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

18 Inductive Step  The rest is just algebra

19

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

21 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?

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

23 Interesting Aside: Visual Proof  Proof is “convincing prose”  Not all proof is “mathematical”

24 Visual Proof 123..n0 1 2 3 n

25 1..n/2..n0 1 2 3 n

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

27 Visual Proof 1..n/20 1 2 3 n

28 Visual Proof 1..n/20 1 2 3 n

29 Visual Proof 1..n/20 1 2 3 n n+1

30 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

31 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?

32 Statement  S(n): n ==5a+7b for some a>=0, and b>=0

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

34 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)

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

36  How many nodes at each level of a binary tree? 0 1 2 4 8 So, how many nodes, all told?

37 Why is it interesting? What does 1111 2 “really mean?” 1×2 3 + 1×2 2 + 1×2 1 + 1×2 0 == 2 3 + 2 2 + 2 1 + 2 0 == 8 + 4 + 2 + 1 == 1 + 2 + 4 + 8

38 Binary numbers How much is 10000 2 ? How does a=10000 2 relate to b=1111 2 ? 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

39 Proof S(n)

40 Basis S(0)

41 Inductive Step S(n+1)

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

43 So S(n+1)

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

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

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

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

48 Visual Proof 1..(n+1)/2..n0 1 2 3 n+1 n

49 Visual Proof 1..(n+1)/2..n0 1 2 3 n+1 n


Download ppt "Proof by Induction CSC 172 SPRING 2002 LECTURE 7."

Similar presentations


Ads by Google