induction and recursion sections 4 1 4 3 section 4 4
play

Induction and Recursion (Sections 4.1-4.3) [Section 4.4 optional] - PDF document

Induction and Recursion (Sections 4.1-4.3) [Section 4.4 optional] Based on Rosen and slides by K. Busch 1 Induction Induction is a very useful proof technique In computer science, induction is used to prove properties of algorithms


  1. Induction and Recursion (Sections 4.1-4.3) [Section 4.4 optional] Based on Rosen and slides by K. Busch 1 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 2 1

  2. Use induction to prove that a proposition is true: ( n ) P Inductive Basis: Prove that is true ( 1 ) P Inductive Hypothesis: Assume is true ( k ) P (for any positive integer k) (  Inductive Step: Prove that is true 1 ) P k 3 Inductive Hypothesis: Assume is true ( k ) P (for any positive integer k) (  Inductive Step: Prove that is true 1 ) P k In other words in inductive step we prove:   ( ) ( 1 ) P k P k for every positive integer k 4 2

  3. Inductive basis Inductive Step   ( ) ( 1 ) P k P k ( 1 ) P True True Proposition true for all positive integers     ( 1 ) ( 2 ) ( 3 ) ( 4 )  P P P P 5 Induction as a rule of inference:       [ ( 1 ) ( ( ) ( 1 ))] ( ) P k P k P k nP n 6 3

  4.  ( 1 ) n n      Theorem:  ( ) : 1 2 3 P n n 2 Proof:  1 ( 1 1 ) Inductive Basis:  ( 1 ) : 1 P 2 Inductive Hypothesis: assume that it holds  ( 1 ) k k     ( ) : 1 2 P k k 2 Inductive Step: We will prove    ( 1 )(( 1 ) 1 ) k k        ( 1 ) : 1 2 ( 1 ) P k k k 2 7 Inductive Step: (inductive       ( 1 ) : 1 2 ( 1 ) P k k k hypothesis)  ( 1 ) k k    ( 1 ) k 2    ( 1 ) 2 ( 1 ) k k k  2    ( 1 )(( 1 ) 1 ) k k  2 End of Proof 8 4

  5. Harmonic numbers 1 1 1 1        1 H j 2 3 4 j  1 , 2 , 3 ,  j 1 1 1 25      Example: 1 H 4 2 3 4 12 9 n Theorem:    1 H 0 n n 2 2 Proof:  Inductive Basis: 0 n 0 n        1 1 1 H H H 0 1 n 2 2 2 2 10 5

  6. n  Inductive Hypothesis: k k   Suppose it holds: 1 H k 2 2  k  Inductive Step: 1 n  1 k   We will show: 1 H  1 k 2 2 11 1 1 1 1 1           1 H    k 1 1 2 k k k 2 3 2 2 1 2 1 1      H   k 1 2 k k 2 1 2    from inductive 1 1 k        1   hypothesis   1 k k 2 2 1 2    1 k      k 1 2    1 k 2 2    1 k     1   2 2  1 k   1 End of Proof 2 12 6

  7. Theorem:  1   H n 0 n n 2 Proof:  Inductive Basis: 0 n        1 1 0 1 H H H n n 0 1 2 2 13 n  Inductive Hypothesis: k  1  Suppose it holds: H k k 2  k  Inductive Step: 1 n We will show:    1 ( 1 ) H k  1 k 2 14 7

  8. 1 1 1 1 1           1 H   1  k 1 2 k k k 2 3 2 2 1 2 1 1      H   k 2 k k 1 2 1 2 from inductive 1 1         1 k hypothesis   1 k k 2 1 2 1       k 1 2 k  k 2 1      1 1 k    1 ( 1 ) k End of Proof 15 n     We have shown: 1 1 H n n 2 2   log k       1 1 log H k k 2  log H k k (for large k ) 16 8

  9. Triominos 2  3 3 2 2  2 2 2 2  2 hole hole hole 17   Theorem: Every checkerboard n n 2 2 , 1 n with one square removed can be tiled with triominoes Proof:  Inductive Basis: 1 n 2  1 1 2 hole 18 9

  10. n  Inductive Hypothesis: k 2  Assume that a checkerboard k k 2 can be tiled with the hole anywhere 2  k k 2 Hole can be anywhere 19  k  Inductive Step: 1 n    1 1 k k 2 2 20 10

  11. By inductive hypothesis squares 2  k k 2 with a hole can be tiled 2  2  k k k k 2 2 add three artificial holes 21 2 3 x 2 3 case: 22 11

  12. 2  2  k k k k 2 2 Replace the three holes with a triomino Now, the whole area can be tiled 23 2 3 x 2 3 case: End of Proof 24 12

  13. Strong Induction To prove : ( n ) P Inductive Basis: Prove that is true ( 1 ) P Inductive Hypothesis:    Assume is true  ( 1 ) ( 2 ) ( ) P P P k (  Inductive Step: Prove that is true 1 ) P k 25 Theorem: Every integer  2 n is a product of primes (Fundamental Theorem of Arithmetic) Proof: (Strong Induction)  Inductive Basis: 2 n Number 2 is a prime  n  Inductive Hypothesis: 2 k Suppose that every integer between and is a product of primes 2 k 26 13

  14.  k  Inductive Step: 1 n  If is prime then the proof is finished 1 k  If is not a prime then it is composite: 1 k  1    ,  2 k a b a b k 27  1    ,  2 k a b a b k By the inductive hypothesis:  , 1 i j   a p p p     1 2 i   1 k a b p p q q 1 1 i j   b q q q primes 1 2 j primes End of Proof 28 14

  15. Theorem: Every postage amount  12 n 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)         12 4 4 4 14 5 5 4 n n         13 4 4 5 15 5 5 5 n n 29  n  Inductive Hypothesis: 12 k Assume that every postage amount between and can be generated 12 k by using 4-cent and 5-cent stamps     4 5 n a b  k  Inductive Step: 1 n  k  If then the inductive step 12 14 follows directly from inductive basis 30 15

  16.      Consider: 15 1 ( 3 ) 4 k k k    12 ( 3 ) k k Inductive hypothesis        ( 3 ) 4 5 k a b            1 ( 3 ) 4 ( 1 ) 4 5 k k a b End of Proof 31 Recursion Recursion is used to describe functions, sets, algorithms  Example: Factorial function ( ) ! f n n  Recursive Basis: ( 0 ) 1 f     Recursive Step: ( 1 ) ( 1 ) ( ) f n n f n 32 16

  17. Recursive algorithm for factorial factorial( ) { n  if then //recursive basis 1 n return 1 else //recursive step return n  factorial( n- 1 ) } 33 Fibonacci numbers  , , , , f f f f 0 1 2 3   Recursive Basis: 0 , 1 f f 0 1    Recursive Step: f f f  1 2 n n n   2 , 3 , 4 , n 34 17

  18.  0 f 0  1 f 1      1 0 1 f f f 2 1 0      1 1 2 f f f 3 2 1      2 1 3 f f f 4 3 2      3 2 5 f f f 5 4 3      5 3 8 f f f 6 5 4      8 5 13 f f f 7 6 5  35 Recursive algorithm for Fibonacci function fibonacci( ) { n if then  //recursive basis { 0 , 1 } n return n else //recursive step return n-  fibonacci( 1 ) fibonacci( 2 ) n- } 36 18

  19. Iterative algorithm for Fibonacci function fibonacci( ) { n  if then  0 0 y n else {  0 x  1 y   for to do { 1 1 i n   z x y x  y y  z } return y } 37    Theorem: 2 n for f  3 n n 1  5   (golden ratio) 2 Proof: Proof by (strong) induction   Inductive Basis: 3 4 n n  2   f 3    2 3 f 4 38 19

  20.  n  Inductive Hypothesis: 3 k    Suppose it holds 2 n f n  k  Inductive Step: 1 n      We will prove for ( 1 ) k 4 f k k 1 39   x   is the solution to equation 2 1 0 x     2 1                   1 2 3 3 2 3 k k k k k ( 1 )            2 3 1 k k k f f f   1 1 k k k induction hypothesis End of Proof 40 20

  21. Euclidean Algorithm for Greatest Common Divisor Recursive Basis:  gcd( , 0 ) a a  Recursive Step: gcd( , ) gcd( , mod ) a b b a b a  b 41 Recursive Euclidean algorithm for greatest common divisor gcd( ) { //assume a>b a , b if then  //recursive basis 0 b return a else //recursive step return gcd(b, mod ) a b } 42 21

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend