# First Midterm Exam Solutions

#### 30 September 2009

Scale for this exam was A = 93, C = 63.

Question text is in black, solutions in blue.

```  Q1: 10 points
Q2: 10 points
Q3: 10 points
Q4: 10 points
Q5: 30 points
Q6: 30+10 points
Total: 100+10 points
```

• The first two true-false questions involve a situation where six people, named A, B, C, D, E, and F, are going to run a race. We assume that all will finish and that it is not possible for two or more of them to finish at exactly the same time.

• Question 1 (10): True or false with justification: There are fewer than 100 possible choices for who finishes first, second, and third in the race. (We are counting choices such as "B first, F second, C third".)

FALSE. This is an instance of the Second Counting Problem, with n = 6 and k = 3, so the number of choices is 63 = 6*5*4 = 120, more than 100.

• Question 2 (10): True or false with justification: Of the number of orderings of finish for all six racers, the number where either A finishes first, or F finishes last, but not both, is 5! + 5! - 4!.

FALSE. If X is the set of finishes with A first, and Y is the set with F last, it is true that |X| = 5!, |Y| = 5!, and |X ∩ Y| = 4! by the Second Counting problem with n = k. So by the Double-Counting Rule, |X ∪ Y| = 5! + 5! - 4!, the number given. But the statement doesn't refer to X ∪ Y, which is the set of finishes with A first or F last or both. To get the size of the set referred to, (X - Y) ∪ (Y - X), you need to subtract |X ∩ Y| again to get 5! + 5! - 4! - 4!.

• Question 3 (10): True or false with justification: Assume that Zane's Noodle Stand offers 13 kinds of vegetables that may be put in your soup. Then the number of ways to choose a set of exactly four vegetable types is more than double the number of ways to choose a set of exactly three vegetable types.

TRUE. The number of ways to pick four vegetables is (13 choose 4) = 13*12*11*10 divided by 1*2*3*4 or 13*11*5. The number of ways to pick three vegtables is (13 choose 3) = 13*12*11 divided by 1*2*3 or 13*11*2. (Both numbers are from the Third Counting Problem.) We can see without multiplying the products out that the first product is 5/2 times the second one, more than twice as big.

• Question 4 (10): True or false with justification: The same six people from Questions 1 and 2 also compete in three rounds of another contest, each of which has a single winner. Consider the number of possible outcomes of this contest, such as "A won two rounds and B won one", or "B, D, and E won one round each". Then this number is exactly (8 choose 5).

TRUE. This is an instance of the Fourth Counting Problem with n (the number of items chosen from) equal to 6 and k (the number of items chosen) equal to 3. By our solution to the Fourth Problem, the answer is (n+k-1 choose k) or (n+k-1 choose n-1), which in this case is (8 choose 5) or (8 choose 3). The reason we use the Fourth Counting Problem instead of the First is that the "outcomes" described in the statement do not indicate the order in which the contests were one, merely the multiset of winners.

• Question 5 (30): In three-card poker, a player's hand is a set of three cards chosen from a standard 52-card deck.
• (a,5) How many different possible three-card hands are there in all?

(52 choose 3) = 52*51*50 divided by 1*2*3 = 26*17*50 = 13*17*100 = 22100, by the Third Counting Problem.

• (b,10) How many possible one-pair hands are there, with two cards of the same rank and a third card of a different rank?

We pick the rank of the pair in (13 choose 1) = 13 ways, the suits of the two cards in the pair in (4 choose 2) = 6 ways, the rank of the third card in 12 ways (since it must have a different rank from the pair), and the suit of the third card in 4 ways. The number of ways to pick all of these, by the Product Rule, is 13*6*12*4 = 3744. There is no double-counting here, as in the two-pair case in five-card poker, because switching the ranks of the pair and of the third card would result in a different hand.

• (c,10) Recall that a flush is three cards of the same suit, and a straight is three cards of consecutive ranks. (Note that A-2-3 and Q-K-A are both straights, but K-A-2 is not.) Which type of hand is more common in three-card poker -- straight or flush? (Remember that a straight flush counts as neither a straight nor a flush.)

