Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2007CS 2251 Proof by Induction. Fall 2007CS 2252 Proof by Induction There are two forms of induction Standard Induction –Prove the theorem is true.

Similar presentations


Presentation on theme: "Fall 2007CS 2251 Proof by Induction. Fall 2007CS 2252 Proof by Induction There are two forms of induction Standard Induction –Prove the theorem is true."— Presentation transcript:

1 Fall 2007CS 2251 Proof by Induction

2 Fall 2007CS 2252 Proof by Induction There are two forms of induction Standard Induction –Prove the theorem is true for some base case (n=0 or n=1) –Show that if the theorem is assumed true for n, then it must be true for n+1 Complete Induction –Show that if the theorem is assumed true for all k<n, then it must be true for n+1

3 Fall 2007CS 2253 Example 1 Prove that for all n>=1, S(n) is true S(n): 1/(1x2) + 1/(2x3) +... + 1/(n(n+1)) = n/(n+1)

4 Fall 2007CS 2254 Proof of Basis Show S(1) is true. – The left-hand side is just 1/1x2) which is 1/2. – The right-hand side is 1/(1+1) which is 1/2 so the statement is true when n=1.

5 Fall 2007CS 2255 Induction Step Assume S(k) is true for some k >= 1: 1/(1x2) +... + 1/(k(k+1)) = k/(k+1) Show S(k+1) is true: 1/(1x2) +... + 1/((k+1)(k+2)) = (k+1)/(k+2) –The left-hand side of S(k+1) is 1/(1x2) +... + 1/(k(k+1)) + 1/((k+1)(k+2)) = [1/(1x2) +... + 1/(k(k+1))] + 1/((k+1)(k+2)) –By our induction assumption, the above equals [k/(k+1)] + 1/((k+1)(k+2)) = (1/(k+1)) [k + 1/(k+2)] = (1/(k+1)) [ (k(k+2) + 1))/(k+2) ] = (1/(k+1)) [ (k^2 + 2k + 1)/(k+2) ] = (1/(k+1)) [ (k + 1)^2 / (k+2) ] = (k+1)/(k+2)

6 Fall 2007CS 2256 Conclusion Under our induction hypothesis, we have shown that the left- and right-hand sides of S(k+1) are true. Therefore, the equation is valid for all n >= 1.

7 Fall 2007CS 2257 Towers of Hanoi A method for the Towers of Hanoi problem is: public static void Towers(int n, int from, int to, int other) { /*1 */ if (n > 1) /* 2 */ Towers(n-1, from, other, to); /* 3 */ System.out.println("Move disk " + n + " to pole " + to); /* 4 */ if (n > 1) /* 5*/ Towers(n-1, other, to, from); } Show that if n has the value k, k>= 1, then the total number of calls to Towers is 2 k - 1.

8 Fall 2007CS 2258 Basis The value of n = 1. If Towers is called and the value of n is 1, then the tests at (1) and (4) fail so there is no recursion and hence the number of calls is 1. But 1 = 2 1 - 1 so the assertion is true for the basis case.

9 Fall 2007CS 2259 Induction Step Assume the assertion is true if n has the value k for some k>=1: the number of calls is 2 k - 1. Assume Towers is called and the value of the formal paramter n is k+1. Show the total number of calls is 2 k+1 - 1. Since k>=1, (k+1)>1 so the calls at (2) and (5) occurwith actual parameter values of k in each case. By our induction assumption, these calls each require 2 k - 1 calls for a total of 2 k - 1 + 2 k - 1 + 1 = 2x2 k - 1 = 2 k+1 - 1 The number of calls is thus 2 k - 1, if the value of n is k for any k>=1.


Download ppt "Fall 2007CS 2251 Proof by Induction. Fall 2007CS 2252 Proof by Induction There are two forms of induction Standard Induction –Prove the theorem is true."

Similar presentations


Ads by Google