# CMPSCI 250 Solutions to Practice Midterm #3

#### Actual midterm will be 18 November 2004

There are four questions for 100 total points.

Solutions are in blue.

When your answer to a problem is a particular number, you may use exponents, falling exponents, factorials, and/or the "choose" notation to indicate the number. However, if the answer is less than 100, you must give the number in ordinary decimal notation for full credit.

Question 1 (20):

A sushi bar sells five kinds of rolls: Alaska, California, Eel, Salmon, and Tuna. Six customers enter the bar and order one roll each.

• (a,5) In how many ways can each customer pick a type of roll? (Here a typical selection might be "Customer 1 -- Tuna, Customer 2 -- Eel, Customer 3 -- Tuna, Customer 4 -- Alaska, Customer 5 -- Tuna, Customer 6 -- Eel".)

First Counting Problem, n=5 (number of things to choose from), k=6 (number of things chosen), number of sequences of choices is 56 = 3125. You can tell it's 56 and not 65 because the Product Rule says that it is 5*5*5*5*5*5.

• (b,5) The order will be reported to the sushi chef as simply the number of rolls of each type, so that the example above would be "Three Tuna, two Eel, and an Alaskan". In how many ways could the six rolls be ordered in this way?

Fourth Counting Problem, again with n=5 and k=6, formula gives (6+5-1 choose 5-1) = (10 choose 4) = 10*9*8*7/1*2*3*4 = 10*3*7 = 210. The bijection takes multisets of sushi types to binary strings with 6 zeros and 4 ones -- for example AEETTT would map to 0110011000.

• (c,5) How many possibilities are there for the set of roll types ordered by the six customers?

Any subset of {Alaska, California, Eel, Salmon, Tuna} is possible except for the empty set (since at least one type of roll has been ordered). There are 25 = 32 possible subsets of a five-element set, so the answer is 31. You could also get this by counting the one-element, two-element,..., and five-element subsets, getting (5 choose 1) + (5 choose 2) + (5 choose 3) + (5 choose 4) + (5 choose 5) = 5 + 10 + 10 + 5 + 1 = 31.

• (d,5) In how many ways could the six customers order without two or more of them ordering the same type of roll?

It is impossible for the six customers to each order different types, since there are only five types, so the answer is 0. This is actually an instance of the Second Counting Problem (no repeats, order matters) with n=5 and k=6. The standard solution is 56 = 5*4*3*2*1*0 = 0, which is correct.

Question 2 (30): Let n and k be arbitrary positive naturals with k ≤ n.

• (a,5) How many binary strings of length n have k or fewer ones?

There are (n choose i) with exactly i ones, so the answer is (n choose 0) + (n choose 1) + ... + (n choose k), the sum for i from 0 to k of (n choose i).

• (b,5) How many binary strings of length n+1 have exactly k ones?

There are (n+1 choose k). Sorry, this problem was too easy for five points.

• (c,10) Prove that for any naturals n and k, the number of binary strings of length n+1 with k ones equals the number of binary strings of length n with either k or k-1 ones.

Let n and k be arbitrary naturals. Let A be the n+1-length strings with k ones, B be the n-length strings with k ones, and C be the n-length strings with k-1 ones. Note that B and C are disjoint. We define a bijection f from A to (B union C). Let w be a string in A. We define f(w) to be the first n letters in w. (Note that w has length n+1 ≥ 1.) If the last letter in w is 0, then f(w) is in B. If the last letter in w is 1, then f(w) is in C. This function is one-to-one because two different strings in w must differ either in the first n letters or in the last letter. It is onto because if v is any string in B, then v = f(v0), and if v is any string in C, then v = f(v1). Since there is a bijection from A to (B union C), these two sets have the same size. Since n and k were arbitrary, we are done.

• (d,10) Prove by induction that for all naturals n and k with k ≤ n, the number of binary strings of length n with k or fewer ones is greater than or equal to the number of binary strings of length n+1 with exactly k ones. (Hint: Let n be arbitary and use induction on k, starting with k=1.)

As suggested, we let n be arbitrary and use induction on k, starting with k=1 and assuming k ≤ n. We have formulas for each number of strings from (a) and (b).

Base Case: For k=1, the sum for i from 0 to 1 of (n choose i) is (n choose 0) + (n choose 1) = n + 1. Since (n+1 choose 1) = n+1, and n+1 ≥ n+1, we have the desired inequality.

Inductive case: Assume that the sum for i from 0 to k of (n choose i) is greater than or equal to (n+1 choose k). We express the sum for i from 0 to k+1 of (n choose i) as this sum, plus (n choose k+1). So the sum up to k+1 is greater than or equal to (n+1 choose k) + (n choose k+1) by the inductive hypothesis. Using the identity from (c), we write (n+1 choose k) as (n choose k) + (n choose k-1), so that our original sum is greater than or equal to (n choose k) + (n choose k-1) + (n choose k+1). Since (n choose k-1) is a natural, this is greaterthan or equal to (n choose k) + (n choose k+1). This in turn is equal to (n+1 choose k+1) by the identity in (c) again.