The number of hands with three cards of the same suit is 4 * (13 choose 3) = 4*13*12*11 divided by 1*2*3 = 13*11*8 = 1144. The number of flushes is thus 1144 - SF, where SF is the number of straight flushes. (We will see in Question 5d that SF = 48, but we won't need that here. The number of rank sequences forming a straight is 12, from A-2-3 through 2-3-4, 3-4-5, etc., to Q-K-A. There are 4*4*4 = 64 suit combinations for each of these rank sequences, so the number of straights is 12*64 - SF. We can compute 12*64 = 768 and see that it is less than 13*11*8 = 1144. (We could even divide both numbers by 8 and see that 12*8 = 96 is less than 13*11.) Thus there are MORE FLUSHES, reversing the situation in five-card poker. The actual numbers are 1096 flushes and 720 straights.

• (d,5) Which type of hand is more common in three-card poker -- three of a kind or straight flush?

There are 13 ranks and (4 choose 3) = 4 ways to choose three cards of that rank, so there are 13*4 = 52 three-of-a-kind hands. (Given any card, you can make a unique three-of-a-kind hand by taking the other three cards of its rank.) For each of the 12 possible rank sequences for a straight, there are 4 choices for the suit of a straight flush, so there are 12*4 = 48 straight flushes and thus MORE THREE-OF-A-KIND HANDS. In five-card poker, the four-of-a-kind hands outnumber the straight flushes by 13*48 = 624 to 40.

• Question 6 (30+10): This multipart question deals with strings using the set of letters {a, b, c}.
• (a,5) If k is any natural number, how many strings of length exactly k start with b? (Your answer should be a function of k.)

This is an instance of the First Counting Problem because we must choose one of three items for each position other than the first, for 3k-1 total choices.

• (b,10) If k is any natural number, let N(k) be the number of strings of length at most k that start with b. Prove by induction on k, with a base case of k = 1, that N(k) = (3k - 1)/2.

For the base case, we compute (31 - 1)/2 = 1 and note that there is exactly one string starting with b and having length at most 1, the string b. So the formula correctly gives N(1) and the base case is proved.

Now assume as the IH that N(k) = (3k - 1)/2. We want to prove that N(k+1) = (3k+1 - 1)/2. We analyze N(k+1) in terms of N(k) -- it is equal to N(k) plus the number of strings that start with b and have length exactly k+1. By the result of Question 6a, this latter number is 3k+1-1 = 3k. So we know that N(k+1) = N(k) + 3k, and thus by the IH we know that N(k+1) = (3k - 1)/2 + 3k = (3k - 1 + 2*3k)/2 = (3k+1 - 1)/2 and the formula is correct for N(k+1). Since we proved that the k-case of the statement implies the (k+1)-case, we have completed the inductive proof.

• The next two parts of the question deal with the following recursive function f from strings to strings. If a string w does not start with an a, then f(w) = w. If w does start with an a, so that w is equal to av for some other string v, then f(w) = f(v). So f(b) = b, and f(ab) = f(b) = b. If we write λ for the empty string (called ```"" ``` in Java), then f(λ) = λ (since λ does not start with a) and f(a) = f(λ) = λ (because a = aλ).
• (c,5) What are f(ba), f(aca), f(caac), f(aacb), and f(aaa)?

f(ba) = ba, f(aca) = f(ca) = ca, f(caac) = caac. f(aacb) = f(acb) = f(cb) = cb, and f(aaa) = f(aa) = f(a) = f(λ) = λ.

• (d,5) If w is any string, what property of w determines the length of f(w)? That is, give me a rule that tells me how to determine the length of f(w) by examining w. You need not prove that your rule is correct.

The length of f(w) is the length of w minus the number of consecutive a's (if any) at the start of w.

• The last two parts of the question deal with a fixed number k and three sets of strings. The set X consists of all strings of length exactly k. The set B consists of all strings of length at most k that start with b, and the set C consists of all strings of length at most k that start with c.
• (e,5) Give a combinatorial proof that |B| = |C|. That is, describe a bijection that takes strings in B to strings in C, and explain why it is a bijection.

If w is any string in B, we can write w as bv because w must start with b. Define g(w) to be cv. Then g(w) is certainly in C. There are two ways to show that g is a bijection. First, we could observe that if we define h(cv) to be bv for any string cv in C, the functions g and h are inverses, which is only possible if both are bijections. Alternatively, we can observe that g is both one-to-one and onto. It is one-to-one because if w = bv and w' = bv' are two different strings in B, then g(w) = cv and g(w') = cv' are different strings in C. It is onto because any string in C can be written as cv, and thus equals g(w) for w = bv. (The function g does not change the length of the string.)

• (f,5) Give a combinatorial proof that |X| = |B| + |C| + 1, by giving a bijection that takes strings in X to strings in B ∪ C ∪ {λ}. Explain why your function is a bijection.

The bijection is the function f from Questions 6c and 6d. If w is any string in X, we know that f(w) either starts with a b, starts with a c, or has no letters at all. Since f(w) also cannot be longer than w, f(w) must be in the set B ∪ C ∪ {λ}.

If v is any string in B or C of some length k - m, then f(amv) = v and amv has length exactly k and is thus in X, so f is onto. (In addition, f(am) = λ.)

If v and v' are two different strings in X, we must show that f(v) and f(v') are two different strings. Let m be the number of consecutive a's at the start of v and m' the number at the start of v'. If m is not equal to m', by Question 6d we know that f(v) and f(v') have different lengths and thus cannot be the same string. If m = m', we can write v = amz and v' = amz', and note that z = z' would imply v = v', which we are assuming to be false, and therefore we know that z = z'. Since f(v) = z and f(v') = z', we have completed the proof that f is onto.