## Practice problems for second midterm - with solutions

### Probability

• 1. A pair of dice are rolled. What is the probability that
• (a) At least one of the dice shows an even number?
• P(at least one is even) = 1 - P(both are odd). And the probability that the first die shows an odd number is 1/2, as is the probability that the second does. Since the dice fall independently, P(both are odd) = P(first is odd)*P(second is odd) = (1/2)*(1/2) = 1/4. Therefore P(at least one is even) = 1 - 1/4 = 3/4.
• (b) Both dice show even numbers?
• This is just like part of the last problem: P(both are even) = P(first is even) * P(second is even) = (1/2)*(1/2) = 1/4.
• (c) The total is greater than 9?
• There are 36 ways the dice can fall. There is 1 way to get a 12 (6 + 6), there are 2 ways to get 11 (5 + 6 and 6 + 5), and 3 ways to get 10. Therefore
P(getting greater than 9) = P(getting 10) + P(getting 11) + P(getting 12) = 3/36 + 2/36 + 1/36 = 1/6.
• (d) At least one of the dice has either a 1 or a 6 showing?
• P(either a 1 or a 6 [or both]) = 1 - P(neither die has 1 or 6). Again, the dice are independent and P(first dice does not have 1 or 6) = 4/6 = 2/3. So P(neither die has 1 or 6) = P(first does not) * P(second does not) = (2/3)*(2/3) = 4/9.
Therefore P(either a 1 or a 6 or both) = 1 - 4/9 = 5/9.
• 2. An urn contains 4 red balls and 6 blue balls.
• (a) If two balls are drawn from the urn, what is the probability that both of them are blue?
• We'll write C(n,k) for "n choose k" (since I can't type the n over the k with parentheses around it). Since you pick two balls from the ten in the urn, the number of ways that "anything" can happen is C(10,2) --- and the number of ways to get two blue balls is choosing two of the six, or C(6,2). So P(two blue balls) = C(6,2)/C(10,2) = 15/45 =1/3.
• (b) If two balls are drawn, what is the probability that at least one is blue?
• P(at least one blue) = 1 - P(both red). And we do P(both red) like we did P(both blue) in part (a): P(both red) = C(4,2)/C(10,2) = 6/45 = 2/9. Therefore
P(at least one blue) = 1 - 2/9 = 7/9.
• (c) Two balls are drawn, and the second one is blue. What is the probability that the first one was red?
• Intuitively, the second ball shouldn't affect the first. But let's check:
P(first is red | second is blue) = P(first is red AND second is blue)/P(second is blue).
Numerator first: To calculate P(first is red AND second is blue), we need to figure out how many ways to do this divided by how many ways anything can happen (as in parts (a) and (b). But since we care about the order we pick the balls this time, the denominator (the number of ways "anything" can happen) is 10*9 = 90. And the numerator is 4*6 = 24. So P(first red AND second blue) = 24/90 = 4/15.
Now the denominator. P(second is blue) can be expressed as P(first red AND second blue) + P(first blue AND second blue) = 4/15 + 1/3 = 9/15 = 3/5 (the 1/3 is from part (a), or do it as (6*5)/(10*9) = 30/90 = 1/3).
Therefore, P(first is red | second is blue) = (4/15) / (3/5) = 4/9. So it does matter about drawing the blue one second (because that ball becomes unavailable to have picked first).
• (d) One ball is drawn from the urn. If it is blue, then one die is tossed. If the ball is red, then a pair of dice are tossed. What is the probability that the total of the (die or) dice is less than 6?
• The event "di(c)e total less than 6" is the union of the two events "the ball is blue and the one die is less than 6" and "the ball is red and the total of the pair of dice is less than 6". So
P(di[c]e total less than 6) = P(blue ball and less than 6) + P(red ball and less than 6).
For the first one, we get a blue ball 6/10 of the time, and one die comes up less than six 5/6 of the time. So P(blue ball and less than 6) = (6/10)*(5/6) = 30/60 = 1/2.
For the second part, we get a red ball 4/10 of the time, and two dice total less than six 10/36 = 5/18 of the time (because there are 36 ways for a pair of dice to come up and one of them is a 2, two are 3's, three are fours and four are fives [see the answer to 1(c) above]). So P(red ball and less than 6) = (4/10)*(5/18)=1/9.
So P(di[c]e total less than 6) = 1/2 + 1/9 = 11/18.
• 3. What is the expected value of the sum of the dice if
• (a) One die is tossed?
• Here is a table of possible outcomes and their probabilities when one die is tossed. In the third column is the product of outcome * probability:  Outcome Probability Product 1 1/6 1/6 2 1/6 2/6 3 1/6 3/6 4 1/6 4/6 5 1/6 5/6 6 1/6 6/6 Total: 21/6
The expected value is 21/6, or 3.5 (but that was pretty obvious, wasn't it?)
• (b) Two dice are tossed?
• We could make a table as in the preceding part, but remember that expectations add -- so since the expected value of the first die is 3.5, and the expected value of the second die is also 3.5, the expected value of the sum of the two dice is the sum of the expected values of the indvidual ones, or 3.5 + 3.5 = 7.
• (c) Three dice are tossed?
• Reasoning as in the preceding part, the expected value of each of the three dice is 3.5, and the expected value of the sum is just 3.5 + 3.5 + 3.5 = 10.5.
• (d) Fifteen dice are tossed?
• Same as before, so we'll get 3.5 + 3.5 + ... + 3.5 = (3.5)*15 = 52.5
• 4. A student studying for a vocabulary test knows the meanings of 12 words from a list of 20 words. If the test contains 10 words from the study list, what is the probability that at least 8 of the words on the test are words that the student knows?
• This is one where "at least" doesn't really help:
P(knows at least 8 words on the test) = P(knows 8 words on the test) + P(knows 9 words on the test) + P(knows 10 words on the test).
To get P(knows 8 words on the test), we can (and should) ignore the order of the words on the test, so the process of the teacher making up the test involves choosing 10 words from the list of 20, so there are C(20,10) ways to do this. Next, if the student knows 8 of the words on the test, it means the teacher chose 8 words from the 12 the student knows, and then 2 words out of the 8 the student doesn't know. There are C(12,8) * C(8,2) ways to do this. So P(knows 8 words on the test) = C(12,8) * C(8,2) / C(20,10).
Similarly, there are C(12,9) * C(8,1) ways for the student to know 9 words on the test (the test has 9 words chosen from the 12 the student knows and 1 from the 8 the student doesn't know). So P(knows 9 words on the test) = C(12,9) * C(9,1) / C(20,10).
Last but not least, there are C(12,10) * C(8,0) ways for the student to know all ten words on the test (10 chosen from the known 12 and 0 chosen from the unknows -- note that C(anything,0) = 1). So P(knows 10 words on the test) = C(12,10) / C(20,10).
Now for the numbers: C(20,10) = 184,756, C(12,8) = 495, C(12,9) = 220, C(12,10) = 66, C(8,2) = 28 and C(8,1) = 8.
So P(knows at least 8 words on test) = P(knows 8) + P(knows 9) + P(knows 10)
= (495)*(28)/184756 + (220)*(8)/184756 + 66/184756
= 15686/184756 = 713/8398 = 0.0849
So learning only 3/5 of the material is not such a good test-taking strategy -- only an 8.49% chance of getting a 'B'.
• 5. There are three coins -- one is a two-headed coin, one is biased and comes up heads 75% of the time, and the third is a "fair" coin. A coin is selected at random and flipped.
• (a) What is the probability that the flipped coin will come up heads?
• We'll assume there is an equal chance (1/3) of picking any of the three coins.
Whenever you pick the first coin you get heads, so P(first coin and heads) = 1/3.
0.75 of the time that you pick the second coin you get heads, so P(second coin and heads) = (0.75)*(1/3) = (3/4)*(1/3) = 1/4.
Half the time that you pick the third coin you get heads, so P(third coin and heads) = (1/2)*(1/3) = 1/6
So P(heads) = 1/3 + 1/4 + 1/6 = 9/12 = 3/4.
• (b) Given that the coin that was flipped comes up heads, what is the probability that it was the fair coin?
• P(fair coin | heads) = P(fair coin and heads) / P(heads) [by the formula! P(A|B) = P(A and B) / P(B)]
From part (a), P(fair coin and heads) = 1/6, and P(heads) = 3/4. So P(fair coin | heads) = (1/6)/(3/4) = 2/9.

### Other stuff

• What is the decimal equivalent of 1011101012? What is the binary equivalent of 66610?
• To convert 1011101012, write increasing powers of 2 under the digits of the number, starting from 20 = 1 under the rightmost digit:
```    1   0   1   1   1   0   1   0   1
256 128  64  32  16   8   4   2   1
```
Now, the decimal equiv of this number is 256 + 64 + 32 + 16 + 4 + 1 = 373.
• To convert 666 to binary, write out powers of 2, starting from right to left (as above) until the next power of 2 would be bigger than 666. So the last one would be 512.
Now, starting from 666, you can subtract (1) 512, which leaves 154
Starting from 154, you cant subtract any (0) 256's
Starting from 154, you can subtract (1) 128, which leaves 26
Starting from 26, you cant subtract any (0) 64's
Starting from 26, you cant subtract any (0) 32's
Starting from 26, you can subtract (1) 16, which leaves 10
Starting from 10, you can subtract (1) 8, which leaves 2
Starting from 2, you cant subtract any (0) 4's
Starting from 2, you can subtract (1) 2, which leaves 0
Starting from 0, you cant subtract any (0) 1's.
Now you can read off all the binary digits from top to bottom: 1010011010
• Construct the Huffman code for the letters A,B,C,D,E,F,G and H if they occur with the following probabilities:

 Letter Probability A 0.18 B 0.01 C 0.16 D 0.14 E 0.32 F 0.10 G 0.03 H 0.06
There are eight letters here, so for a fixed-length code you would need three bits per letter. On average, how many bits per letter are needed for the Huffman code?

• I drew the diagram leaving the letters in the order they came, just to show you can do it. Here it is, followed by the explanation:

The least common letters are B and G, so connect them first to make BG with probability 0.04. Then the least common letters are BG and H, so connect them to make BGH with probability 0.10. Now the least common letters are F and BGH, so connect them to make BFGH with probability 0.20. Now the least common letters are A and BFGH, so connect them to make ABFGH with probability 0.38. At this point the least common letters are C and D, so connect them to make CD with probability 0.30. Then the least common letters are CD and E so connect them to make CDE with probability 0.62. Finally connect ABFGH with CDE to make ABCDEFGH with probability 1.0.
Next, put 0 / 1 labels on the branches of each connection as shown. Then you can read off the code for each letter by the sequence of 0's and 1's you pass to get from the root ABCDEFGH of the tree to the letter at the other end:
 Letter Code Length Probability Product A 000 3 0.18 0.54 B 01100 5 0.01 0.05 C 100 3 0.16 0.48 D 101 3 0.14 0.42 E 11 2 0.32 0.64 F 010 3 0.1 0.3 G 01101 5 0.03 0.15 H 0111 4 0.06 0.24 Total (expected length): 2.82

The expected letter length is 2.82, which is less than the 3.0 bits per letter that would be required by a fixed length code - it's about 6% better (3-2.82)/3.