390 likes | 509 Views
CSci 2011 Discrete Mathematics Lecture 21. Yongdae Kim. Admin. Due dates and quiz Groupwork 10 is due on Nov 16 th . Homework 6 is due on Dec 2 nd . Quiz 6: Dec 9 th . 1 page cheat sheet is allowed. E-mail: csci2011-help@cselabs.umn.edu Put [2011] in front. Check class web site
E N D
CSci 2011 Discrete MathematicsLecture 21 Yongdae Kim CSci 2011
Admin • Due dates and quiz • Groupwork 10 is due on Nov 16th. • Homework 6 is due on Dec 2nd. • Quiz 6: Dec 9th. • 1 page cheat sheet is allowed. • E-mail: csci2011-help@cselabs.umn.edu • Put [2011] in front. • Check class web site • Read syllabus, Use forum. CSci 2011
Graphs CSci 2011
Total CSci 2011
Recap • Propositional operation summary • Check translation • Definition • Tautology, Contradiction, logical equicalence CSci 2011
Recap CSci 2011
Recap • Quantifiers • Universal quantifier: x P(x) • Negating quantifiers • ¬x P(x) = x ¬P(x) • ¬x P(x) = x ¬P(x) xy P(x, y) • Nested quantifiers • xy P(x, y): “For all x, there exists a y such that P(x,y)” • xy P(x,y): There exists an x such that for all y P(x,y) is true” • ¬x P(x) = x ¬P(x), ¬x P(x) = x ¬P(x) CSci 2011
Recap CSci 2011
Recap • p→q • Direct Proof: Assume p is true. Show that q is also true. • Indirect Proof: Assume ¬q is true. Show that p is true. • Proof by contradiction • Proving p: Assume p is not true. Find a contradiction. • Proving p→q • ¬(p→q) (p q) p ¬q • Assume p is tue and q is not true. Find a contradiction. • Proof by Cases: [(p1p2…pn)q] [(p1q)(p2q)…(pnq)] • If and only if proof: pq (p→q)(q→p) • Existence Proof: Constructive vs. Non-constructive Proof • Uniqueness: 1) Show existence 2) find contradiction if not unique • Forward and backward reasoning • Counterexample CSci 2011
What is a set? • A set is a unordered collection of “objects” • set-builder notation: D = {x | x is prime and x > 2} • a S if an elementa is an element of a set S. a S if not. • U is the universal set. • empty (or null) set = { }, if a set has zero elements. • S T if x (x S x T), S = T if S T and if T S. • S T if S is a subset of T, and S is not equal to T. • The cardinality of a set, |A| is the number of elements in a set. • The power set of S, P(S), is the set of all the subsets of S. • If a set has n elements, then the power set will have 2n elements • A x B = { (a,b) | a A and b B } • A U B = { x | x A or x B } • A ∩ B = { x | x A and x B } • two sets are disjoint if their intersection is the empty set • A - B = { x | x A and x B } • Ac = { x | x A } CSci 2011
Set identities CSci 2011
Functions • A function takes an element from a set and maps it to a UNIQUE element in another set • Domain, co-domain, range • A function f is one-to-one (injection) if f(x) = f(y) implies x = y. • A function f is onto (surjection) if for all y C, there exists x D such that f(x)=y. • A function f is bijection if it is 1-1 and onto. • A function f is an identity function if f(x)=x. • Composition of functions: (f°g)(x) = f(g(x)). • f-1 is an inverse function of f if (f°f-1)(x)=(f-1°f)(x)=x. CSci 2011
Recap • Useful functions • x = n if and only if n ≤ x < n+1 • x = n if and only if n-1 < x ≤ n • round(x) = x+0.5 • n! = n * (n-1) * (n-2) * … * 2 * 1 • Sequence and Series • Arithmetic Progression: a, a+d, a+2d, …, a+nd, … • an = a + (n-1) d • Geometric Progression: a, ar, ar2, ar3, …, arn-1, … • an = arn-1 • 1 + 2 + 3 + … + n = n(n+1)/2 n 1 ar a + - n if r 1 j ar r 1 = - j 0 ( n 1 ) a if r 1 = + = CSci 2011
Recap • For finite and infinite sets, two sets A and B have the same cardinality if there is a one-to-one correspondence from A to B • Countably infinite: elements can be listed • Anything that has the same cardinality as the integers • Uncountably infinite: elements cannot be listed • An algorithm is “a finite set of precise instructions for performing a computation or for solving a problem” • Complexity • f(x)O(g(x)) if kR, cR, xR, xk 0f(x)|cg(x)|. • f(x)(g(x)) if kR, cR, xR, xk f(x)| c g(x)|. • f(x)(g(x)) if f(x)O(g(x)) and f(x)(g(x)). Equivalently, if kR, c1,c2R, xR, xk c1 |g(x)| |f(x)| c2 |g(x)|. CSci 2011
Recap • Def: a | b (a (a0) divides b) if c such that b = ac. • Theorem: Let a, b, c be integers. Then • a | b, a | c a | (b + c) • a | b a | bc c Z. • a | b, b | c a | c. • a, b Z, m Z+, a b mod m iff m | (a - b) iff k such that a=b+km. • a b mod m, c d mod m a + c b + d mod m, ac bd mod m. • p Z+ is prime if the only positive factors of p are 1 and p. n is composite if a such that a | n and 1 < a < n. • If n is composite then a such that a | n and a < √n. • gcd(a, b): the largest d Z such that d | a and d | b. Formally, • d | a, d | b • e | a, e | b e | d • a and b are relatively prime if gcd (a,b) = 1 • a1, a2, … an are pairwise relatively prime if gcd(ai, aj) = 1 for 1≤i<j≤n. • Algorithms: DecToBin, Eucledean, Square-and-multiply CSci 2011
Recap • Induction • Strong mathematical induction assumes P(1), P(2), …, P(k) are all true, and uses that to show that P(k+1) is true. [P(1) P(2) p(3) … P(k) ] P(k+1) • If there are n1 ways to do task 1, and n2 ways to do task 2 • Then there are n1n2 ways to do both tasks in sequence • If there are n1 ways to do task 1, and n2 ways to do task 2 • If these tasks can be done at the same time, • Then there are n1+n2 ways to do one of the two tasks • Pigeon-hole principle: If N objects are placed into k boxes, then there is at least one box containing N/k objects • A permutation is an ordered arrangement of the elements of some set S: P(n, r) = n! / (n-r)!. • When order does not matter, it is called combination: C(n, r) = n! / (r! (n-r)!) • C(n,r) = C(n,n-r), n+1Ck= nCk+nCk-1, i=0nnCi = 2n • A combinatorial proof is a proof that uses counting arguments to prove a theorem • (x+y)n= i=0nnCi xi yn-i CSci 2011
Proof practice: corollary 2 • Let n be a non-negative integer. Then i=0n (-1)nnCi = 0 • Algebraic proof • Binomial equation: (x+y)n = i=0nnCi xiyn-i • Put x=-1, and y = 1 • 0 = i=0n (-1)nnCi CSci 2011
Vandermonde’s identity • Let m, n, and r be non-negative integers with r not exceeding either m or n. Then m+rCn = i=0r (mCr-inCi) • Consider two sets, one with m items and one with n items • Then there are m+rCn ways to choose r items from the union of those two sets • Next, we’ll find that value via a different means • Pick i elements from the set with n elements • Pick the remaining r-i elements from the set with m elements • Via the product rule, there are mCr-inCi ways to do that for EACH value of i • Lastly, consider this for all values of i. CSci 2011
ch 6.1 Discrete Probability Yongdae Kim CSci 2011
Terminology • Experiment • A repeatable procedure that yields one of a given set of outcomes • Rolling a die, for example • Sample space • The range of outcomes possible • For a die, that would be values 1 to 6 • Event • One of the sample outcomes that occurred • If you rolled a 4 on the die, the event is the 4 CSci 2011
Probability definition • The probability of an event occurring is: p(E) = |E| / |S| • Where E is the set of desired events (outcomes) • Where S is the set of all possible events (outcomes) • Note that 0 ≤ |E| ≤ |S| • Thus, the probability will always between 0 and 1 • An event that will never happen has probability 0 • An event that will always happen has probability 1 CSci 2011
Dice probability • What is the probability of getting “snake-eyes” (two 1’s) on two six-sided dice? • Probability of getting a 1 on a 6-sided die is 1/6 • Via product rule, probability of getting two 1’s is the probability of getting a 1 AND the probability of getting a second 1 • Thus, it’s 1/6 * 1/6 = 1/36 • What is the probability of getting a 7 by rolling two dice? • There are six combinations that can yield 7: (1,6), (2,5), (3,4), (4,3), (5,2), (6,1) • Thus, |E| = 6, |S| = 36, P(E) = 6/36 = 1/6 CSci 2011
Poker CSci 2011
Playing Card CSci 2011
The game of poker • You are given 5 cards (this is 5-card stud poker) • The goal is to obtain the best hand you can • The possible poker hands are (in increasing order): • No pair • One pair (two cards of the same face) • Two pair (two sets of two cards of the same face) • Three of a kind (three cards of the same face) • Straight (all five cards sequentially – ace is either high or low) • Flush (all five cards of the same suit) • Full house (a three of a kind of one face and a pair of another face) • Four of a kind (four cards of the same face) • Straight flush (both a straight and a flush) • Royal flush (a straight flush that is 10, J, K, Q, A) CSci 2011
Poker probability: royal flush • What is the chance ofgetting a royal flush? • That’s the cards 10, J, Q, K, and A of the same suit • There are only 4 possible royal flushes • Possibilities for 5 cards: C(52,5) = 2,598,960 • Probability = 4/2,598,960 = 0.0000015 • Or about 1 in 650,000 CSci 2011
Poker probability: four of a kind • What is the chance of getting 4 of a kind when dealt 5 cards? • Possibilities for 5 cards: C(52,5) = 2,598,960 • Possible hands that have four of a kind: • There are 13 possible four of a kind hands • The fifth card can be any of the remaining 48 cards • Thus, total possibilities is 13*48 = 624 • Probability = 624/2,598,960 = 0.00024 • Or 1 in 4165 CSci 2011
Poker probability: flush • What is the chance of getting a flush? • That’s all 5 cards of the same suit • We must do ALL of the following: • Pick the suit for the flush: C(4,1) • Pick the 5 cards in that suit: C(13,5) • As we must do all of these, we multiply the values out (via the product rule) • This yields C(4,1) C(13,5) = 5148 • Possibilities for 5 cards: C(52,5) = 2,598,960 • Probability = 5148/2,598,960 = 0.00198 • Or about 1 in 505 CSci 2011
Inclusion-exclusion principle • The possible poker hands are (in increasing order): • Nothing • One pair cannot include two pair, three of a kind, four of a kind, or full house • Two pair cannot include three of a kind, four of a kind, or full house • Three of a kind cannot include four of a kind or full house • Straight cannot include straight flush or royal flush • Flush cannot include straight flush or royal flush • Full house • Four of a kind • Straight flush cannot include royal flush • Royal flush CSci 2011
Poker probability: three of a kind • What is the chance of getting a three of a kind? • That’s three cards of one face • Can’t include a full house or four of a kind • We must do ALL of the following: • Pick the face for the three of a kind: C(13,1) • Pick the 3 of the 4 cards to be used: C(4,3) • Pick the two other cards’ face values: C(12,2) • We can’t pick two cards of the same face! • Pick the suits for the two other cards: C(4,1)*C(4,1) • As we must do all of these, we multiply the values out (via the product rule) • This yields C(13,1) C(4,3) C(12,2) C(4,1) C(4,1) = 54,912 • Possibilities for 5 cards: C(52,5) = 2,598,960 • Probability = 54,912/2,598,960 = 0.0211 • Or about 1 in 47 CSci 2011
Poker hand odds • The possible poker hands are (in increasing order): • Nothing 1,302,540 0.5012 • One pair 1,098,240 0.4226 • Two pair 123,552 0.0475 • Three of a kind 54,912 0.0211 • Straight 10,200 0.00392 • Flush 5,140 0.00197 • Full house 3,744 0.00144 • Four of a kind 624 0.000240 • Straight flush 36 0.0000139 • Royal flush 4 0.00000154 CSci 2011
More on probabilities • Let E be an event in a sample space S. The probability of the complement of E is: • Recall the probability for getting a royal flush is 0.0000015 • The probability of not getting a royal flush is 1-0.0000015 or 0.9999985 • Recall the probability for getting a four of a kind is 0.00024 • The probability of not getting a four of a kind is 1-0.00024 or 0.99976 CSci 2011
Probability of the union of two events • Let E1 and E2 be events in sample space S • Then p(E1 U E2) = p(E1) + p(E2) – p(E1∩E2) • Consider a Venn diagram dart-board CSci 2011
Probability of the union of two events p(E1 U E2) S E1 E2 CSci 2011
Probability of the union of two events • If you choose a number between 1 and 100, what is the probability that it is divisible by 2 or 5 or both? • Let n be the number chosen • p(2|n) = 50/100 (all the even numbers) • p(5|n) = 20/100 • p(2|n) and p(5|n) = p(10|n) = 10/100 • p(2|n) or p(5|n) = p(2|n) + p(5|n) - p(10|n) = 50/100 + 20/100 – 10/100 = 3/5 CSci 2011
Dealing cards • Consider a dealt hand of cards • Assume they have not been seen yet • What is the chance of drawing a flush? • Does that chance change if I speak words after the experiment has completed? • Does that chance change if I tell you more info about what’s in the deck? • No! • Words spoken after an experiment has completed do not change the chance of an event happening by that experiment • No matter what is said CSci 2011
Monty Hall Paradox CSci 2011
What’s behind door number three? • The Monty Hall problem paradox • Consider a game show where a prize (a car) is behind one of three doors • The other two doors do not have prizes (goats instead) • After picking one of the doors, the host (Monty Hall) opens a different door to show you that the door he opened is not the prize • Do you change your decision? • Your initial probability to win (i.e. pick the right door) is 1/3 • What is your chance of winning if you change your choice after Monty opens a wrong door? • After Monty opens a wrong door, if you change your choice, your chance of winning is 2/3 • Thus, your chance of winning doubles if you change • Huh? CSci 2011
What’s behind door number one hundred? • Consider 100 doors • You choose one • Monty opens 98 wrong doors • Do you switch? • Your initial chance of being right is 1/100 • Right before your switch, your chance of being right is still 1/100 • Just because you know more info about the other doors doesn’t change your chances • You didn’t know this info beforehand! • Your final chance of being right is 99/100 if you switch • You have two choices: your original door and the new door • The original door still has 1/100 chance of being right • Thus, the new door has 99/100 chance of being right • The 98 doors that were opened were not chosen at random! • Monty Hall knows which door the car is behind • Reference: http://en.wikipedia.org/wiki/Monty_Hall_problem CSci 2011