=============================================================== Lect 17 - November 20, 2008 - ECS 20 - Fall 2008 - Phil Rogaway =============================================================== Today: o Quiz answers - avoid garble-speak o Counting (a zillion examples) --------------------------- Quiz answers --------------------------- Formally define what it means for a function f: A -> B to be one-to-one. Random examples of garbled or wrong answers: + \forall x\in A there exists a unique y \in B + (Ax\in \R) (Ax'\in \R) f(x) -> f(x') : x=x' (one value of domain goes to only one value of range) + in function f, for every element in A, there is one and only one element in B each of them can imply to + (\forall b\in B)(\exists ! a \in A (f(a)=B) // Better than the others, // because "wrong", not garbled --------------------------- Side board --------------------------- n! = number of ways to order n different items 2^n = number of subsets of n items P(n,r) = n!/(n-r)! = n*(n-1)*...*(n-r+1) = the number of ways to fill r bins, one item per bin, using items drawn from 1,...,n. No replacement; an item, once used, is gone. C(n,r) = n! / r!(n-r)! = P(n,r)/r! = number of r-element subsets from a set of n different items. No replacement; an item, once used, is gone. product rule = if event A can occur in $a$ ways and, independent of this, event B can occur in $b$ ways,then the number of combinations of ways for A and B to occur is $ab$. (Really just a statement that |A x B| = |A| |B| for finite A, B.) sum rule = if event A can occur in $a$ ways and event B can occur in $b$ ways but both events cannot occur together. Then the number of ways for A or B to occur is a+b. (Really just a statement that |A \cup B| = |A|+|B| for disjoint A, B. inclusion/exclusion counting: |A \cup B| = |A| + |B| - |A \cap B| (and generalizations). --------------------------- Example counting exercises ------------------------- Please calculate values explicitly; I like to see the numbers. 1. License plates in Nebraska are 3 distinct letters (A-Z, but not O), followed by 3 distinct numbers. How many possible license plates are there? Answer: 25*24*23*10*9*8 = P(25,3) P(10,3) = 9,936,000 2. How many ways can a blue, white, and red ball be put into 10 different bins? Assume no bin can contain two balls. Answer: 10*9*8 = P(10,3) = 720 3. How many different ways a salesman travel among n cities, where he starts in city 1 and visits each other city once and only once before returning to city 1. Answer: (n-1)! 4. How many ways can you select a president, vice president, and treasurer in a club of 30 people? Answer: P(30,3) = 24,360 5. How many way can you form Male-Female dance partners if there are 12 women and 8 men. Assume each man is partnered with some woman (4 women go un-partnered). Answer: P(12,8) = 19,958,400 6. How many ways you position 7 people in a circle? Answer: 6! = 720 7. A man, a woman, a boy, a girl, a dog, and a cat are walking single-file down the road. a. How many ways can this happen? Answer: 6! = 720 b. How many ways if the dog comes first? Answer: 5! = 120 c. How many ways if the dog immediately follows the boy? Answer: 5! = 120 d. How many ways if the dog (and only the dog) is immediately between the man and the boy. Answer: 2*4! = 48 (form a man-dog-boy or a boy-dog-man combo) 8. In how many ways can 10 adults and 5 children be positioned in a line so that no two children are next to each other? (they fight) Answer: 10!*P(11,5) = 10! 11! / 6! = 201,180,672,000 \approx 10^11.3 9. How many arrangements are there of the letters a..z such that there are exactly 10 letters between the "a" and the "z"? Answer: 15!*P(24,10)*2 = 24!*30 \approx 1.86*10^25 (reasoning: after selecting the AxxxxxxxxxxZ block, treat it as atomic and rearrange with the 14 remaining letters in any of 15! ways. Double to account for AxxxxxxxxxxZ and ZxxxxxxxxxxA possibilities.) 10. You take a group of four people to a Chinese restaurant that has 100 different dishes. All food will be shared among the four of you. How many ways can you order 4 dishes? Answer: C(100,4) = 100*99*98*97 / (4*3*2*1) = 3,921,225 11. You toss a coin 8 times. How many ways can it land with 5 heads all together? Answer: C(8,5) = 56 (Note this is C(8,3). In general, C(n,r) = C(n,n-r).) 12. How many 6-element subsets are there of the 26 letters, A ... Z ? Answer C(26,6) = 230,230 And if two letters? C(26,2) = 26*25/2 = 338. In general, C(n,2) = n(n-1)/2 13. An urn contains 15 red, numbered, balls, and 10 white, numbered balls. 5 balls are removed. (A) How many different samples are possible? Answer: C(25,5) = 53,130 (B) How many samples contain only red balls? Answer: C(15,5) = 3003. (B') So what is the probability that a random sample will contain only red balls? Answer: 3003 / 53,130 \approx 0.005652 (0.5652 %) (about 1 in 18) (C) How many samples contains 3 red balls and 2 white balls? Answer: C(15,3) * C(10,2) = 20,475 (C') So what's the chance that a random sample will contain 3 red balls and one white ball Answer: 20,475 / 53,130 \approx 0.3854 (38.54%) For next time.... POKER DEFINITIONS: straight = 5 consecutive cards: A2345, 23456, 34567, ..., 890JQ, 90JQK, 0JQKA royal flush = 0JQKA of one suit straight flush = straight in one suit that is not a royal flush four of a kind = four cards of one value, eg., four 9's full house = 3 cards of one value, 2 cards of another value flush = five cards of a single suit straight = a straight that is not a royal flush or a straight flush three of a kind = three cards of one value, a fourth card of a different value, and a fifth card of a third value two pairs = two cards of one value, two more cards of a second value, and the remaining card of a third value one pair = two cards of one value, but not classified above 16. How many poker hands are there? Answer: C(52,5)=2,598,960 17. How many poker hands are full houses? Answer: A full house can be identified by a pair, like (J,8), where the first component of the pair is what you have three of, the second component is what you have two of. So there are 13*12 such pairs. For each there are C(4,3)=4 ways to chose the first component, and C(4,2)=6 ways to choose the second component. So all together there are 13*12*4*6=3744 possible full houses. The chance of being dealt a full house is therefore 3744/2598960 \approx .001441 18. How many poker hands are two pairs? Answer: We can identify 2 pairs as in {J,8}. Note that now the pair is now unordered. There are C(13,2) such sets. For each there are C(4,2) ways to choose the larger card and C(4,2) ways to choose the smaller card. There are now 52-8 remaining cards one can choose as the fifth card. So the total is C(13,2)*C(4,2)*C(4,2)*44 = 123,552. The chance of being dealt two pairs is therefore 123,552/2,598,960 \approx .047539.