Math 5366 Fall 015 Exam Solutions 1. (0 points) Find the appropriate generating function (in closed form) for each of the following problems. Do not find the coefficient of x n. (a) In how many ways can n balls be put in 4 boxes if each box is nonempty? Solution: The generating function for each box is x + x + x 3 + = x 1 x. x 4 The generating function for the problem is the fourth power of this, (1 x). 4 (b) How many quaternary sequences (0 s, 1 s, s, 3 s) of length n are there having at least 1 of each of the four digits? Solution: Here, the generating function is (x + x! + x3 3! + ) 4 = (e x 1) 4. (c) In how many ways can n balls be put in 4 boxes if the first box has an even number of balls and the last box has an odd number of balls? Solution: The generating function for the first box is 1 + x + x 4 + = 1. 1 x For the last box, it is x + x 3 + x 5 + = x. For the problem we have 1 x 1 1 1 x 1 x 1 x 1 x 1 x = x (1 x ) (1 x). (d) How many quaternary sequences of length n have an even number of 0 s and an odd number of 1 s? e x + e x Solution: Even number of 0 s:, odd number of 1 s: generating function is ex + e x e x e x e x = e4x 1. 4 e x e x, our
. (0 points) Find the generating function for each of the following problems. Then SOLVE for the number asked. (a) In how many ways can n balls be put into 4 boxes if the first box has at least balls? x 1 x. x (1 x), and the coefficient of 4 xn in Solution: The generating function for the first box is x +x 3 +x 4 + = for the problem, the generating function is ( ) ( ) n + 4 1 n + 1 this is =. 4 1 3 (b) How many quaternary sequences of length n have at least two 0 s? Solution: For 0 we need x + x3 + =! 3! ex 1 x. The rest just contribute e x each. The generating function for the problem is e 4x e 3x xe 3x. The answer to the question is n! times the coefficient of x n in this expression or ( ) 4 n n! n! 3n n! 3n 1 = 4 n 3 n n3 n 1. (n 1)! 3. (10 points) Find a recurrence, with initial conditions, for a n, the number of ternary sequences of length n in which all the 0 s occur before any. Hint: After the first appears, the remaining digits can only be 1 s and s. Solution: If the sequence starts with either 0 or 1, then filling in the remaining n 1 positions is the same kind of problem: they must have all 0 s occurring before any. The count for this is a n 1, so there are a n 1 strings of this type. If the string starts with a, then the remaining n 1 positions consist of only 1 s and s, and there are a total of n 1 strings of this type. The total count is a n = a n 1 + n 1. For the initial conditions, the empty string fulfills the requirements so a 0 = 1. Alternatively, all strings of length 1 are ok so a 1 = 3. As a check, the recurrence continues 1, 3, 8, 0, 8,.... How many bad strings of length 3 are there? I count 7: 00, 01, 0, 0, 10, 00, 10. This leaves 3 3 7 = 0 good strings, as it should. Page
4. (0 points) Solve each of the following recurrence relations (a) a n = 7a n 1 10a n, a 0 = 4, a 1 = 11. Solution: The characteristic polynomial is x 7x + 10 = (x )(x 5) so the general solution is a n = A n + B5 n. The initial conditions give us A + B = 4, A + 5B = 11. Multiplying the first by and subtracting from the second, 3B = 3. Thus, B = 1, A = 3, and the solution is a n = 3 n + 5 n. (b) a n = 6a n 1 9a n, a 0 = 1, a 1 = 9. Solution: Here, the characteristic polynomial is x 6x + 9 = (x 3). Since there is a multiple root the general solution is a n = (An + B)3 n. The initial conditions now say B = 1, 3A + 3B = 9, or A =. The solution is a n = (n + 1)3 n. 5. (0 points) solve each of the following inhomogeneous recurrence relations. Hint: You solved the homogeneous problem in part 3a. Sorry about that it should have been 4(a). (a) a n = 7a n 1 10a n 3 n, a 0 = 1, a 1 = 39. Solution: The general solution to an inhomogeneous recurrence has the form (Particular solution to inhomogeneous recurrence) + (general homogeneous solution). We know the general homogeneous solution is A n + B5 n from question 4. For a particular solution, we should guess a n = P 3 n. Trying this, P 3 n = 7P 3 n 1 10P 3 n 3 n. Dividing by 3 n, 9P = 1P 10P 18, or P = 18. So the general solution to the recurrence is A n + B5 n + 9 3 n. The initial conditions yield A + B + 9 = 1, A + 5B + 7 = 39. From these, we get B =, A = 1 so the solution we seek is a n = n + 5 n + 3 n+. (b) a n = 7a n 1 10a n + 3 5 n 1, a 0 = 1, a 1 = 7. Solution: Since 5 n is already part of the homogeneous solution, for a particular solution we should guess a n = P n5 n. Trying this, P n5 n = 7P (n 1)5 n 1 10P (n )5 n + 3 5 n 1. Dividing by 5 n 1, 5nP = 7(n 1)P P (n ) + 3. If you really trust yourself, you can plug in a value for n to get P. One student use n = to get 10P = 7P + 3. I just worked with the original expression: 5nP = 7nP 7P np + 4P + 3 np (5 7 + ) + P (7 4) = 3. Either way, P = 1, and the general solution is A n + B5 n + n 5 n. The initial conditions give A + B = 1, A + 5B + 5 = 7. From these, we get A = 1, B = 0. The solution we seek is a n = n + n5 n. Page 3
Here is another approach to problems like number 5. Take part (a). If we know that the particular solution has to have the form P 3 n and the general solution will be a n = A n +B5 n +(particular) = A n +B5 n +P 3 n, then we can create another initial condition and solve for A, B, P using those. In this case, a = 135. We have A + B + P = 1, A + 5B + 3P = 39, 4A + 5B + 9P = 135. Subtracting twice the second from the third and then twice the first from the second, 15B + 3P = 57, 3B + P = 15, and we get 6B = 1 B =, P = 9, A = 1. On 5(b), we could not use a n = A n + B5 n + P 5 n because 5 n would be used twice so we need a n = A n + B5 n + P n5 n. With a = 54, A + B = 1, A + 5B + 5P = 7, 4A + 5B + 50P = 54. We quickly find A = 1, B = 0, P = 1. This method requires that we know the form of the particular solution. It usually requires more effort than the method outlined in the book and in class (more variables and more equations to solve) but in small cases it can be pretty fast. 6. (10 points) Solve each of the following recurrence relations. You may use any approach that can be sufficiently justified. I will give extra credit if you use generating functions. (a) a n = a n 1 + 3a n + 9a n 3 + + 3 n 1 a 0, a 0 = 3. Solution: Here are two approaches: First, if we just plug in values, a 1 = a 0 = 3, a = a 1 + 3a 0 = 1, a 3 = 1 + 3 3 + 9 3 = 48, we might be able to guess that a n = 3 4 n 1, when n 1, with a 0 = 3, which technically does not fit the pattern. With this guess, we could verify by induction that the guess is right: if true through n 1 then a n = 3 4 n + 3 4 n 3 + + 3 n 1 4 0 + 3 n. All but the last term form a geometric progression (ratio 3 4 ) so a n = 3 n + 3 4n 3 4 3n 1 4 0 1 3 4 = 3 n + 3 4 n 1 3 n = 3 4 n 1, as desired. More thematic is the following: If n then we can write a n 1 = a n +3a n 3 + + 3 n a 0. We multiply this by 3 and subtract from the original recurrence: a n = a n 1 + 3a n + 9a n 3 + + 3 n 1 a 0 (3a n 1 = 3a n + 3 a n 3 + + 3 n 1 a 0 ) to get a n 3a n 1 = a n 1, or a n = 4a n 1, but not starting at n = 1 but at n =. Since a 1 = 3, we have, for n 1, a n = 3 4 n 1, as above. Page 4
(b) a n = na n 1 + 3n 3, a 0 = 1. Strong hint: One approach is to guess a particular solution of the form a n = P, and then solve the homogeneous problem. Solution: The point of this problem is to stress this idea that for an inhomogeneous system, General solution = General homogeneous solution + Particular solution. The homogeneous problem, a n = na n 1 can easily be solved by iteration: a 1 = 1 a 0, a = a 1 = 1 a 0, a 3 = 3 1a 0, etc. so a n = An!. But what about the particular solution? The hint says to try a n = P, a constant. We get P = np + 3n 3, or n(p + 3) (P + 3) = 0, and this should be 0 for all n. This happens when P = 3 so our particular solution worked. The general solution is a n = An! 3, and a 0 = 1 requires A = 4. The solution is a n = 4n! 3. 7. Some extra credit questions, if you are interested. Generating functions help on (d). (a) ( points) Solve the recurrence in question 3. (b) (8 points) Find, with initial conditions, a recurrence for a n, the number of sequences of length n made of 0 s, 1 s, s, 3 s, 4 s, if all 0 s appear before any and all s appear before any 4. Solve the recurrence. I will give credit for sufficient progress. (c) (4 points) Solve the recurrence a n = a n 1 + a n + 3a n 3 + + na 0, a 0 = 1. (d) (4 points) Solve the recurrence a n = na n 1 + (n 1)a n + + a 0, a 0 = 1. Page 5