# Third Midterm Exam Solutions

#### 18 November 2004

Questions are in black, solutions in blue.

Two superscripting errors (in solutions to 3a and 3b) corrected 21 April 2005 -- thanks to Gordon Morehouse.

• Question 1 (20): Sgt. Preston of the Yukon is assembling a team of eight dogs to pull his sled. The candidate dogs are of three breeds: Alaskan, Mixed, and Siberian. The team will be arranged in a single line beginning with the lead dog.
• (a,5) Assuming that he has at least eight of each breed available, how many choices does he have for which breed occupies which position in the team? (For example, he might pick "Alaskan, Mixed, Siberian, Mixed, Mixed, Alaskan, Siberian, Siberian".)

First Counting Problem, sequences of length 8 from a three element set so n=3, k=8, nk = 38 = 6561.

• (b,5) Again assuming he has at least eight of each breed available, how many choices does he have for how many dogs of each breed are on his team? (In the example above, he has picked "two Alaskan, three Mixed, and three Siberian".)

Fourth Counting Problem, again n=3 and k=8, solution is k+n-i choose n-1 or 10 choose 2 which is 45.

• (c,5) Now suppose he has chosen two Alaskans, two Mixed, and four Siberians for the team. How many choices does he have for which breed goes in which position? (Hint: First count the ways to place the two Alaskans, then count the ways to place the two Mixed among the remaining positions.)

There are 8 choose 2 = 28 ways to place the two Alaskans (Third Counting Problem, counting subsets of size 2 from the set of 8 positions.) For each of these there are 6 choose 2 = 15 ways to place the two Mixed. Once these are placed, the positions for the Siberians are fixed. By the Product Rule, there are 28 times 15 or 420 ways to place the eight dogs.

• (d,5) Again assuming that he has picked his eight dogs, in how many ways can he select which dogs go in the first four positions? (For example, he might pick "dog 7, dog 3, dog 8, dog 1" in that order.)

Second Counting Problem, n=8, k=4, answer 84 = 8*7*6*5 = 1680.

• Question 2 (20): In Game C the player throws a single fair six-sided die k times in sequence. She wins if she completes the k throws without ever throwing the same number twice in a row. Prove by induction for all positive naturals k that the probability of winning Game C is exactly (5/6)k-1.

Base case is k=1 because we are doing induction on positive naturals. For k=1 the probability of winning is 1 because it is impossible to throw the same number twice in a row if you only throw once. This matches the formula because (5/6)0 = 1.

For the inductive case, assume that the probability of winning the k-move Game C is (5/6)k-1 and consider the k+1-move game. To win this, the player must first win the game on the first k moves, then throw the k+1'st die so as not to match the k'th die. By the Independence Rule, the probability of the AND of these two events is the product of their individual probabilities, because the die throws are independent.

The first probability is (5/6)k-1 by the inductive hypothesis. The second probability is 5/6, because there are six equally likely ways for the k+1'st die to come up and five of them are winning. So the resulting probability for the k+1-move game is (5/6)k-1 times (5/6) or (5/6)k, as desired.

• Question 3 (20): Let n and k be naturals and let Σ be an alphabet of size n. The language S(n,k) is the set of all strings over Σ that (a) contain exactly k distinct letters, (b) have each letter at most twice, and (c) have each two occurrences of the same letter, if any, next to each other. For example, with Σ = {a,b}, S(2,1) = {a, aa, b, bb} and S(2,2) = {ab, abb, aab, aabb, ba, baa, bba, bbaa}.
• (a,10) Determine the number of elements in S(5,3).

There are 53 = 5*4*3 = 60 ways to choose the three letters that appear and in which order they appear. For each of the three letters, we must choose whether to make it a single or double letter. This gives us 2*2*2 = 8 strings for each no-repeat sequence of three letters, or 60*8 = 480 strings in all.

• (b,10) Determine the number of elements in S(n,k) for any naturals n and k.

Generalizing the example, we have nk ways to choose which k of the n letters occur in which order (Second Counting Problem). For each of these we have 2k strings because each of the k letters may be single or double. This gives us nk2k strings in all.

• Question 4 (25): This problem deals with two more dice games. In Game D the player throws k six-sided dice at once. She wins \$6 for every die that comes up six. In Game E she again throws k six-sided dice, but this time she wins \$6 if at least one six comes up, and nothing otherwise.
• (a,10) Calculate the expected value of Game D, as a function of k.

The player's expected winnings from a single die are (6\$)(1/6) + (\$0)(5/6) = \$1. The player's total is the sum of the winnings on each die, which is \$k for k dice.

• (b,15) Calculate the expected value of Game E, as a function of k. (Hint: It may be easiest to compute the probability that the player loses Game E.)

The probability of losing the game is the probability of all k throws being numbers other than 6, which by the Independence Rule is (5/6)k. The expected payoff is thus (\$6)(1 - (5/6)k) + (\$0)((5/6)k = (\$6)(1 - (5/6)k). This is \$0 if k=0, \$1 if k=1, \$11/6 if k=2, \$91/36 if k=3, and approaches \$6 as k increases (since for large k, it is almost certain that the payoff will be \$6).

• Question 5 (15): Define a directed multigraph G to have vertex set {1,2,3} and the following adjacency matrix:

``````
1  0  2
1  1  0
0  0  1
``````
• (a,5) Draw the directed multigraph G.

``````

______                ______
/      \              /      \
\-(1)<-/              \-(2)<-/
||^                  /
|| \________________/
||
||      Please excuse the ASCII art --
||      there are loops on each vertex and
||      three other edges, two from 1 to 3
VV      and one from 2 to 1.
-(3)<-
/      \
\______/
``````
• (b,10) Compute the number of one-step, two-step, four-step, and eight-step paths from vertex 2 to vertex 3 in G.

The way I intended for you to solve this problem was to use the Path-Matrix Theorem, calculating the three matrices:

``````
1  0  4           1  0  8           1  0 16
A^2   = 2  1  2     A^4 = 4  1 12    A^8 =  8  1 56
0  0  1           0  0  1           0  0  1
``````
so that there are no one-step, 2 two-step, 12 four-step, and 56 eight-step paths.

Several students found another correct solution. From inspection of the diagram it is clear that a k-step path will consist of the edge from 2 to 1, one of the two edges from 1 to 3, and exactly k-2 loops which may be at any of the three vertices. The number of ways to distribute the k-2 loops among the three vertices is an instance of the Fourth Counting Problem, with n = 3 and k = k-2. The solution is k-2+3-1 choose 2 or k choose 2, times 2 to account for the choice of which edge is taken from 1 to 3. This gives the correct solution of 2*0=0 for k=1, 2*1=2 for k=2, 2*6=12 for k=4, and 2*28=56 for k=8.