22C:19 Discrete Structures Discrete Probability Fall 2014 Sukumar Ghosh.
22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.
-
Upload
brook-hall -
Category
Documents
-
view
215 -
download
1
Transcript of 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.
![Page 1: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/1.jpg)
22C:19 Discrete MathInduction and Recursion
Fall 2011Sukumar Ghosh
![Page 2: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/2.jpg)
What is mathematical induction?
It is a method of proving that something holds.
Suppose we have an infinite ladder, and we want to knowif we can reach every step on this ladder.
We know the following two things:
1. We can reach the base of the ladder2. If we can reach a particular step, then we can reach the
next step
Can we conclude that we can reach every step of the ladder?
![Page 3: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/3.jpg)
Understanding induction
Suppose we want to prove that P(x) holds for all x
![Page 4: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/4.jpg)
Proof structure
![Page 5: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/5.jpg)
Example 1
![Page 6: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/6.jpg)
Example continued
![Page 7: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/7.jpg)
Example continued
![Page 8: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/8.jpg)
What did we show?
![Page 9: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/9.jpg)
Example 2
![Page 10: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/10.jpg)
Example continued
![Page 11: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/11.jpg)
Example continued
![Page 12: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/12.jpg)
Example 3
![Page 13: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/13.jpg)
Strong induction
![Page 14: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/14.jpg)
Example
![Page 15: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/15.jpg)
Proof using Mathematical Induction
![Page 16: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/16.jpg)
Same Proof using Strong Induction
![Page 17: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/17.jpg)
Errors in Induction
Question: What is wrong here?
![Page 18: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/18.jpg)
Errors in Induction
Question: What is wrong here?
![Page 19: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/19.jpg)
Recursion
Recursion means defining something, such as a
function, in terms of itself
– For example, let f(x) = x!
– We can define f(x) as f(x) = x * f(x-1)
![Page 20: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/20.jpg)
Recursive definition
Two parts of a recursive definition: Base case and a Recursive step
.
![Page 21: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/21.jpg)
Recursion example
![Page 22: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/22.jpg)
Fibonacci sequence
![Page 23: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/23.jpg)
Bad recursive definitions
Why are these definitions bad?
![Page 24: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/24.jpg)
More examples of recursion: defining strings
![Page 25: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/25.jpg)
Structural induction
A technique for proving a property of a recursively defined object.It is very much like an inductive proof, except that in the inductive step we try to show that if the statement holds for each of the element used to construct the new element, then the result holds for the new element too.
Example. Prove that if T is a full binary tree, and h(T) is the height of the tree then the number of elements in the tree n(T) ≤ 2 h(T)+1 -1.
See the textbook (pages 306-307) for a solution.
![Page 26: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/26.jpg)
Recursive Algorithm
Example 1. Given a and n, compute an
procedure power (a : real number, n: non-negative integer)
if n = 0 then power (a, n) := 1
else power (a, n) := a. power (a, n-1)
![Page 27: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/27.jpg)
Recursive algorithms: Sorting
Here is the recursive algorithm Merge sort. It merges two sortedIists to produce a new sorted list
8 2 4 6 10 1 5 3
8 2 4 6 10 1 5 3
8 2 4 6 10 1 5 3
![Page 28: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/28.jpg)
Mergesort
The merge algorithm “merges” two sorted lists
2 4 6 8 merged with 1 3 5 10 will produce 1 2 3 4 5 6 8 10
procedure mergesort (L = a1, a2, a3, … an)
if n > 0 then
m:= n/2
L1 := a1, a2, a3, … am
L2 := am+1, am+2, am+3, … an
L := merge (mergesort(L1), mergesort(L2))
![Page 29: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/29.jpg)
Example of Mergesort
8 2 4 6 10 1 5 3
8 2 4 6 10 1 5 3
8 2 4 6 10 1 5 32 8 4 6 1 10 3 5
2 4 6 8 1 3 5 10
1 2 3 4 5 6 8 10
![Page 30: 22C:19 Discrete Math Induction and Recursion Fall 2011 Sukumar Ghosh.](https://reader038.fdocuments.in/reader038/viewer/2022103123/56649dac5503460f94a9b15b/html5/thumbnails/30.jpg)
Pros and Cons of RecursionWhile recursive definitions are easy to understand
Iterative solutions for Fibonacci sequence are much faster (see 316-317)