We have completed the induction and thus the proof. The assumption that k ≤ n appears never to have been needed.

Question 3 (30): If n and k are any naturals, define h(n,k) to be the number of subsets of the set {1,...,n} of size k that do not contain two adjacent numbers. For example, h(4,2) = 3 because the relevant sets are {1,3}, {1,4}, and {2,4}. The other three subsets of size 2 contain two adjacent numbers.

• (a,10) Explain why h(n,0) = 1, h(n,1) = n, and h(n,2) = (n-1 choose 2).

Since there is exactly one empty set and it has no adjacent elements, h(n,0) = 1.

Since there are (n choose 1) = n one-element sets and none of them have adjacent elements, h(n,1) = n.

We prove h(n,2) = (n-1 choose 2) by induction on n. For n≤2 no two-element set is possible, and (-1 choose 2), (0 choose 2), and (1 choose 2) are all 0. For the inductive case, assume there are (n-1 choose 2) such 2-element subsets of {1,...,n}. The 2-element subsets {1,...,n+1} consist of all of these, plus the set {k,n+1} for all k from 1 through n-1. This totals to (n-1 choose 2) + (n-1 choose 1) which is (n choose 2) by Pascal's Identity (Question 2(c) on this exam).

• (b,5) Explain why h(n,k) = 0 if n is even and k > n/2.

If k > n/2, then k-1 ≥ n/2. If there were any sets of k elements without any adjacent elements, we would have k elements in the set and at least k-1 elements in the k-1 nonempty gaps between these k elements. This would add to more than n/2 + n/2 = n elements, which is impossible.

• (c,15) Prove that h(n,k) = (n choose 2k-1) for all n and k. (Hint: Define and justify a bijection from the no-adjacent element sets of size k and all the sets of size 2k-1.)

Aargh. This is wrong, as I should have seen because it doesn't agree with part (a) for k=2. The correct value for h(n,k) is (n-k+1 choose k). This can be shown two ways, by induction or by finding a bijection. To proceed by induction as for the n=2 case, note that a no-adjacent set of size k from {1,...,n+1} is either a set of size k from {1,...,n}, or {n+1} unioned with a no-adjacent set of size k-1 from {1,..,n-1}. So h(n+1,k) = h(n,k) + h(n-1,k-1). If we assume the IH for k-1, this becomes h(n,k) + (n-k+1 choose k-1). If we assume the IH for n and k, this becomes (n-k+1 choose k) + (n-k+1 choose k-1). By Pascal's Identity this equals (n-k choose k), verifying the formula for h(n+1,k).

The combinatorial proof is to find a bijection between no-adjacent size-k subsets of {1,...,n} and arbitrary size-k subsets of {1,...,n-k+1}. This is easiest in the other direction. Write the size-k subset of {1,...,n-k+1} as a binary string with k ones and n-1 zeros. The bijection replaces the first k-1 ones with 10's and leaves the zeros and the last 1 alone. This increases the length to n and forces the longer sequence to not have two ones in a row.

Question 4 (20): The word "CAMBRIDGE" consists of nine different letters.

• (a,5) How many three-letter strings can be formed from the letters of "CAMBRIDGE" without repeating a letter?

Second Counting Problem with n=9 and k=3, answer 93 = 9*8*7 = 504.

• (b,5) If I choose one of the three-letter strings at random, what is the probability that I get one whose letters are in alphabetical order, as in the string "AIM"?

There is one in-order string for each of the three-element subsets of {C,A,M,B,R,I,D,G,E}. The number of such subsets is (9 choose 3) = 9*8*7/1*2*3 = 84. The probability is the number of in-order strings over the number of all strings, or 84/504 = 1/6. Without calculating this, we can see that the three letters chosen are equally likely to be in any of the six possible orders, so we could get the answer of 1/6 that way as well.

• (c,10) If I divide the nine letters into three three-letter strings with every division being equally likely, what is the expected number of strings that will have their letters in alphabetical order? Justify your answer.

This problem probably could have been stated more clearly. I mean to put the nine letters in a random order, and look at the strings given by the first three, middle three, and last three letters in this order. There is a 1/6 probability that the first three are in order, so the expected number of in-order strings is (1/6)*1 + (5/6)*0 = 1/6. Similarly the expected number of middle strings in order is 1/6, and the same for last-three strings. Since expected values add whether or not the random variables are independent, the total expected number of in-order strings is 1/6 + 1/6 + 1/6 = 1/2.