600 likes | 681 Views
Induction and Recursion. CSC-2259 Discrete Structures. 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
E N D
Induction and Recursion CSC-2259 Discrete Structures Konstantin Busch - LSU
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 Konstantin Busch - LSU
Use induction to prove that a proposition is true: Inductive Basis: Prove that is true Inductive Hypothesis: Assume is true (for any positive integer k) Inductive Step: Prove that is true Konstantin Busch - LSU
Inductive Hypothesis: Assume is true (for any positive integer k) Inductive Step: Prove that is true In other words in inductive step we prove: for every positive integer k Konstantin Busch - LSU
Inductive basis Inductive Step True True Proposition true for all positive integers Konstantin Busch - LSU
Induction as a rule of inference: Konstantin Busch - LSU
Theorem: Proof: Inductive Basis: Inductive Hypothesis: assume that it holds Inductive Step: We will prove K. Busch - LSU
Inductive Step: (inductive hypothesis) End of Proof Konstantin Busch - LSU
Harmonic numbers Example: Konstantin Busch - LSU
Theorem: Proof: Inductive Basis: Konstantin Busch - LSU
Inductive Hypothesis: Suppose it holds: Inductive Step: We will show: Konstantin Busch - LSU
from inductive hypothesis End of Proof Konstantin Busch - LSU
Theorem: Proof: Inductive Basis: Konstantin Busch - LSU
Inductive Hypothesis: Suppose it holds: Inductive Step: We will show: Konstantin Busch - LSU
from inductive hypothesis End of Proof Konstantin Busch - LSU
We have shown: It holds that: Konstantin Busch - LSU
Triominos hole hole hole Konstantin Busch - LSU
Theorem: Every checkerboard with one square removed can be tiled with triominoes Proof: Inductive Basis: hole Konstantin Busch - LSU
Inductive Hypothesis: Assume that a checkerboard can be tiled with the hole anywhere Hole can be anywhere Konstantin Busch - LSU
Inductive Step: Konstantin Busch - LSU
By inductive hypothesis squares with a hole can be tiled add three artificial holes Konstantin Busch - LSU
23 x 23 case: Konstantin Busch - LSU
Replace the three holes with a triomino Now, the whole area can be tiled Konstantin Busch - LSU
23 x 23 case: End of Proof Konstantin Busch - LSU
Strong Induction To prove : Inductive Basis: Prove that is true Inductive Hypothesis: Assume is true Inductive Step: Prove that is true Konstantin Busch - LSU
Theorem: Every integer is a product of primes (at least one prime in the product) Proof: (Strong Induction) Inductive Basis: Number 2 is a prime Inductive Hypothesis: Suppose that every integer between and is a product of primes Konstantin Busch - LSU
Inductive Step: If is prime then the proof is finished If is not a prime then it is composite: Konstantin Busch - LSU
By the inductive hypothesis: primes primes End of Proof Konstantin Busch - LSU
Theorem: Every postage amount 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) Konstantin Busch - LSU
Inductive Hypothesis: Assume that every postage amount between and can be generated by using 4-cent and 5-cent stamps Inductive Step: If then the inductive step follows directly from inductive basis Konstantin Busch - LSU
Consider: Inductive hypothesis End of Proof Konstantin Busch - LSU
Recursion Recursion is used to describe functions, sets, algorithms Example: Factorial function Recursive Basis: Recursive Step: Konstantin Busch - LSU
Recursive algorithm for factorial factorial( ) { if then return else return } //recursive basis //recursive step Konstantin Busch - LSU
Fibonacci numbers Recursive Basis: Recursive Step: Konstantin Busch - LSU
Recursive algorithm for Fibonacci function fibonacci( ) { if then return else return } //recursive basis //recursive step Konstantin Busch - LSU
Iterative algorithm for Fibonacci function fibonacci( ) { if then else { for to do { } return } Konstantin Busch - LSU
Theorem: for (golden ratio) Proof: Proof by (strong) induction Inductive Basis: Konstantin Busch - LSU
Inductive Hypothesis: Suppose it holds Inductive Step: We will prove for Konstantin Busch - LSU
is the solution to equation induction hypothesis End of Proof Konstantin Busch - LSU
Greatest common divisor Recursive Basis: Recursive Step: Konstantin Busch - LSU
Recursive algorithm for greatest common divisor gcd( ) { if then return else return } //assume a>b //recursive basis //recursive step Konstantin Busch - LSU
Lames Theorem: The Euclidian algorithm for , uses at most divisions (iterations) Proof: We show that there is a Fibonacci relation in the divisions of the algorithm Konstantin Busch - LSU
remainder divisions first zero result Konstantin Busch - LSU
This holds since and is integer Konstantin Busch - LSU
This holds since Konstantin Busch - LSU
End of Proof Konstantin Busch - LSU
Algorithm Mergesort 8 2 4 6 9 7 10 1 5 3 split 8 2 4 6 9 7 10 1 5 3 sort sort 1 3 5 7 10 2 4 6 8 9 merge 1 2 3 4 5 6 7 8 9 10 Konstantin Busch - LSU
sort( ) { if then { return } else return } Konstantin Busch - LSU
Input values of recursive calls 8 2 4 6 9 7 10 1 5 3 8 2 4 6 9 7 10 1 5 3 8 2 4 6 9 7 10 1 5 3 8 2 6 9 7 10 1 5 3 4 8 2 7 10 Konstantin Busch - LSU