Math 5366 Fall 2015 Exam 2 Solutions 1. (20 points) Find the appropriate generating function (in closed form) for each of the following problems. Do not find the coefficient of xn . (a) In how many ways can n balls be put in 4 boxes if each box is nonempty? x . 1−x x4 The generating function for the problem is the fourth power of this, . (1 − x)4 Solution: The generating function for each box is x + x2 + x3 + · · · = (b) How many quaternary sequences (0’s, 1’s, 2’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 + x2 2! + x3 3! + · · · )4 = (ex − 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? 1 Solution: The generating function for the first box is 1 + x2 + x4 + · · · = 1−x 2. x 3 5 For the last box, it is x + x + x + · · · = 1−x2 . For the problem we have 1 1 x x 1 = . 1 − x 2 1 − x 1 − x 1 − x2 (1 − x2 )2 (1 − x)2 (d) How many quaternary sequences of length n have an even number of 0’s and an odd number of 1’s? ex + e−x ex − e−x , odd number of 1’s: , our 2 2 ex + e−x ex − e−x 2x e4x − 1 generating function is e = . 2 2 4 Solution: Even number of 0’s: 2. (20 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 2 balls? Solution: The generating function for the first box is x2 +x3 +x4 +· · · = x2 . 1−x x2 for the problem, the generating function is , and the coefficient of xn in 4 (1 − x) n−2+4−1 n+1 this is = . 4−1 3 (b) How many quaternary sequences of length n have at least two 0’s? 2 3 Solution: For 0 we need x2! + x3! + · · · = ex − 1 − x. The rest just contribute ex each. The generating function for the problem is e4x − e3x − xe3x . The answer to the question is n! times the coefficient of xn in this expression or n 3n 3n−1 4 − − n! = 4n − 3n − n3n−1 . n! n! (n − 1)! 3. (10 points) Find a recurrence, with initial conditions, for an , the number of ternary sequences of length n in which all the 0’s occur before any 2. Hint: After the first 2 appears, the remaining digits can only be 1’s and 2’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 2. The count for this is an−1 , so there are 2an−1 strings of this type. If the string starts with a 2, then the remaining n − 1 positions consist of only 1’s and 2’s, and there are a total of 2n−1 strings of this type. The total count is an = 2an−1 +2n−1 . For the initial conditions, the empty string fulfills the requirements so a0 = 1. Alternatively, all strings of length 1 are ok so a1 = 3. As a check, the recurrence continues 1, 3, 8, 20, 28, . . . . How many bad strings of length 3 are there? I count 7: 200, 201, 202, 220, 210, 020, 120. This leaves 33 − 7 = 20 good strings, as it should. Page 2 4. (20 points) Solve each of the following recurrence relations (a) an = 7an−1 − 10an−2 , a0 = 4, a1 = 11. Solution: The characteristic polynomial is x2 − 7x + 10 = (x − 2)(x − 5) so the general solution is an = A2n + B5n . The initial conditions give us A + B = 4, 2A + 5B = 11. Multiplying the first by 2 and subtracting from the second, 3B = 3. Thus, B = 1, A = 3, and the solution is an = 3 · 2n + 5n . (b) an = 6an−1 − 9an−2 , a0 = 1, a1 = 9. Solution: Here, the characteristic polynomial is x2 − 6x + 9 = (x − 3)2 . Since there is a multiple root the general solution is an = (An + B)3n . The initial conditions now say B = 1, 3A + 3B = 9, or A = 2. The solution is an = (2n + 1)3n . 5. (20 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) an = 7an−1 − 10an−2 − 2 · 3n , a0 = 12, a1 = 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 A2n + B5n from question 4. For a particular solution, we should guess an = P 3n . Trying this, P 3n = 7P 3n−1 − 10P 3n−2 − 2 · 3n . Dividing by 3n−2 , 9P = 21P − 10P − 18, or 2P = 18. So the general solution to the recurrence is A2n + B5n + 9 · 3n . The initial conditions yield A + B + 9 = 12, 2A + 5B + 27 = 39. From these, we get B = 2, A = 1 so the solution we seek is an = 2n + 2 · 5n + 3n+2 . (b) an = 7an−1 − 10an−2 + 3 · 5n−1 , a0 = 1, a1 = 7. Solution: Since 5n is already part of the homogeneous solution, for a particular solution we should guess an = P n5n . Trying this, P n5n = 7P (n − 1)5n−1 − 10P (n − 2)5n−2 + 3 · 5n−1 . Dividing by 5n−1 , 5nP = 7(n − 1)P − 2P (n − 2) + 3. If you really trust yourself, you can plug in a value for n to get P. One student use n = 2 to get 10P = 7P + 3. I just worked with the original expression: 5nP = 7nP − 7P − 2nP + 4P + 3 → nP (5 − 7 + 2) + P (7 − 4) = 3. Either way, P = 1, and the general solution is A2n + B5n + n · 5n . The initial conditions give A + B = 1, 2A + 5B + 5 = 7. From these, we get A = 1, B = 0. The solution we seek is an = 2n + n5n . 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 3n and the general solution will be an = A2n +B5n +(particular) = A2n +B5n +P 3n , then we can create another initial condition and solve for A, B, P using those. In this case, a2 = 135. We have A + B + P = 12, 2A + 5B + 3P = 39, 4A + 25B + 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 = 12 → B = 2, P = 9, A = 1. On 5(b), we could not use an = A2n + B5n + P 5n because 5n would be used twice so we need an = A2n + B5n + P n5n . With a2 = 54, A + B = 1, 2A + 5B + 5P = 7, 4A + 25B + 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) an = an−1 + 3an−2 + 9an−3 + · · · + 3n−1 a0 , a0 = 3. Solution: Here are two approaches: First, if we just plug in values, a1 = a0 = 3, a2 = a1 + 3a0 = 12, a3 = 12 + 3 · 3 + 9 · 3 = 48, we might be able to guess that an = 3 · 4n−1 , when n ≥ 1, with a0 = 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 an = 3 · 4n−2 + 32 · 4n−3 + · · · + 3n−1 40 + 3n . All but the last term form a geometric progression (ratio 43 ) so 3 · 4n−2 − 43 3n−1 40 an = 3 + = 3n + 3 · 4n−1 − 3n = 3 · 4n−1 , 1 − 43 n as desired. More thematic is the following: If n ≥ 2 then we can write an−1 = an−2 +3an−3 + · · · + 3n−2 a0 . We multiply this by 3 and subtract from the original recurrence: an = an−1 + 3an−2 + 9an−3 + · · · + 3n−1 a0 −(3an−1 = 3an−2 + 32 an−3 + · · · + 3n−1 a0 ) to get an − 3an−1 = an−1 , or an = 4an−1 , but not starting at n = 1 but at n = 2. Since a1 = 3, we have, for n ≥ 1, an = 3 · 4n−1 , as above. Page 4 (b) an = nan−1 + 3n − 3, a0 = 1. Strong hint: One approach is to guess a particular solution of the form an = 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, an = nan−1 can easily be solved by iteration: a1 = 1 · a0 , a2 = 2a1 = 2 · 1 · a0 , a3 = 3 · 2 · 1a0 , etc. so an = An!. But what about the particular solution? The hint says to try an = 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 an = An! − 3, and a0 = 1 requires A = 4. The solution is an = 4n! − 3. 7. Some extra credit questions, if you are interested. Generating functions help on (d). (a) (2 points) Solve the recurrence in question 3. (b) (8 points) Find, with initial conditions, a recurrence for an , the number of sequences of length n made of 0’s, 1’s, 2’s, 3’s, 4’s, if all 0’s appear before any 2 and all 2’s appear before any 4. Solve the recurrence. I will give credit for sufficient progress. (c) (4 points) Solve the recurrence an = an−1 + 2an−2 + 3an−3 + · · · + na0 , a0 = 1. (d) (4 points) Solve the recurrence an = nan−1 + (n − 1)an−2 + · · · + a0 , a0 = 1. Page 5
© Copyright 2025 Paperzz