This preview shows page 1-2-3-4-5-6-7-8-55-56-57-58-59-60-61-62-112-113-114-115-116-117-118-119 out of 119 pages.
15-251Great Theoretical Ideas in Computer Science++()+( ) = ?Counting II: Recurring Problems and CorrespondencesLecture 7, September 16, 20082Review from last time...3AB1-1 onto Correspondence(just “correspondence” for short)4If a finite set A has a k-to-1 correspondence to finite set B, then |B| = |A|/k5Sometimes it is easiest to count the number of objects with property Q, by counting the number of objects that do not have property Q.6The number of subsets of an n-element set is 2n.7The number of subsets of size r that can be formed from an n-element set is:n!r!(n-r)!=nr8A choice tree provides a “choice tree representation” of a set S, if1. Each leaf label is in S, and each element of S is some leaf label2. No two leaf labels are the same9Product Rule (Rephrased)Suppose every object of a set S can be constructed by a sequence of choices with P1 possibilities for the first choice, P2 for the second, and so on. IF 1. Each sequence of choices constructs an object of type S2. No two different sequences create thesame objectThere are P1P2P3…Pn objects of type SANDTHEN10How Many Different Orderings of Deck With 52 Cards?What object are we making? Ordering of a deckConstruct an ordering of a deck by a sequence of 52 choices: 52 possible choices for the first card; 51 possible choices for the second card; : : 1 possible choice for the 52nd card.By product rule: 52 × 51 × 50 × … × 2 × 1 = 52!11The Sleuth’s CriterionThere should be a unique way to createan object in S.In other words:For any object in S, it should be possible to reconstruct the (unique) sequence of choices which lead to it.12The three big mistakes people make in associating a choice tree with a set S are:1. Creating objects not in S2. Leaving out some objects from the set S3. Creating the same object two different ways13DEFENSIVE THINKINGask yourself:Am I creating objects of the right type?Can I reverse engineer my choice sequence from any given object?14Inclusion-ExclusionIf A and B are two finite sets, what is the size of (A ∪ B) ?15Inclusion-ExclusionIf A and B are two finite sets, what is the size of (A ∪ B) ?|A| + |B| - |A ∩ B|15Inclusion-ExclusionIf A, B, C are three finite sets, what is the size of (A ∪ B ∪ C) ?16Inclusion-ExclusionIf A, B, C are three finite sets, what is the size of (A ∪ B ∪ C) ?|A| + |B| + |C| - |A ∩ B| - |A ∩ C| - |B ∩ C| + |A ∩ B ∩ C|16Inclusion-ExclusionIf A1, A2, …, An are n finite sets, what is the size of (A1 ∪ A2 ∪ … ∪ An) ?17Inclusion-ExclusionIf A1, A2, …, An are n finite sets, what is the size of (A1 ∪ A2 ∪ … ∪ An) ?∑i |Ai| - ∑i < j |Ai ∩ Aj| + ∑i < j < k |Ai ∩ Aj ∩ Ak| … + (-1)n-1 |A1 ∩ A2 ∩ … ∩ An|17Let’s use our principles to extend our reasoning to different types of objects18Counting Poker Hands1952 Card Deck, 5 card hands4 possible suits:♥♦♣♠13 possible ranks:2,3,4,5,6,7,8,9,10,J,Q,K,A2052 Card Deck, 5 card hands4 possible suits:♥♦♣♠13 possible ranks:2,3,4,5,6,7,8,9,10,J,Q,K,APair: set of two cards of the same rankStraight: 5 cards of consecutive rankFlush: set of 5 cards with the same suit20Ranked Poker HandsStraight Flush: a straight and a flush4 of a kind: 4 cards of the same rankFull House: 3 of one kind and 2 of anotherFlush: a flush, but not a straightStraight: a straight, but not a flush3 of a kind:3 of the same rank, but not a full house or 4 of a kind2 Pair: 2 pairs, but not 4 of a kind or a full houseA Pair21Straight Flush22Straight Flush9 choices for rank of lowest card at the start of the straight22Straight Flush9 choices for rank of lowest card at the start of the straight4 possible suits for the flush22Straight Flush9 choices for rank of lowest card at the start of the straight4 possible suits for the flush9 × 4 = 3622Straight Flush9 choices for rank of lowest card at the start of the straight4 possible suits for the flush9 × 4 = 3652536=362,598,960= 1 in 72,193.333…224 of a Kind234 of a Kind13 choices of rank234 of a Kind13 choices of rank48 choices for remaining card234 of a Kind13 choices of rank48 choices for remaining card13 × 48 = 624234 of a Kind13 choices of rank48 choices for remaining card13 × 48 = 624525624=6242,598,960= 1 in 4,16523Flush24Flush4 choices of suit24Flush4 choices of suit135choices of cards244 × 1287= 5148Flush4 choices of suit135choices of cards244 × 1287= 5148Flush4 choices of suit135choices of cards“but not a straight flush…”244 × 1287= 5148Flush4 choices of suit135choices of cards“but not a straight flush…” - 36 straight flushes244 × 1287= 5148Flush4 choices of suit135choices of cards“but not a straight flush…” - 36 straight flushes5112 flushes244 × 1287= 5148Flush4 choices of suit135choices of cards“but not a straight flush…” - 36 straight flushes5112 flushes5,112= 1 in 508.4…52524Straight259 choices of lowest cardStraight259 × 1024= 92169 choices of lowest card45 choices of suits for 5 cardsStraight259 × 1024= 92169 choices of lowest card45 choices of suits for 5 cards“but not a straight flush…”Straight259 × 1024= 92169 choices of lowest card45 choices of suits for 5 cards“but not a straight flush…” - 36 straight flushesStraight259 × 1024= 92169 choices of lowest card45 choices of suits for 5 cards“but not a straight flush…” - 36 straight flushes9180 straightsStraight259 × 1024= 92169 choices of lowest card45 choices of suits for 5 cards“but not a straight flush…” - 36 straight flushes9180 straights9,180= 1 in 283.06…525Straight25RankingStraight Flush 364-of-a-kind 624Full House 3,744Flush 5,112Straight 9,1803-of-a-kind 54,9122-pair 123,552A pair 1,098,240Nothing 1,302,54026Storing Poker Hands:How many bits per hand?I want to store a 5 card poker hand using the smallest number of bits (space efficient)27Order the 2,598,560 Poker Hands Lexicographically (or in any fixed way)To store a hand all I need is to store its index of size log2(2,598,560) = 22 bitsHand 0000000000000000000000Hand 0000000000000000000001Hand 0000000000000000000010...28Is 22 Bits OPTIMAL?29Is 22 Bits OPTIMAL?221 = 2,097,152 < 2,598,56029Is 22 Bits OPTIMAL?221 = 2,097,152 < 2,598,560Thus there are more poker hands than there are 21-bit strings29Is 22 Bits OPTIMAL?221 = 2,097,152 < 2,598,560Thus
View Full Document