Download presentation
Presentation is loading. Please wait.
Published byLeonard Snow Modified over 8 years ago
1
6/12/2016 Prepared by Dr.Saad Alabbad1 CS100 : Discrete Structures Proof Techniques(2) Mathematical Induction & Recursion Dr.Saad Alabbad Department of Computer Science E-mail: salabbad@gmail.com Tel # 2581888
2
6/12/2016 Prepared by Dr.Saad Alabbad2 Mathematical Induction Principle of Mathematical Induction To prove that P(n) is true for all positive integers n where P(n) is a propositional function we complete two steps: Basis Step: prove that P(1) is true. Inductive Step: show that if P(k) is true then P(k+1) is true for all positive integers k (i.e P(k) P(k+1) ) This can be expressed as [P(1) k P(k) P(k+1)] n P(n)
3
6/12/2016 Prepared by Dr.Saad Alabbad3 Mathematical Induction Example(1): Show that if n is a postive integer then 1+2+…+n=[n(n+1)]/2 Basis Step: P(1) is true since 1=[1(1+1)]/2=2/2=1 Inductive Step: Assume that P(k) is true i.e 1+2+…+k=[k(k+1)]/2 (*) We need to show that P(k+1) is true By adding k+1 to (*) we obtain 1+2+…+k+(k+1)= [k(k+1)]/2+(k+1) = [k(k+1)+2(k+1)]/2 =(k+1)(k+2)/2 by taking k+1 as a common factor =P(k+1) So P(k+1) is true under the assumption that P(k) is true which completes the proof.
4
6/12/2016 Prepared by Dr.Saad Alabbad4 Mathematical Induction Example(2): Show that n<2 n for all positive integers n Basis Step: P(1) is true since 1<2 1 Inductive Step: Assume that P(k) is true i.e k<2 k (*) We need to show that P(k+1) is true i.e k+1<2 k+1 By adding 1 to (*) we obtain K+1<2 k +1. But since 1 2 k for all positive integers k. We have K+1<2 k +1 2 k +2 k =2.2 k =2 k+1 K+1<2 k+1 So P(k+1) is true under the assumption that P(k) is true which completes the proof.
5
6/12/2016 Prepared by Dr.Saad Alabbad5 Mathematical Induction Example(3): Show that the number of subsets of a finite set S is 2 n where n is the number of elements of the set S. Basis Step: P(0) is true since the set with zero elements (empty set) has exactly one subset. Namely itself 2 0 =1 Inductive Step: Assume that P(k) is true i.e every set with k elements has 2 k subsets We need to show that P(k+1) is true i.e every set with k+1 elements has 2 k+1 subsets Let T be a set with k+1 elements then we can write T=S {a} where a is an element of T and S=T-{a} For each subset X of S there are two subsets of T: subset that contains a i.e X {a} and the subset that does not contain a i.e X (see next slide) Since S has k elements, there are 2 k subsets of S and hence there are 2. 2 k = 2 k+1 subsets of T (see next slide) So P(k+1) is true under the assumption that P(k) is true which completes the proof.
6
6/12/2016 Prepared by Dr.Saad Alabbad6 Mathematical Induction { } { } { } {1} { } {1} { } {2} {1} {1,2} { } {2} {1} {1,2} { } {3} {2} {2,3} {1} {1,3} {1,2} {1,2,3} { } {3} {2} {2,3} {1} {1,3} {1,2} {1,2,3} S={1,2} T={1,2,3} a=3 Every subset of T can be generated by adding or omitting element a from every subset of S Example(3): Illustration
7
6/12/2016 Prepared by Dr.Saad Alabbad7 Mathematical Induction Example(4): Show that 2 n n! for all positive integers n 4 Basis Step: P(4) is true since 2 4 =16 4!=24 (note: basis step is 4) Inductive Step: Assume that P(k) is true i.e 2 k k! (*) for all k 4 We need to show that P(k+1) is true i.e 2 k+1 (k+1)! Multiply (*) by 2, we obtain 2.2 k =2 k+1 2.K! (k+1)k! Since 2<k+1 =(k+1)! So 2 k+1 (k+1)! So P(k+1) is true under the assumption that P(k) is true which completes the proof.
8
6/12/2016 Prepared by Dr.Saad Alabbad8 Strong Mathematical Induction Principle of Strong Mathematical Induction To prove that P(n) is true for all positive integers n where P(n) is a propositional function we complete two steps: Basis Step: prove that P(1) is true. Inductive Step: show that if P(1) P(2) .. P(k) are true then P(k+1) is true for all positive integers k (i.e P(k) P(k+1) ) This can be expressed as [P(1) P(2)… P(k) P(k+1)] n P(n) Sometimes it is called second principle of induction It is equivalent to the mathematical induction we have seen.However, in many cases it is much easier to prove using the strong induction. Note that the difference lies in the inductive step. We assume that P(1),P(2) up to P(k) are true and we show that P(k+1) is true where in the normal induction we assume that only P(k) is true and show that P(k+1) is true.
9
6/12/2016 Prepared by Dr.Saad Alabbad9 Strong Mathematical Induction Example: Show that if n is an integer greater than 1, then n can be written as the product of primes Basis Step: P(2) is true since 2 can be written as the product of one prime (itself!) Inductive Step: Assume that P(2),…P(k) are true i.e P(j) is true for 2 j k We need to show that P(k+1) is true i.e k+1 can be written as product of primes Now we have two cases: K+1 is prime which means that P(k+1) is true. K+1 is composite and can be written as the product of two positive integers 2 a b k+1 By the inductive step we see that both a and b can be written as the product of primes. Thus if K+1 is composite it can hbe written as the product of primes (primes in the factorization of a and b) So P(k+1) is true under the assumption that P(j) is true for 2 j k which completes the proof. Note: this theorem is called the Fundamental Theorem of Arithmetic
10
6/12/2016 Prepared by Dr.Saad Alabbad10 Recursive Definitions: Recursively Defined Functions Recursion See: "Recursion" if you still don't get it, Recursion: Defining something (process,function,set,concept,etc..) in terms of itself Example(1): One’s ancestors : his father and his father’s ancestors Example(2): Factorial of n is defined as n!=n*n-1*….*1 Can be defined recursively as: n!=n* (n-1)!
11
6/12/2016 Prepared by Dr.Saad Alabbad11 Recursive Definitions: Recursion See: "Recursion" if you still don't get it, Recursion: Defining something (process,function,set,concept,etc..) in terms of itself Example(1): One’s ancestors : his father and his father’s ancestors Example(2): Factorial of n is defined as n!=n*n-1*….*1 Can be defined recursively as: n!=n* (n-1)!
12
6/12/2016 Prepared by Dr.Saad Alabbad12 Recursive Definitions: Recursively Defined Functions Recursive functions have two parts 1)Basis step: gives the value of the function at some initial value (usually zero). It is needed to terminate the recursive step. 2)Recursive Step: gives a rule of finding the value of the function from previous values Example(1): Factorial of n is defined as n!=n*n-1*….*1 Can be defined recursively as: 0!=1 [basis step] n!=n* (n-1)! [recursive step] Example(2): Let F(n)=0+1+2+…+n. Define F(n) recursively: F(0)=0 [basis step] F(n)=n+F(n-1) [recursive step] we can also write F(n+1)=(n+1)+F(n) Question : Define F(n)=2 n recursively.
13
6/12/2016 Prepared by Dr.Saad Alabbad13 Recursive Definitions: Recursively Defined Functions Example(3):Febonacci numbers f n are defined as: f 0 =0 [basis step] f 1 =1 f n = f n-1 + f n-2 [inductive step] Compute f 5. f 5 = f 4 +f 3 f 2 =1+0=1 f 3 =f 2 +f 1 =1+1=2 = f 3 +f 2 +f 2 +f 1 f 4 =f 3 +f 2 =2+1=3 f 5 =f 4 +f 3 =3+2=5 =f 2 +f 1 +f 1 +f 0 +f 1 +f 0 +1 =f 1 +f 0 + 1+ 1+ 0+1+ 0+1=5 More efficient way
14
6/12/2016 Prepared by Dr.Saad Alabbad14 Recursive Definitions: Recursively Defined Sets Recursive definition of sets have two parts 1)Basis step: initial collection of elements in the set. 2)Recursive Step: gives a rule for forming new elements in the set from those already in the set. Example(1): Define the set S as follow 2 S [basis step] If x S and y S then x+y S [ Recursive step] What is S ?? 2 in S 2+2=4 in S [Recursive step] 2+4=6 in S [Recursive step] Etc… Can you figure it out?
15
6/12/2016 Prepared by Dr.Saad Alabbad15 Recursive Definitions: Recursive Algorithm Recursive algorithms: solve a problem by reducing it to an instance of the same problem with smaller input. Factorial Algorithm int fac(int n) { if (n == 0) return 1; return n * fac(n-1); } Exponentiation Algorithm int power(int a, int n) { if (n == 0) return 1; return a * power (a,n-1); }
16
6/12/2016 Prepared by Dr.Saad Alabbad16 Recursive Definitions: Fibonacci Recursive Algorithm Fibonacci Algorithm int fib(int n) { if (n == 0) return 0; if (n == 1) return 1; return fib(n-1)+ fib(n-2); } f5f5 f4f4 f3f3 f3f3 f2f2 f2f2 f1f1 f0f0 f1f1 f1f1 f0f0 f2f2 f1f1 f1f1 f0f0
17
6/12/2016 Prepared by Dr.Saad Alabbad17 Recursive Definitions: Fibonacci Recursive Algorithm Fibonacci Algorithm int fib(int n) { if (n == 0) return 0; if (n == 1) return 1; return fib(n-1)+ fib(n-2); } f5f5 f4f4 f3f3 f3f3 f2f2 f2f2 f1f1 f0f0 f1f1 f1f1 f0f0 f2f2 f1f1 f1f1 f0f0
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.