Professional Documents
Culture Documents
(1 + x2 )3
(b)
(1 − x)6
Solution: ∞
(1 + x2 )3
2 4 6
X k+5 k
= (1 + 3x + 3x + x ) x .
(1 − x)6 k=0
k
15 20 18 16 14
The coefficient of x will be +3 +3 + = 56, 314.
5 5 5 5
2. Find a closed form expression for the generating function for the sequence:
(a) 5, 5, 5, 5, · · ·
5
Solution: Answer: 5 + 5x + 5x2 + · · · = .
1−x
(b) 5, 0, 5, 0, 5, 0, · · ·
3. Use the answer to part (c) above to find a formula for 1 + 6 + · · · + (1 + 2n + 3n2 ).
1
Solution: We need the coefficient of xn in 1−x A(x), where A(x) is the generating
function for the sequence in part (c). That is, we need the coefficient of xn in
2 7 6
2
− 3
+ ,
(1 − x) (1 − x) (1 − x)4
or
2n3 + 5n2 + 5n + 2
n+1 n+2 n+3
2 −7 +6 = .
1 2 3 2
4. Find the generating function for each of the following problems. Write your answer as
1 2
simply as possible (that is, 1 + x2 + x3 + x4 + · · · should be written 1−x − x or 1−x+x
1−x
.)
n
Note: Just find the generating function (ordinary or exponential,) don’t solve for x .
(a) In how many ways can n balls be put into 5 boxes if there is at least one ball in the
first box and at most 3 in the second?
Solution:
x 1 1 1 x(1 + x + x2 + x3 ) x − x5
(1 + x + x2 + x3 ) = , or .
1−x 1−x1−x1−x (1 − x)4 (1 − x)5
Page 2
(b) How many sequences made up of a, b, c, d, e of length n are there if there is at least
one a and at most 3 b’s?
Solution:
x2 x3 x x x x2 x3
x
(e − 1) 1 + x + + e e e = 1+x+ + (e4x − e3x )
2! 3! 2! 3!
(c) How many ways can n balls be put into 5 boxes if the first box has an even number
of balls and the second, an odd number?
(d) How many sequences made up of a, b, c, d, e of length n are there if there must be
an even number of a’s and an odd number of b’s?
ex + e−x ex − e−x
Solution: Here, the generating functions for even/odd are and .
2 2
The generating function we seek is
(e) How many ways can n balls be put into 5 boxes if no box has exactly 2 balls?
1
Solution: For one box it would be 1 + x + x3 + x4 + · · · = − x2 =
1−x
1 − x 2 + x3
. Probably the first formula is better. Our generating function is
1−x
5
1 2
−x .
1−x
Page 3
(f) How many sequences made up of a, b, c, d, e of length n are there if you can’t have
exactly 2 of any letter?
5
x2
x
Solution: Here there really only is one answer: e − .
2
x − x5
Solution: We seek the coefficient of xn in. This will be
(1 − x)5
n−1+4 n−5+4 n+3 n−1
− = − .
4 4 4 4
I will
note that this formula is correct if n > 0 (rather than just n > 5) because
n
k
is defined to be 0 k > n ≥ 0.
(b) How many sequences made up of a, b, c, d, e of length n are there if there is at least
one a and at most 3 b’s?
(c) How many ways can n balls be put into 5 boxes if the first box has an even number
of balls and the second, an odd number?
x
Solution: We need the coefficient of xn in . This is just a hard
(1 − x2 )2 (1
− x)3
problem. If we were to use partial fractions, we would have
x x
=
(1 − x2 )2 (1 − x)3 (1 + x)2 (1 − x)5
1 3 4 4 4 3 2
= − − + + − − .
64 1 − x (1 − x)2 (1 − x)3 (1 − x)5 1 + x (1 + x)2
Page 4
Our coefficient would be
1 n+2 n+4 n n
−3 − 4(n + 1) + 4 +4 − 3(−1) − 2(n + 1)(−1) .
64 2 4
(d) How many sequences made up of a, b, c, d, e of length n are there if there must be
an even number of a’s and an odd number of b’s?
(e) How many ways can n balls be put into 5 boxes if no box has exactly 2 balls?
Solution: We have
5
5x2 10x4 10x6 5x8
1 2 1
−x = 5
− 4
+ 3
− 2
+ − x10
1−x (1 − x) (1 − x) (1 − x) (1 − x) 1−x
so if n > 10 we get
n+4 n+1 n−2
−5 + 10 − 10(n − 5) + 5,
4 3 2
(f) How many sequences made up of a, b, c, d, e of length n are there if you can’t have
exactly 2 of any letter?
Solution: This time, the two cases are fairly similar in complexity. We have
5
x2
x
e − = e5x − 5x2 e4x + 10x4 e3x − 10x6 e2x + 5x8 ex − x10
2
5n − 5n(n − 1)4n−2 + 10P (n, 4)3n−4 − 10P (n, 6)2n−6 − 5P (n, 8).
Page 5
6. Use generating functions to find the number of ways to put n balls into 3 boxes if the
first box can hold at most 5 balls and the second can hold at most 10. Your answer will
vary depending on the size of n. For large n, simplify your answer as much as possible.
Can you prove your answer (for large n) by an easy counting argument?
or
(1 − x6 )(1 − x11 ) 1 − x6 − x11 + x17
= .
(1 − x)3 (1 − x)3
The coefficient of xn in this expression, for large n is
n+2 n−4 n−9 n − 15
− − + .
2 2 2 2
Expanding this out and simplifying, you get a constant, 66. The reason: for large
n, there are 6 choices for how many balls to put in the first box and 11 for the
second. What’s left goes in the third box. So if n ≥ 17 we get 6 × 11 = 66 possible
combinations.
7. Find recurrences, with initial conditions, for each of the following problems.
(a) How many n-digit ternary sequences do not contain consecutive 0’s?
Solution: This is kind of easy after the last few questions. The reason: This
problem (both parts) came from a past exam. If the first position is a 1 or a
2, the remaining n − 1 positions just have to avoid consecutive 0’s. This can
happen in 2an−1 ways. If the first position is a 0 then the second position must
contain 1 or 2, and the remaining n − 2 positions just need to avoid consecutive
0’s. The relation is an = 2an−1 + 2an−2 .
For initial conditions, the empty sequence does not contain consecutive 0’s, nor
does any sequence of length 1 so we have a0 = 1, a1 = 3. If you worry about
whether the empty sequence has some property, you can find a1 and a2 instead.
In this case there is only one bad string of length 2 so a2 = 9 − 1 = 8.
Solution: Usually, the recurrence for this kind of problem is the same as for
without, except that there will be an inhomogeneous term. The count goes like
this: If the first position is a 1 or a 2, then we need to pick up consecutive 0’s
Page 6
among the remaining n − 1 positions for a count of 2an−1 . If the first position
is a 0 but the second is 1 or 2, we still need consecutive 0’s, and they must
come from the remaining n − 2 positions for a count of 2an−2 . But here, we
have another case: If the first two positions are 0’s, we have our consecutive
0’s and the remaining n − 2 positions are arbitrary. The recurrence is an =
2an−1 + 2an−2 + 3n−2 . Here, the initial conditions are a0 = 0, a1 = 0, or if you
prefer, a1 = 0, a2 = 1.
(c) How many n-digit quaternary sequences do not contain any of 00, 10, 10, 11?
Solution: First, there is a typo: It should have been 00, 01, 10, 11 that we are
avoiding. If the first position is a 2 or a 3, then we need only avoid 00, 01, 10,
11 in the remaining n − 1 positions. This leads to a count of 2an−1 . If we start
with a 0 or a 1, then the next position must be a 2 or a 3, and the remaining
n − 2 positions must still avoid 00, 01, 10, 11. Since there are two possibilities
for each of the first two positions, this case has a count of 4an−2 . Our recurrence
is an = 2an−1 + 4an−2 , with initial conditions a0 = 1, a1 = 4.
(d) How many n-digit quaternary sequences do not have any 0’s or 1’s to the right of
any 3?
Solution: If we start with 0, 1 or 2, then we need only avoid 3’s to the right of
0’s or 1’s the rest of the way for a count of 3an−1 . But if the first position is a
3, then no subsequent position can be 0 or 1, leaving only two choices (2 or 3)
for each of the remaining n − 1 positions, for a count of 2n−1 . Our recurrence is
an = 3an−1 + 2n−1 with initial condition a0 = 1.
Solution: For the practice, I will use the iterative approach. We have
a0 = 1, a1 = 3 + 1, a2 = 32 + 3 + 2, a3 = 33 + 32 + 2 · 3 + 22 , . . .
This might be enough to guess that an will have two pieces, 3n and a geometric piece
3n−1 + 2 · 3n−2 + 22 3n−3 + · · · + 2n−1 . If we multiply this second piece by 3 - 2 it
becomes 3n − 2n . Thus, it appears that an = 2 · 3n − 2n . To check, we show that this
satisfies the recurrence. If an−1 = 2 · 3n−1 − 2n−1 then
as desired.
Page 7
9. I once put the following problem on Exam 2, but the class found it fairly hard (under
exam conditions). Suppose we form a sequence out of the numbers 0, 1, 2, 3, 4, 5.
(a) Find a recurrence for an , the number of such sequences of length n which don’t
contain consecutive numbers not divisible by 3. That is, sequences like 10403 are
ok but 13423 is not because 4 and 2 are consecutive numbers not divisible by 3.
Solution: o and 3 are divisible by 3, and 1, 2, 4, 5 are not. If the first position
is 0 or 3, we just need to avoid consecutive numbers not divisible by 3 in the
remaining n − 1 positions, contributing 2an−1 . If the first digit is 1, 2, 4, or 5,
then the next digit must be 0 or 3, and we need to avoid numbers not divisible
by 3 in the remaining n − 2 positions. This gives a count of 4 · 2an−2 for this
case. The recurrence is an = 2an−1 + 8an−2 .
Solution: This was the point of the problem: I was proud of myself for coming
up with a fairly natural recurrence that had a nice solution. The characteristic
polynomial is x2 − 2x − 8 = (x + 2)(x − 4). The general solution is an =
A(−2)n + B4n . The initial conditions tell us A + B = 1, −2A + 4B = 6 so
4n+1 − (−2)n
B = 43 , A = − 13 . Our solution is an = .
3
(d) Find a recurrence for the number of such sequences of length n which DO contain
consecutive numbers not divisible by 3. Now 10403 is not ok but 13423 is not.
Another typo here–it was supposed to say that 12423 IS OK.
Page 8
10. Solve the following recurrence relations.
(a) an = 3an−1 + 4an−2 − 12an−3 , a0 = 1, a1 = 4, a2 = 14.
This simplifies to −2P = −2, or P = 1. The fact that the n2 terms and n
terms cancelled tells us that our guess was right. The general solution is an =
(A+Bn)2n +C3n +2n , and the initial conditions give A+C = 4, 2A+2B +3C =
5, 4A + 8B + 9C = 5, leading to A = 3, B = −2, C = 1. The solution to the
recurrence is an = 3n + (n2 − 2n + 3)2n .
Page 9
(e) an = 2an−1 − an−2 , a0 = 1, a1 = 3, USING generating functions.
∞
X
Solution: We let A(x) = an xn . We pull off the first two terms and use the
n=0
recurrence:
∞
X ∞
X
n
A(x) = a0 + a1 x + an x = a0 + a1 x + (2an−1 − an−2 )xn
n=2 n=2
∞
X ∞
X
n
We break the sum into two pieces 2 an−1 x , − an−2 xn . The second of
n=2 n=2
these is −a0 x2 − a1 x3 − a2 x4 + · · · = −x2 A(x). For the first, we do something
similar. Factoring an x out we have 2x(a1 x + a2 x2 + · · · ) = 2x(A(x) − a0 ).
Putting the pieces together, A(x) = a0 + a1 x + 2x(A(x) − a0 ) − x2 A(x). We
solve this equation for A(x) and we have (x2 − 2x + 1)A(x) = a0 + x(a1 − 2a0 ).
Plugging in the initial conditions,
1+x 1+x
A(x) = = .
x2
− 2x + 1 (1 − x)2
n + 1 n
an is the coefficient of xn in A(x), or + = 2n + 1.
1 1
Page 10
we have
∞
X ∞
X
n
6an−1 x = 6x an−1 xn−1 = 6x(A(x) − a0 ),
n=2 n=2
∞
X X∞
9an−2 xn = 9x 2
an−2 xn−2 = 9x2 A(x) and
n=2 n=2
∞ ∞
X X 18x2
2 · 3n xn = 18x 2 n−2 n−2
3 x = .
n=2 n=2
1 − 3x
18x2
so A(x) = a0 + a1 x + 6x(A(x) − a0 ) − 9x2 A(x) + , or (1 − 6x + 9x2 )A(x) =
1 − 3x
18x2 18x2
a0 + a1 x − 6xa0 + = 1 − 6x + . Thus,
1 − 3x 1 − 3x
1 − 6x 18x2
A(x) = +
(1 − 3x)2 (1 − 3x)3
as before.
(g) an = 2nan−1 + 2n n!, a1 = 1, with and without generating functions. For the
generating function approach, use exponential generating functions.
The point of exponential generating functions is that they help the factor of n
Page 11
n 1
go away. That is, n!
= (n−1)!
Thus, we have
∞ ∞ ∞
X xn X X xn−1 2x
A(x) = 1 + 2an−1 + 2n xn = 1 + 2x an−1 + ,
n=1
(n − 1)! n=1 n=1
(n − 1)! 1 − 2x
2x 1 1
or A(x) = 1 + 2xA(x) + = 2xA(x) + , or A(x) = . The
1 − 2x 1 − 2x (1 − 2x)2
coefficient of xn in this expression is (n+1)2n , but we need n! times this number
giving an = n!(n + 1)2n = (n + 1)!2n .
Solution: This can probably be done with generating functions but the fol-
lowing is easier. If n ≥ 3 then an−1 = an−2 + 4an−3 + · · · + 4a0 and if
we subtract this from the original we have an − an−1 = an−1 + 3an−2 , or
an = 2an−1 + 3an−2 . Now we have a second order recurrence, but only from
n = 3 on. It has characteristic polynomial x2 − 2x − 3 = (x − 3)(x + 1). The
general solution has the form an = A3n + B(−1)n . We can’t plug a0 and a1
into this, we need a1 and a2 instead. We use the original recurrence to tell us
a2 = a1 + 4a0 = 14. Now 3A − B = 10, 9A + B = 14 so A = 2, B = −4. Our
solution is a0 = 1, an = 2 · 3n − 4(−1)n for n ≥ 1. As a check, when n = 3 we
have a3 = a2 + 4a1 + 4a0 = 14 + 40 + 4 = 58 and 2 · 33 − 4(−1)3 = 54 + 4 = 58.
Solution: This can be done fairly easily with generating functions because an
is almost a convolution (of the a’s and 2n ). We have
∞
X ∞
X ∞
X
n
A(x) = an x = a0 + an x = a0 + (an−1 +2an−2 +4an−3 +· · ·+2n−1 a0 )xn .
n
Page 12
1 − 2x
Thus, A(x) = , and an is the coefficient of xn in this. That coefficient is
1 − 3x
1 when n = 0 and 3n − 2 · 3n−1 = 3n−1 when n ≥ 1. So for n ≥ 1, an = 3n−1 .
Easier is to use the same trick as in part (a). We can’t just subtract an−1 , in this
case. When n ≥ 2 we can write an−1 = an−2 +2an−3 +· · ·+2n−2 a0 . If we multiply
this by 2 and subtract from the original recurrence we have an − 2an−1 = an−1 ,
or an = 3an−1 . Noting that a1 = 1, ti follows that an = 3n−1 for all n ≥ 1.
Finally, I will mention that on this problem, it is easy to guess the answer. We
have a0 = 1, a1 = a0 = 1, a2 = a1 + 2a0 = 3, a3 = a2 + 2a1 + 4a0 = 9. If we
guess a0 = 1, an = 3n−1 for n ≥ 1 then
3n−2 − 32 2n−2
an = 2 + 2n−1 = 3n−1 − 2n−1 + 2n−1 = 3n−1 ,
1− 3
Page 13