CSCI 00 Foundations of Computer Science (FoCS) Solutions for Homework 7 Homework Problems. [0 POINTS] Problem.4(e)-(f) [or F7 Problem.7(e)-(f)]: In each case, count. (e) The number of orders in which a traveling salesman can visit the 50 states. Solution: In this problem, since order does matter, we are counting the number of k- orderings or k-permutations, where k = 50 and the number of elements we are ordering is n = 50. Therefore, we can calculate q as the number of k-orderings as q = n! (n k)! = 50! = 50! 0! This is a very large number! If you happen to have used a calculator for this, the answer is.044090778040805 0 4 (yikes). (f) The number of poker hands with a card in every suit. Solution: A poker hand consists of exactly five cards. The problem requires four cards to be in the four different suits. This implies that two cards will be of the same suit; in this case, there are ways to select the two cards. For the other suits, there are ways to select each card. Finally, we multiply the by 4, one for each suit: q = 4 ( )( )( )( ) = 4!!( )! (!!( )! ) = 85, 44. [0 POINTS] Problem.8(b) [this problem is not in the F7 textbook]: What is the coefficient of x in the expansion of: (b) ( x) Solution: We need to find the () i ( x) i term that produces the x term. Here, i =. From the Binomial Theorem, the x term is then () i ( x) i = () ( ) x =!!! (7)( 8)x = 40x The coefficient of x in the expansion of ( x) is 40.. [8 POINTS] Problem 4.8 [or F7 Problem 4.5]: Sets A, B, C have sizes,, 4. What are the min and max for A B C? Solution: 4 A B C 9
4. [8 POINTS] Problem 4.9(a) [this problem is not in the F7 textbook]: Consider the binary strings consisting of 0 bits. (a) How many contain fewer s than 0 s? Solution: Overall, there are 0 = 04 binary strings consisting of 0 bits. We must find x, the number of 0-bit binary strings containing fewer s than 0 s. There are at least two approaches here: i. Observe that the answer will be symmetric with the number of 0-bit binary strings containing fewer 0 s than s. Therefore, first calculate the number of 0-bit binary strings with the same number of 0 s and s as ( 0) 5 = 0! 5!5! = 5. Then, based on symmetry, x = 04 5 = 8. ii. Observe that to have fewer s than 0 s, a 0-bit binary string must contain n 0 s, where n takes on values {, 7, 8, 9, 0}. Therefore, we can calculate x = 0 0 7 0 8 0 9 0 = 0 0 45 0 = 8 0 5. [0 POINTS] Problem 4.9(f)-(g) [or F7 Problem 4.(f)-(g)]: In each case, count the number of objects/arrangements of the given type: (f) US Social Security numbers (see Problem. [or F7 Problem.5]) with digits in strictly increasing order. Solution: This problem is essentially asking you to count x as the number of 9-digit sequences (i.e., leading zeroes are fine) in which each subsequent digit going from left to right increases. This is actually a rather small set of values: {04578, 04579, 04589, 045789, 04789, 05789, 045789, 045789, 045789, 45789} The number of sequences is therefore x = 0. (g) US Social Security numbers with digits in non-decreasing order. Solution: This problem is asking you to count y as the number of 9-digit sequences (i.e., leading zeroes are fine) in which each subsequent digit going from left to right does not decrease. A good way to tackle this problem is to come up with a simpler representation. In this case, use delimiters between each digit, in order from 0 up to 9. Let each represent a digit, and each represent a change from digit n to digit n. There will always be exactly 9 characters (because we require a 9-digit sequence) and exactly 9 delimiters, for an overall total of 8 characters. As an example, represents the 9-digit sequence 00077. Given the above representation, we need to count the number of ways we can place 9 delimiters before/among/after 9 digits. To accomplish this, we need to choose 9 spots out of 8. Therefore, y = ( 8 9 ) = 48, 0.
. [ POINTS] Problem 4. [or F7 Problem 4.]: Use inclusion-exclusion to count the integer solutions to x x x = 0 where x 0, x 8, and 0 x 5. Solution: Start by adjusting the ranges of x and x to be non-negative integers, so let y = x with 0 y, y = x with 0 y, and simply y = x with 0 y 5. From this, we use inclusion-exclusion to count the integer solutions of y y y = 0. This is a k-subset with repetition problem. From Chapter, we can make use of n k Q(n, k) = k More specifically, we start by counting the number of solutions with y, y, y 0; here, with n = 0 and k =, we have n k Q(n, k) = Q(0, ) = = = k Next (the exclusion part), let S be the set of solutions that violate the upper bound constraint on y. Therefore, S contains solutions to y y y = 0 with y. Similarly, let S be the set of solutions with y 7, and let S be the set of solutions with y. Given these sets, the number of solutions that satisfy y y y = 0 is Using inclusion-exclusion, we have Q(0, ) S S S S S S = S S S S S S S S S S S S To obtain S, observe that solutions to y y y = 0 with y are solutions to z y y = 7, where z = y and z 0. Therefore, S = Q(7, ) = ( 9 ) =. Using a similar approach, S = Q(, ) = ( 5) = 05 and S = Q(4, ) = ( ) = 5. To determine S S, we observe that this intersection contains solutions with both y and y 7. Therefore, S S = Q(0, ) = ( ) =. Similarly, S S = Q( 9, ) = 0 and S S = Q(, ) = 0. Finally, the cardinality of the intersection of all three, i.e., S S S = Q(, ) = 0. Putting this all together yields S S S = 05 5 0 0 0 = 55 Therefore, our answer is 55 = 7.
7. [0 POINTS] Problem 4.50(a)-(b) [or F7 Problem 4.4(a)-(b)]: 8 distinguishable dice are rolled. How many outcomes are there? Solution: First, given 8 dice, there are 8 =, 79, possible outcomes. (a) How many outcomes do not contain a? How many do not contain a or? Solution: To determine how many outcomes do not contain a, each die roll has 5 possible outcomes. Therefore, with 8 dice, we have 5 8 = 90, 5 possible outcomes that do not contain a. Similarly, to determine how many outcomes do not contain a or a, each die roll has 4 possible outcomes. Therefore, with 8 dice, we have 4 8 = 5, 5 possible outcomes that do not contain a or a. (b) How many outcomes contain all numbers? [Hint: Inclusion-exclusion.] Solution: As noted above, with 8 dice, there are 8 =, 79, possible outcomes. Exclude from this the 5 8 = 90, 5 outcomes that do not contain a, the 5 8 = 90, 5 outcomes that do not contain a, etc. More specifically, we exclude 5 8 =, 4, 750 outcomes here. Next, we include (i.e., add back) the 4 8 = 5, 5 outcomes that do not contain a or a, since these were excluded twice in the previous step. To do this for each pair, we add back ( ) 4 8 = 98, 040. Continuing this pattern, we have our answer x calculated as x = 8 5 8 4 8 8 8 4 8 5 =, 79,, 4, 750 98, 040, 0 840 = 9, 50 8. [ POINTS] Problem 5.7(a)-(c) [this problem is not in the F7 textbook]: Randomly roll two dice. Compute the probabilities to roll: (a) One six Solution: Overall, there are = possible outcomes. Of these, 0 outcomes contain exactly one die roll of. Note we do not count a pair of sixes here. Therefore, the probability of rolling a on either die is 0 = 0.777. (b) A sum of Solution: Of the = possible outcomes, 5 outcomes that yield a sum of. Therefore, the probability of rolling a sum of on a pair of dice is 5 = 0.88. (c) A sum that is a multiple of Solution: In this problem, we are looking for dice roll sums in set S = {,, 9, }. Of the = possible outcomes, there are 5 4 = outcomes that yield a sum in set S. Therefore, the probability of rolling a sum that is a multiple of three on a pair of dice is = 0.. 4
9. [0 POINTS] Problem 5.7(a)-(b) [this problem is not in the F7 textbook]: Draw two cards randomly from a 5-card deck. Compute the probabilities: (a) The first is a K and the second a picture-card (i.e., A, K, Q, J). Solution: For the first card drawn, the probability of drawing a K is P[first is K] = 4 5 = 0.079. For the second card drawn, the probability of drawing a picture-card is P[second is picture-card first is K] = 5 5 = 0.94. Combining these two as a product, we have P[answer] = 4 5 5 5 = 5 = 0.0 (b) At least one card is a picture-card (i.e., A, K, Q, J). Solution: Start with all possible ways to select two cards, i.e., 5 5 = 5. Next, determine all possible ways to select no picture-cards. Note that we have 5 = non-picture-cards. Here, all possible ways to select two non-picture-cards is 5 = 0. Therefore, the probability of drawing two cards with at least one card being a picturecard is 5 5 0 = = 0.549 5 5 5 0. [0 POINTS] Problem.(a)-(b) [this problem is not in the F7 textbook]: One in 0 men are colorblind and one in 400 women are colorblind. There are an equal number of men and women. You select a person at random. (a) What is the probability that the person is colorblind? Solution: Given that there are an equal number of men and women, we select each with probability, which we then multiply and combine as follows: 0 400 = 40 800 = 800 = 0.05 (b) The person is colorblind. What is the probability that the person is male? Solution: Here, we are calculating P[person is male person is colorblind]. Using the conditional probability equation with A representing person is male and B representing person is colorblind, we have P[A B] = P[A B] P[B] First, P[A B] = 0 800 = 0.05. And from (a), P[B] = 800 = 0.05. Then, we have P[A B] = P[A B] P[B] = 0 800 800 = 0 = 0.954 5
CMMMMMMMMMMMMMMMMMMMFFFFFFFFFFFFFFFFFFFC