cs 23022 discrete mathematical structures
DESCRIPTION
CS 23022 Discrete Mathematical Structures. Mehdi Ghayoumi MSB rm 132 [email protected] Ofc hr: Thur, 9:30-11:30a. Announcements. There is no Homework !!! Next session we have a quiz for Induction. No. { x Z : x < 0 } has no least element. Mathematical Induction - why does it work?. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/1.jpg)
CS 23022Discrete Mathematical Structures
Mehdi GhayoumiMSB rm [email protected] Ofc hr: Thur, 9:30-11:30a
![Page 2: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/2.jpg)
Announcements
There is no Homework!!!
Next session we have a quiz for Induction
![Page 3: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/3.jpg)
Mathematical Induction - why does it work?
Definition:
A set S is “well-ordered” if every non-empty subset of S has a least element.
Examples:
the set of natural numbers (N) is well-ordered.
Is the set of integers (Z) well ordered?
No. { x Z : x < 0 }
has no least element.
![Page 4: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/4.jpg)
Mathematical Induction - why does it work?
Is the set of non-negative reals (R) well ordered?
No. { x R : x > 1 }
has no least element.
![Page 5: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/5.jpg)
Strong Mathematical InductionAn example.
Given n blue points and n orange points in a plane with no 3 collinear, prove there is a way to match
them, blue to orange, so that none of the segments between the pairs intersect.
![Page 6: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/6.jpg)
Strong Mathematical InductionBase case (n=1):
Assume any matching problem of size less than (k+1) can be solved.
Show that we can match (k+1) pairs.
![Page 7: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/7.jpg)
Strong Mathematical InductionShow that we can match (k+1) pairs.
Suppose there is a line partitioning the group into a smaller one of j blues and j oranges, and another smaller one of (k+1)-j blues and (k+1)-j oranges.
OK!! (by IH)
OK!! (by IH)
![Page 8: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/8.jpg)
Strong Mathematical InductionHow do we know such a line always exists?
Consider the convex hull of the points:
If there is an alternating pair of colors on the hull, we’re done!
OK!! (by IH)
OK!! (by IH)
![Page 9: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/9.jpg)
Strong Mathematical InductionIf there is no alternating pair, all points on hull are
the same color.
Notice that any sweep of the hull hits an orange point first and also last. We sweep on some slope not given by a pair of points.
OK!! (by IH)
OK!! (by IH)
Keep score of # of each color seen. Orange gets the early lead, and then comes from behind to tie at the end.
There must be a tie along the way
![Page 10: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/10.jpg)
Strings and Inductive DefinitionsLet be a finite set called an alphabet.
The set of strings on , denoted * is defined as:
*, where denotes the null or empty string.
If x , and w *, then wx *, where wx is the
concatenation of string w with symbol x.
![Page 11: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/11.jpg)
Strings and Inductive Definitions
Countably infinite
Example: Let = {a, b, c}. Then
* = {, a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa, aab,…}
How big is *?
Is there a largest string in *? No.
![Page 12: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/12.jpg)
Strings and Inductive DefinitionsInductive definition of the length of strings
(the length of string w is |w|.):
|| = 0
If x , and w *, then |wx| = |w| + 1
I point this out because the length of strings is something
we might like to use for an inductive argument.
![Page 13: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/13.jpg)
Strings and Inductive DefinitionsInductive definition of the reversal of a string
(the reversal of string w is written wR.):R =
If x , and w *, then (wx)R = ? For example (abc)R = cbax(w)R
For example (abc)R = c(ab)R
= cb(a)R
= cba()R
= cba= cba
![Page 14: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/14.jpg)
Strings and Inductive DefinitionsA Theorem:
x,y * (xy)R = yRxR
Proof (by induction on |y|):Base Case (|y| = 0): If |y| = 0, y = , then (xy)R = (x)R = xR = xR =
yRxR.IH: If |y| n, then x *, (xy)R = yRxR.
Prove: If |y| = n+1, then x *, (xy)R = yRxR.
![Page 15: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/15.jpg)
Strings and Inductive DefinitionsIH: If |y| n, then x *, (xy)R = yRxR.
Prove: If |y| = n+1, then x *, (xy)R = yRxR.If |y| = n+1, then a , u *, so
that y = ua, and |u| = n.Then, (xy)R = (x(ua))R by substitution
= ((xu)a)R by assoc. of concatenation = a(xu)R by inductive defn of reversal = auRxR by IH
= (ua)RxR by inductive defn of reversal = yRxR by substitution
![Page 16: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/16.jpg)
AlgorithmsAn iterative algorithm is one that repeats the same sequence of
steps a number of times.
for loops
while loops
repeat loops
goto??
The running time of an iterative algorithm depends on the number of times the loop is invoked.
![Page 17: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/17.jpg)
AlgorithmsHow many times does “twiddle-thumbs” happen?
1. for i = 1 to n2. for j = 1 to m
3. twiddle-thumbs
The “time complexity” of an algorithm is a measure of its running time.
But different machines run at different speeds!
So we give running times in terms of big-oh, since different machines affect run times by constant factors.
Complexity is O(mn)
![Page 18: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/18.jpg)
Inductive DefinitionsWe completely understand the function f(n) = n!,
right?
As a reminder, here’s the definition:n! = 1 · 2 · 3 · … · (n-1) · n, n 1
Inductive (Recursive) Definition
But equivalently, we could define it like this:
n!n (n 1)!, if n 11, if n 1
Recursive Case
Base Case
![Page 19: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/19.jpg)
Inductive DefinitionsAnother VERY common example:
Fibonacci Numbers
Recursive Case
Base Cases
f (n) 0 if n 01 if n 1f (n 1) f (n 2) if n 1
Is there a non-recursive definition for the Fibonacci
Numbers?
![Page 20: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/20.jpg)
Inductive DefinitionsFibonacci Numbers
double fib(int n) { double prev = -1; double result = 1; double sum; int i; for(i = 0;i <= n;++ i) { sum = result + prev; prev = result; result = sum; } return result; }
![Page 21: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/21.jpg)
AlgorithmsAlgorithm MAX
Input: x1, x2, …, xn, an array of numbersOutput: y, the maximum of x1, x2, …, xn
1. for j = 1 to n-12. if xj > xj+1 then3. temp = xj+1 4. xj+1 = xj
5. xj = tempComplexity is O(n)
vars x1 x2 x3 x4
input 3 2 4 1j = 1 3 2 4 1j = 2 2 3 4 1j = 3 2 3 4 1final 2 3 1 4
![Page 22: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/22.jpg)
AlgorithmsAlgorithm BUBBLE
Input: x1, x2, …, xn, an array of numbersOutput: ??
1. for j = n downto 22. MAX(x1,x2,…,xj)
3. output ??
A reasonable output for this function would be:A. x1, the minimum element of the arrayB. xn, the max element of the arrayC. The entire array… it has now been sortedD. j the loop counter
![Page 23: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/23.jpg)
Algorithms
![Page 24: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/24.jpg)
Algorithms
![Page 25: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/25.jpg)
Algorithmsint main() { int array[BUBBLE], i, j,temp = 0; for (i = 0; i < BUBBLE; i ++) { cout<<“…”;for (j = 0; j < BUBBLE; j++); { temp = array[j+1]; array[j+1] = array[j]; array[j] = temp; } } return 0; }
![Page 26: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/26.jpg)
AlgorithmsThe running time of this algorithm is:
A. O(n log n)
B. O(n)
C. O(n2)
D. None of the above.
![Page 27: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/27.jpg)
Running timesIt’s fun to make comparisons about the running times of
algorithms of various complexities. Inp size
compxity
10 20 30 40 50 60
n .00001s .00002s .00003s .00004s .00005
s .00006s
n2 .0001s .0004s .0009s .0016s .0025s .0036s
n5 .1s 3.2s 24.3s 1.7m 5.2m 13m
3n .059s 58m 6.5y 3855c 2x108c 1.3x1013c
But computers are getting
faster! Maybe we can do
better.
![Page 28: CS 23022 Discrete Mathematical Structures](https://reader035.vdocuments.us/reader035/viewer/2022062811/568161b3550346895dd17a8a/html5/thumbnails/28.jpg)