Download presentation
Presentation is loading. Please wait.
Published byErin Poppy Rodgers Modified over 8 years ago
1
Induction and Recursion CSC-2259 Discrete Structures Konstantin Busch - LSU1
2
Induction Konstantin Busch - LSU2 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
3
Konstantin Busch - LSU3 Use induction to prove that a proposition is true: Inductive Basis: Inductive Hypothesis: Inductive Step: Prove that is true Assume is true Prove that is true (for any positive integer k)
4
Konstantin Busch - LSU4 Inductive Step:Prove that is true Inductive Hypothesis:Assume is true In other words in inductive step we prove: (for any positive integer k) for every positive integer k
5
Konstantin Busch - LSU5 True Inductive basis Inductive Step Proposition true for all positive integers
6
Konstantin Busch - LSU6 Induction as a rule of inference:
7
7 Inductive Basis: Inductive Hypothesis: Inductive Step: K. Busch - LSU Theorem: Proof: We will prove assume that it holds
8
Konstantin Busch - LSU8 Inductive Step: (inductive hypothesis) End of Proof
9
Konstantin Busch - LSU9 Harmonic numbers Example:
10
Konstantin Busch - LSU10 Theorem: Proof: Inductive Basis:
11
Konstantin Busch - LSU11 Inductive Hypothesis: Suppose it holds: Inductive Step: We will show:
12
Konstantin Busch - LSU12 End of Proof from inductive hypothesis
13
Konstantin Busch - LSU13 Theorem: Proof: Inductive Basis:
14
Konstantin Busch - LSU14 Inductive Hypothesis: Suppose it holds: Inductive Step: We will show:
15
Konstantin Busch - LSU15 End of Proof from inductive hypothesis
16
Konstantin Busch - LSU16 We have shown: It holds that:
17
Konstantin Busch - LSU17 hole Triominos
18
Konstantin Busch - LSU18 Theorem:Every checkerboard with one square removed can be tiled with triominoes Proof: Inductive Basis: hole
19
Konstantin Busch - LSU19 Inductive Hypothesis: Hole can be anywhere Assume that a checkerboard can be tiled with the hole anywhere
20
Konstantin Busch - LSU20 Inductive Step:
21
Konstantin Busch - LSU21 By inductive hypothesis squares with a hole can be tiled add three artificial holes
22
Konstantin Busch - LSU22 2 3 x 2 3 case:
23
Konstantin Busch - LSU23 Replace the three holes with a triomino Now, the whole area can be tiled
24
Konstantin Busch - LSU24 End of Proof 2 3 x 2 3 case:
25
Strong Induction Konstantin Busch - LSU25 Inductive Basis: Inductive Hypothesis: Inductive Step: Prove that is true Assume is true Prove that is true To prove :
26
Konstantin Busch - LSU26 Theorem: Every integer is a product of primes (at least one prime in the product) Proof: Inductive Basis: Number 2 is a prime Inductive Hypothesis: Suppose that every integer between and is a product of primes (Strong Induction)
27
Konstantin Busch - LSU27 Inductive Step: If is prime then the proof is finished If is not a prime then it is composite:
28
Konstantin Busch - LSU28 By the inductive hypothesis: primes End of Proof
29
Konstantin Busch - LSU29 Theorem: Every postage amount can be generated by using 4-cent and 5-cent stamps Proof: Inductive Basis: We examine four cases (because of the inductive step) (Strong Induction)
30
Konstantin Busch - LSU30 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
31
Consider: Konstantin Busch - LSU31 Inductive hypothesis End of Proof
32
Factorial function Recursion Konstantin Busch - LSU32 Recursion is used to describe functions, sets, algorithms Example: Recursive Step: Recursive Basis:
33
Konstantin Busch - LSU33 factorial( ) { if then return else return } //recursive basis //recursive step Recursive algorithm for factorial
34
Konstantin Busch - LSU34 Fibonacci numbers Recursive Basis: Recursive Step:
35
Konstantin Busch - LSU35
36
Konstantin Busch - LSU36 fibonacci( ) { if then return else return } //recursive basis //recursive step Recursive algorithm for Fibonacci function
37
Konstantin Busch - LSU37 fibonacci( ) { if then else { for to do { } return } Iterative algorithm for Fibonacci function
38
Konstantin Busch - LSU38 Theorem: (golden ratio) for Proof:Proof by (strong) induction Inductive Basis:
39
We will prove for Konstantin Busch - LSU39 Inductive Hypothesis: Inductive Step: Suppose it holds
40
Konstantin Busch - LSU40 is the solution to equation End of Proof induction hypothesis
41
Konstantin Busch - LSU41 Greatest common divisor Recursive Step: Recursive Basis:
42
Konstantin Busch - LSU42 gcd( ) { if then return else return } //recursive basis //recursive step Recursive algorithm for greatest common divisor //assume a>b
43
Konstantin Busch - LSU43 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
44
Konstantin Busch - LSU44 first zeroresult divisions remainder
45
Konstantin Busch - LSU45 This holds since and is integer
46
Konstantin Busch - LSU46 This holds since
47
Konstantin Busch - LSU47 End of Proof
48
Konstantin Busch - LSU48 Algorithm Mergesort 8 2 4 6 9 7 10 1 5 3 8 2 4 6 97 10 1 5 3 2 4 6 8 9 1 3 5 7 10 1 2 3 4 5 6 7 8 9 10 split sort merge
49
Konstantin Busch - LSU49 sort( ) { if then { return } else return }
50
Konstantin Busch - LSU50 8 2 4 6 9 7 10 1 5 3 Input values of recursive calls 8 2 4 6 97 10 1 5 3 8 2 46 97 10 15 3 4 8 269 82 7 101 710 53
51
Konstantin Busch - LSU51 1 2 3 4 5 6 7 8 9 10 Input and output values of merging 2 4 6 8 91 3 5 7 10 2 4 86 97 10 15 3 4 2 869 82 7 101 710 53
52
Konstantin Busch - LSU52 merge( ) { while do { Remove smaller first element of from its list and insert it to } if then { append remaining elements to } return } //two sorted lists
53
Konstantin Busch - LSU53 2 4 6 8 9 2 4 86 9 merging Comparison 24 8 4 8 8 69 9 2 2 4 24 6 34 6 8 2 4 6 8 9 2<6 4<6 6<8 8<9
54
Konstantin Busch - LSU54 The total number of comparisons to merge two lists is at most: Length of ALength of B Merged size
55
Konstantin Busch - LSU55 Recursive invocation tree Assume
56
Konstantin Busch - LSU56 Elements per list #levels of tree = Assume Recursive invocation tree
57
Konstantin Busch - LSU57 merging tree
58
Konstantin Busch - LSU58 merging tree Elements per list
59
Konstantin Busch - LSU59 Merges per level Total cost: merging tree Comparisons per level Elements per merge
60
If the number of comparisons is at most Konstantin Busch - LSU60 If the number of comparisons is at most Time complexity of merge sort:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.