Solutions to this exam are here.

- Answer the problems on the exam pages.
- There are four problems for 95 total points plus 10 extra credit. Actual scale was A=92, C=62.
- If you need extra space use the back of a page.
- No books, notes, calculators, or collaboration.

Q1: 25 points Q2: 30 points Q3: 20 points plus 10 extra credit Q4: 20 points Total: 95 points plus 10 extra credit

**Question 1 (25):**Five customers, whom we'll call A, B, C, D, and E, enter a small video rental shop. The shop has only one copy of each of the three*Lord of the Rings*movies, which we'll call movies 1, 2, and 3.- (a,5) In how many ways may the three movies each be assigned to one of the customers? (An example assignment might be "A gets movie 1, D gets movie 2, A gets movie 3".)
- (b,5) In how many ways could the above assignment be made if we only consider how many movies each customer gets? (So the above example becomes "A gets two movies, D gets one, and the others get none".)
- (c,5) How many of the assignments in part (a) are possible if no customer may get more than one movie?
- (d,5) How many of the assignments in part (b) are possible if no customer may
get more than one movie?
**Note: In parts (a)-(d) every movie must be assigned to a customer.** - (e,5) Now suppose that the store has at least five copies of each movie, and
that each customer may take some of the movies, all of them, or none.
**(But no customer may take more than one copy of the same movie.)**(Example: "A takes 1 and 3, B takes none, C takes all, D takes 3 only, E takes 2 and 3") In how many ways can the assignment of movies to customers be made?

**Question 2 (30):**This problem involves strings over the alphabet {a,b,c}. A**palindrome**is a string that is equal to its own reversal, such as λ, aba, or cabbac.- (a,5) List all the palindromes of length 0, 1, and 2.
- (b,10) Let n be an arbitrary natural. Explain why the number of palindromes of length n+2 is exactly three times the number of palindromes of length n.
- (c,15)
Using the result of (b), whether you proved it or not, prove
*by induction*for all naturals n that the number of palindromes of length n is 3^{(n+1)/2}, where the slash represents Java integer division. (Hint: You may use either string induction of separate inductions for odd and even numbers. Remember that if k is a natural, (k+2)/2 is always equal to (k/2) + 1 for Java integer division.)

**Question 3 (20+10):**In the card game of**Blackjack**or**twenty-one**the player is dealt two cards. (For the purposes of this problem we will say that they are dealt from a standard 52-card deck, with four cards in each of the thirteen ranks {A,2,3,4,5,6,7,8,9,10,J,Q,K}.)- (a,10) To get a score of 21, one of the cards must be an ace and the other must have a rank in the set {10,J,Q,K}. If any set of two cards is equally likely, what is the probability that the player's score is 21?
- (b,10) To get a score of 20, both cards must have ranks in the set {10,J,Q,K}.
**(Note: This isn't actually true because you could have an ace and a nine, but you were told to solve the problem as written.)**What is the probability of this happening, if each set of two cards is equally likely? - (c,10 extra credit) Counting an ace as 11, a card with rank in {J,Q,K} as 10, and every other card as its numerical value, what is the probability that the player has a score of 17, 18, 19, 20, or 21 with her two cards?

**Question 4 (20):**This question deals with the undirected graph in the following picture. Recall that an edge in an undirected graph may be traversed in*either*direction. (**Note: This graph has no loops and exactly four edges.**)(2)-------(3) | \ / | \ / | \ / | \/ | /\ | / \ | / \ | / \ (1) (4)

- (a,5) Write the adjacency matrix of this graph, using the numerical order on the vertices {1,2,3,4}.
- (b,15) Determine how many paths of length 0, 1, 2, 3, and 4 there are from vertex 1 to vertex 4 in this graph, and list these paths. (For example, there is exactly one two-step path from 1 to 3, which we may describe as "1 to 2 to 3".) (Hint: If you do one complete matrix multiplication, you can compute the individual entries of the other matrices you need. It is also possible to find all the paths by exhaustive search, but the matrix method is more reliable.)

Last modified 24 April 2005