TEST 3 CS/APMA 202 Name:_________answer key__________ Directions: This exam is closed book and closed notes. You may not consult any notes, textbooks, homeworks, or other materials. A calculator may be used for numerical computation only. (24) 1. How many bit strings of length 16 have (a) exactly four 0s? 16! 16*15*14*13 C(16, 4) = C(16, 12) = 12!4! = = 4*5*7*13 = 1820 4*3*2 [Choose 4 of the 16 bit positions to place the 0s into (or 12 of 16 to place the 1s into).] (b) the same number of 0s as 1s? 16! 16*15*14*13*12*11*10*9 C(16, 8) = = = 2*13*11*5*9 = 12870 8!8! 8*7*6*5*4*3*2 [Choose 8 of the 16 bit positions to place the 0s into (or to place the 1s into).] (c) at least fourteen 1s? 16*15 2 + 16 + 1 = 8*15 + 17 = 120 + 17 = 137 [If it has at least fourteen 1s, then it has exactly 14 1s or exactly 15 1s, or exactly 16 1s.] C(16, 14) + C(16, 15) + C(16, 16) = (d) at least three 1s? 216 – (C(16, 2) + C(16, 1) + C(16, 0)) = 216 – 137 = 65536 – 137 = 65399 [If it has at least three 1s then we wish to count all bit strings except those with exactly two 1s, exactly one 1, or no 1s. There are 216 total bit strings of length 16 and we subtract out the aforementioned strings.] (e) exactly six 1s if every 1 must be immediately followed by a 0? C(7, 1) + C(7, 1)C(6, 1) + C(7, 2) + C(7, 1)C(6, 2) + C(7, 4) = 7 + 7*6 + 21 + 7*15 + 35 = 210 [If it has exactly six 1s then it must have ten 0s. Since every 1 must be immediately followed by a 0, we are looking for strings of the form _10_10_10_10_10_10_ where the four remaining 1s must be distributed amongst the 7 _s. There are four cases to consider: case 1: All four 1s are placed into the same _. There are C(7, 1) ways to do this since we must choose 1 of the seven _s. case 2: One of the _s gets three 1s. Then the remaining 1 must be placed in another blank. There are C(7, 1) ways to choose the _ to place three 1s into then C(6, 1) ways to choose one of the remaining blanks. case 3: Two 1s are placed into some _. Then either the remaining two 1s are placed into another _ or they are split up into two separate _s. In the former case, we have C(7, 2) ways to choose 2 of the 7 _s to put two 1s in. In the latter case, we have C(7, 1) ways to choose the _ to put two 1s in and C(6, 2) ways to choose from the remaining six _s to distribute the other two 1s to. case 4: No _ gets more than one 1. So we have C(7, 4) ways to choose four of the seven _s to put a single 1 into each.] (20) 2. Recall that a standard deck of cards contains 52 cards. There are 4 suits (Hearts, Diamonds, Clubs, and Spades) and 13 kinds (2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A). For each kind there is one card of each suit so there are 4 cards of each kind. This accounts for all 52 cards in the deck. Since each of the 52 cards is distinct, if I deal you a poker hand of 5 cards from the deck then there are C(52, 5) different hands you could be dealt (combination is used since the order that you get the 5 cards does not matter). If all C(52, 5) poker hands are equally likely to be dealt to you, what is the probability that (a) Your hand contains the Queen of Diamonds? C(51, 4) 51!47!5! 5 C(52, 5) = 52!47!4! = 52 0.096154 [Along with the Queen of Diamonds, you choose 4 of the remaining 51 cards to fill your hand.] (b) Your hand does not contain the Jack of Spades? C(51, 5) 51!47!5! 47 C(52, 5) = 52!46!5! = 52 0.903846 [You choose 5 cards from the 51 in the deck other than the Jack of Spades.] (c) Your hand contains exactly 2 Kings? C(4, 2)C(48, 3) 48!47!5!4! 47*46*5*4*4*3 47*46 2162 = 2!2!3!45!52! = 52*51*50*49*2 = 13*17*5*49 = 54145 0.03993 C(52, 5) [You first choose 2 of the 4 suits for your two Kings. Then you must choose 3 of the 48 nonking cards in the deck to fill out your hand.] (d) Your hand is a flush (That is, all cards in your hand are of the same suit)? C(4, 1)C(13, 5) 4*13!47!5! 4*13*12*11*10*9 11*9 99 = 52!8!5! = 52*51*50*49*48 = 13*5*49*16 = 50960 0.00194 C(52, 5) [You first choose 1 of the 4 suits for the flush. Then you choose 5 of the 13 kinds of that suit.] (12) 3. Let A = {1, 2, 3, 4}. Then R = {(1,1), (1,3), (2,1), (2,2), (3,2), (3,3)} is a relation over A. (a) Is R reflexive? No. [(4,4) R.] (b) Is R symmetric? No. [(1,3) R but (3,1) R.] (c) Is R transitive? No. [(1,3) R and (3,2) R, but (1,2) R.] (d) Is R antisymmetric? Yes. (e) What is R2? R2 = {(1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1), (3,2), (3,3)}. 2 (10) 4. Let B = {a, b, c}. Find the transitive closure of the relation R = {(a,c), (b,a), (c,b)} over B. First add (a,b), (b,c), and (c,a) to get {(a,b), (a,c), (b,a), (b,c), (c,a), (c,b)}. But the relation is still not transitive. Now add (a,a), (b,b), and (c,c) to get the complete relation BB. The complete relation is transitive so the transitive closure of R is the complete relation. (10) 5. Let C = ZZ. Then R = { ((a,b),(c,d)) ad = bc } is a relation over C. Is R an equivalence relation? If so, prove it. If not, give a reason why R is not an equivalence relation. [Note that this is not quite the same problem that you saw in HW11. Give it some thought.] R is not an equivalence relation since it is not transitive. For example, ((0,1), (0,0)) R since 0*0 = 1*0 = 0 and ((0,0), (1,0)) R since 0*0 = 0*1 = 0, but ((0,1), (1,0)) R since 0*0 1*1. (10) 6. Let D = {1, 2, 3, 4, 5, 6}. Then {{1, 2}, {3, 4, 5}, {6}} is a partition of D. By the theorem relating equivalence relations to partitions, there exists an equivalence relation R over D such that the sets of the partition above are the equivalence classes of R. Give the relation R. R = {(1,1), (1,2), (2,1), (2,2), (3,3), (3,4), (3,5), (4,3), (4,4), (4,5), (5,3), (5,4), (5,5), (6,6)}. 3 (14) 7. Let P be the partially ordered set ({2, 4, 6, 9, 12, 18, 60}, ) (a) Draw the Hasse diagram for P. 60 4 12 18 6 9 2 (b) Are 6 and 9 comparable? No. [6 does not divide 9 and 9 does not divide 6.] (c) Are 4 and 60 comparable? Yes. [4 divides 60.] (d) Find the minimal elements. 2 and 9 are minimal elements. (e) Find all lower bounds of {18, 60}. 2 and 6 are lower bounds of {18, 60}. (f) What is the greatest lower bound of {18, 60} (if it exists)? 6 is the greatest lower bound of {18, 60}. (+8) Extra Credit: Let S be a set. Prove that (P(S), ) is a lattice. [Recall that a lattice is a partially ordered set in which every pair of elements has both a least upper bound and a greatest lower bound]. We proved in class that (P(S), ) is a poset, so you need to show that every pair of elements has an l.u.b. and a g.l.b. Proof: Let S be a set. Let A, B P(S). We must show that {A, B} has both a least upper bound and a greatest lower bound. The least upper bound of {A, B} is A B. First, A B is an upper bound for {A, B} since both A A B and B A B. Now let C be an upper bound of {A, B}. To show that A B is the least upper bound of {A, B}, we must show that A B C. Since C is an upper bound of {A, B} then A C and B C. Now let x A B. Then x A or x B. If x A, then x C since A C. Similarly, if x B then x C since B C. So x C. Hence A B C. So we have shown that A B is the least upper bound of {A, B}. The greatest lower bound of {A, B} is A B. First of all, A B is a lower bound of {A, B} since both A B A and A B B. Now let D be a lower bound of {A, B}. To show that A B is the greatest lower bound of {A, B}, we must show that D A B. Since D is a lower bound of {A, B} then D A and D B. Now let y D. Then y A and y B. So y A B. Hence D A B. So we have shown that A B is the greatest lower bound of {A, B}. Hence for any two elements in P(S), we have shown how to find the greatest lower bound and least upper bound of these two elements. So (P(S), ) is a lattice. Pledge: I pledge that I have neither given nor received unauthorized aid on this exam. _______________________ (sign pledge) 4