0% found this document useful (0 votes)
22 views

cgt-53-70 (3)

The document discusses generating functions, particularly in the context of counting problems and combinatorial mathematics. It introduces the concept of generating functions as a way to represent sequences and provides examples, including Newton's Binomial Theorem and various counting problems using generating functions. Additionally, it touches on exponential generating functions and their applications in permutations and other combinatorial scenarios.

Uploaded by

taiyamxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

cgt-53-70 (3)

The document discusses generating functions, particularly in the context of counting problems and combinatorial mathematics. It introduces the concept of generating functions as a way to represent sequences and provides examples, including Newton's Binomial Theorem and various counting problems using generating functions. Additionally, it touches on exponential generating functions and their applications in permutations and other combinatorial scenarios.

Uploaded by

taiyamxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

3

Generating Functions

As we have seen, a typical counting problem includes one or more parameters, which of
( )
course show up in the solutions, such as nk , P (n, k), or the number of derangements of
[n]. Also recall that
∑n ( )
n n k
(x + 1) = x .
k
k=0
(n)
This provides the values k as coefficients of the Maclaurin expansion of a function. This
turns out to be a useful idea.

DEFINITION 3.0.1 f (x) is a generating function for the sequence a0 , a1 , a2 , . . . if




f (x) = ai xi .
i=0

Sometimes a generating function can be used to find a formula for its coefficients, but
if not, it gives a way to generate them. Generating functions can also be useful in proving
facts about the coefficients.

3.1 Newton's Binomial Theorem


Recall that ( )
n n! n(n − 1)(n − 2) · · · (n − k + 1)
= = .
k k! (n − k)! k!

53
54 Chapter 3 Generating Functions

The expression on the right makes sense even if n is not a non-negative integer, so long as
k is a non-negative integer, and we therefore define
( )
r r(r − 1)(r − 2) · · · (r − k + 1)
=
k k!
when r is a real number. For example,
( ) ( )
1/2 (1/2)(−1/2)(−3/2)(−5/2) −5 −2 (−2)(−3)(−4)
= = and = = −4.
4 4! 128 3 3!
These generalized binomial coefficients share some important properties of the usual
binomial coefficients, most notably that
( ) ( ) ( )
r r−1 r−1
= + . (3.1.1)
k k−1 k
Then remarkably:

THEOREM 3.1.1 Newton’s Binomial Theorem For any real number r that is
not a non-negative integer,
∑∞ ( )
r r i
(x + 1) = x
i=0
i
when −1 < x < 1.
Proof. It is not hard to see that the series is the Maclaurin series for (x + 1)r , and that
the series converges when −1 < x < 1. It is rather more difficult to prove that the series is
equal to (x + 1)r ; the proof may be found in many introductory real analysis books.

EXAMPLE 3.1.2 Expand the function (1 − x)−n when n is a positive integer.


We first consider (x + 1)−n ; we can simplify the binomial coefficients:
(−n)(−n − 1)(−n − 2) · · · (−n − i + 1) (n)(n + 1) · · · (n + i − 1)
= (−1)i
i! i!
(n + i − 1)!
= (−1)i
i! (n − 1)!
( ) ( )
i n+i−1 i n+i−1
= (−1) = (−1) .
i n−1
Thus ( )
∑∞ ∑∞ ( )
−n i n+i−1 i n+i−1
(x + 1) = (−1) x = (−x)i .
i=0
n − 1 i=0
n − 1
Now replacing x by −x gives
∑∞ ( )
−n n+i−1 i
(1 − x) = x.
i=0
n − 1
−n
( )
So (1 − x) n−1 , the number of submultisets of {∞ ·
is the generating function for n+i−1
1, ∞ · 2, . . . , ∞ · n} of size i.
3.1 Newton’s Binomial Theorem 55

In many cases it is possible to directly construct the generating function whose coeffi-
cients solve a counting problem.

EXAMPLE 3.1.3 Find the number of solutions to x1 + x2 + x3 + x4 = 17, where


0 ≤ x1 ≤ 2, 0 ≤ x2 ≤ 5, 0 ≤ x3 ≤ 5, 2 ≤ x4 ≤ 6.
We can of course solve this problem using the inclusion-exclusion formula, but we use
generating functions. Consider the function

(1 + x + x2 )(1 + x + x2 + x3 + x4 + x5 )(1 + x + x2 + x3 + x4 + x5 )(x2 + x3 + x4 + x5 + x6 ).

We can multiply this out by choosing one term from each factor in all possible ways. If
we then collect like terms, the coefficient of xk will be the number of ways to choose one
term from each factor so that the exponents of the terms add up to k. This is precisely the
number of solutions to x1 + x2 + x3 + x4 = k, where 0 ≤ x1 ≤ 2, 0 ≤ x2 ≤ 5, 0 ≤ x3 ≤ 5,
2 ≤ x4 ≤ 6. Thus, the answer to the problem is the coefficient of x17 . With the help of a
computer algebra system we get

(1 + x + x2 )(1 + x + x2 + x3 + x4 + x5 )2 (x2 + x3 + x4 + x5 + x6 )
= x18 + 4x17 + 10x16 + 19x15 + 31x14 + 45x13 + 58x12 + 67x11 + 70x10
+ 67x9 + 58x8 + 45x7 + 31x6 + 19x5 + 10x4 + 4x3 + x2 ,

so the answer is 4.

EXAMPLE 3.1.4 Find the generating function for the number of solutions to x1 +
x2 + x3 + x4 = k, where 0 ≤ x1 ≤ ∞, 0 ≤ x2 ≤ 5, 0 ≤ x3 ≤ 5, 2 ≤ x4 ≤ 6.
This is just like the previous example except that x1 is not bounded above. The
generating function is thus

f (x) = (1 + x + x2 + · · ·)(1 + x + x2 + x3 + x4 + x5 )2 (x2 + x3 + x4 + x5 + x6 )


= (1 − x)−1 (1 + x + x2 + x3 + x4 + x5 )2 (x2 + x3 + x4 + x5 + x6 )
(1 + x + x2 + x3 + x4 + x5 )2 (x2 + x3 + x4 + x5 + x6 )
= .
1−x
Note that (1 − x)−1 = (1 + x + x2 + · · ·) is the familiar geometric series from calculus;
alternately, we could use example 3.1.2. Unlike the function in the previous example, this
function has an infinite expansion:

f (x) = x2 + 4x3 + 10x4 + 20x5 + 35x6 + 55x7 + 78x8


+ 102x9 + 125x10 + 145x11 + 160x12 + 170x13 + 176x14
+ 179x15 + 180x16 + 180x17 + 180x18 + 180x19 + 180x20 + · · · .

You can see how to do this in Sage.


56 Chapter 3 Generating Functions

EXAMPLE 3.1.5 Find a generating function for the number of submultisets of {∞ ·


a, ∞·b, ∞·c} in which there are an odd number of as, an even number of bs, and any number
of cs. As we have seen, this is the same as the number of solutions to x1 + x2 + x3 = n in
which x1 is odd, x2 is even, and x3 is unrestricted. The generating function is therefore

(x + x3 + x5 + · · ·)(1 + x2 + x4 + · · ·)(1 + x + x2 + x3 + · · ·)
1
= x(1 + (x2 ) + (x2 )2 + (x2 )3 + · · ·)(1 + (x2 ) + (x2 )2 + (x2 )3 + · · ·)
1−x
x
= .
(1 − x2 )2 (1 − x)

Exercises 3.1.
For some of these exercises, you may want to use the sage applet above, in example 3.1.4, or your
favorite computer algebra system.
( ) (r−1) (r−1)
1. Prove that kr = k−1 + k .
∑ (r) i
2. Show that the Maclaurin series for (x + 1)r is ∞ i=0 i x .
3. Concerning example 3.1.4, show that all coefficients beginning with x16 are 180.
4. Use a generating function to find the number of solutions to x1 + x2 + x3 + x4 = 14, where
0 ≤ x1 ≤ 3, 2 ≤ x2 ≤ 5, 0 ≤ x3 ≤ 5, 4 ≤ x4 ≤ 6.
5. Find the generating function for the number of solutions to x1 + x2 + x3 + x4 = k, where
0 ≤ x1 ≤ ∞, 3 ≤ x2 ≤ ∞, 2 ≤ x3 ≤ 5, 1 ≤ x4 ≤ 5.
6. Find a generating function for the number of non-negative integer solutions to 3x + 2y + 7z =
n.
7. Suppose we have a large supply of red, white, and blue balloons. How many different bunches
of 10 balloons are there, if each bunch must have at least one balloon of each color and the
number of white balloons must be even?
8. Use generating functions to show that every positive integer can be written in exactly one
way as a sum of distinct powers of 2.
9. Suppose we have a large supply of blue and green candles, and one gold candle. How many
collections of n candles are there in which the number of blue candles is even, the number of
green candles is any number, and the number of gold candles is at most one?

3.2 Exponential Generating Functions


There are other ways that a function might be said to generate a sequence, other than as
what we have called a generating function. For example,

∑∞
x 1 n
e = x
n=0
n!
3.2 Exponential Generating Functions 57

is the generating function for the sequence 1, 1, 12 , 3!


1
, . . .. But if we write the sum as

∑ xn
x
e = 1· ,
n=0
n!

considering the n! to be part of the expression xn /n!, we might think of this same function
as generating the sequence 1, 1, 1, . . ., interpreting 1 as the coefficient of xn /n!. This is not
a very interesting sequence, of course, but this idea can often prove fruitful. If

∑ xn
f (x) = an ,
n=0
n!

we say that f (x) is the exponential generating function for a0 , a1 , a2 , . . ..

EXAMPLE 3.2.1 Find an exponential generating function for the number of permu-
tations with repetition of length n of the set {a, b, c}, in which there are an odd number
of a s, an even number of b s, and any number of c s.
For a fixed n and fixed numbers of the letters, we already know how to do this. For
( )
example, if we have 3 a s, 4 b s, and 2 c s, there are 3 49 2 such permutations. Now consider
the following function:
∑ ∞ ∞ ∞
x2i+1 ∑ x2i ∑ xi
.
i=0
(2i + 1)! i=0
(2i)! i=0
i!

What is the coefficient of x9 /9! in this product? One way to get an x9 term is
( ) 9
x3 x4 x2 9! x9 9 x
= = .
3! 4! 2! 3! 4! 2! 9! 3 4 2 9!

That is, this one term counts the number of permutations in which there are 3 a s, 4 b s,
and 2 c s. The ultimate coefficient of x9 /9! will be the sum of many such terms, counting
the contributions of all possible choices of an odd number of a s, an even number of b s,
and any number of c s.
∑∞
xi
Now we notice that = ex , and that the other two sums are closely related to
i=0
i!
this. A little thought leads to

∑ ∞
∑ ∞

xi (−x)i xi + (−x)i
ex + e−x = + = .
i=0
i! i=0
i! i=0
i!

Now xi + (−x)i is 2xi when i is even, and 0 when i is odd. Thus

∑∞
x −x 2x2i
e +e = ,
i=0
(2i)!
58 Chapter 3 Generating Functions

so that
∑∞
x2i ex + e−x
= .
i=0
(2i)! 2

A similar manipulation shows that

∑∞
x2i+1 ex − e−x
= .
i=0
(2i + 1)! 2

Thus, the generating function we seek is

ex − e−x ex + e−x x 1 1
e = (ex − e−x )(ex + e−x )ex = (e3x − e−x ).
2 2 4 4
Notice the similarity to example 3.1.5.

Exercises 3.2.
1. Find the coefficient of x9 /9! in the function of example 3.2.1. You may use Sage or a similar
program.
2. Find an exponential generating function for the number of permutations with repetition of
length n of the set {a, b, c}, in which there are an odd number of a s, an even number of b s,
and an even number of c s.
3. Find an exponential generating function for the number of permutations with repetition of
length n of the set {a, b, c}, in which the number of a s is even and at least 2, the number of
b s is even and at most 6, and the number of c s is at least 3.
4. In how many ways can we paint the 10 rooms of a hotel if at most three can be painted red,
at most 2 painted green, at most 1 painted white, and any number can be painted blue or
orange? (The rooms are different, so order matters.)
5. Recall from section 1.4 that the Bell numbers Bn count all of the partitions of {1, 2, . . . , n}.
∑∞
xn
Let f (x) = Bn · , and note that
n=0
n!
( n ( ) )

∑∞
xn−1 ∑∞
xn ∑∞ ∑ n xn
f (x) = Bn = Bn+1 = Bn−k ,
n=1
(n − 1)! n=0
n! n=0
k n!
k=0

using the recurrence relation 1.4.1 for Bn+1 from section 1.4. Now it is possible to write this
as a product of two infinite series:
(∞ )( ∞ )

∑ xn ∑
f (x) = Bn · an xn
= f (x)g(x).
n=0
n! n=0

Find an expression for an that makes this true, which will tell you what g(x) is, then solve
the differential equation for f (x), the exponential generating function for the Bell numbers.
From section 1.4, the first few Bell numbers are 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147,
115975, 678570, 4213597, 27644437. You can use Sage to check your answer.
3.3 Partitions of Integers 59

3.3 Partitions of Integers


DEFINITION 3.3.1 A partition of a positive integer n is a multiset of positive integers
that sum to n. We denote the number of partitions of n by pn .
Typically a partition is written as a sum, not explicitly as a multiset. Using the usual
convention that an empty sum is 0, we say that p0 = 1.

EXAMPLE 3.3.2 The partitions of 5 are


5
4+1
3+2
3+1+1
2+2+1
2+1+1+1
1 + 1 + 1 + 1 + 1.
Thus p5 = 7.
There is no simple formula for pn , but it is not hard to find a generating function
for them. As with some previous examples, we seek a product of factors so that when
the factors are multiplied out, the coefficient of xn is pn . We would like each xn term
to represent a single partition, before like terms are collected. A partition is uniquely
described by the number of 1s, number of 2s, and so on, that is, by the repetition numbers
of the multiset. We devote one factor to each integer:
∞ ∑
∏ ∞
(1 + x + x2 + x3 + · · ·)(1 + x2 + x4 + x6 + · · ·) · · · (1 + xk + x2k + x3k + · · ·) · · · = xik .
k=1 i=0

When this product is expanded, we pick one term from each factor in all possible ways, with
the further condition that we only pick a finite number of “non-1” terms. For example,
if we pick x3 from the first factor, x3 from the third factor, x15 from the fifth factor,
and 1s from all other factors, we get x21 . In the context of the product, this represents
3 · 1 + 1 · 3 + 3 · 5, corresponding to the partition 1 + 1 + 1 + 3 + 5 + 5 + 5, that is, three
1s, one 3, and three 5s. Each factor is a geometric series; the kth factor is
1
1 + xk + (xk )2 + (xk )3 + · · · = ,
1 − xk
so the generating function can be written

∏ 1
.
1 − xk
k=1
60 Chapter 3 Generating Functions

Note that if we are interested in some particular pn , we do not need the entire infinite
product, or even any complete factor, since no partition of n can use any integer greater
than n, and also cannot use more than n/k copies of k.

EXAMPLE 3.3.3 Find p8 .


We expand

(1 + x + x2 + x3 + x4 + x5 + x6 + x7 + x8 )(1 + x2 + x4 + x6 + x8 )(1 + x3 + x6 )
(1 + x4 + x8 )(1 + x5 )(1 + x6 )(1 + x7 )(1 + x8 )
= 1 + x + 2x2 + 3x3 + 5x4 + 7x5 + 11x6 + 15x7 + 22x8 + · · · + x56 ,

so p8 = 22. Note that all of the coefficients prior to this are also correct, but the following
coefficients are not necessarily the corresponding partition numbers.
Partitions of integers have some interesting properties. Let pd (n) be the number of
partitions of n into distinct parts; let po (n) be the number of partitions into odd parts.

EXAMPLE 3.3.4 For n = 6, the partitions into distinct parts are

6, 5 + 1, 4 + 2, 3 + 2 + 1,

so pd (6) = 4, and the partitions into odd parts are

5 + 1, 3 + 3, 3 + 1 + 1 + 1, 1 + 1 + 1 + 1 + 1 + 1,

so po (6) = 4.
In fact, for every n, pd (n) = po (n), and we can see this by manipulating generating
functions. The generating function for pd (n) is


fd (x) = (1 + x)(1 + x )(1 + x ) · · · =
2 3
(1 + xi ).
i=1

The generating function for po (n) is



∏ 1
fo (x) = (1 + x + x + x + · · ·)(1 + x + x + x + · · ·) · · · =
2 3 3 6 9
.
i=0
1 − x2i+1

We can write
1 − x2 1 − x4 1 − x6
fd (x) = · · ···
1 − x 1 − x2 1 − x3
and notice that every numerator is eventually canceled by a denominator, leaving only the
denominators containing odd powers of x, so fd (x) = fo (x).
3.3 Partitions of Integers 61

We can also use a recurrence relation to find the partition numbers, though in a
somewhat less direct way than the binomial coefficients or the Bell numbers. Let pk (n) be
the number of partitions of n into exactly k parts. We will find a recurrence relation to
compute the pk (n), and then
∑n
pn = pk (n).
k=1

Now consider the partitions of n into k parts. Some of these partitions contain no 1s, like
3 + 3 + 4 + 6, a partition of 16 into 4 parts. Subtracting 1 from each part, we get a partition
of n − k into k parts; for the example, this is 2 + 2 + 3 + 5. The remaining partitions of
n into k parts contain a 1. If we remove the 1, we are left with a partition of n − 1 into
k − 1 parts. This gives us a 1–1 correspondence between the partitions of n into k parts,
and the partitions of n − k into k parts together with the partitions of n − 1 into k − 1
parts, so pk (n) = pk (n − k) + pk−1 (n − 1).
Using this recurrence we can build a triangle containing the pk (n), and the row sums of
this triangle give the partition numbers. For all n, p1 (n) = 1, which gives the first column
of the triangle, after which the recurrence applies. Also, note that pk (n) = 0 when k > n
and we let pk (0) = 0; these are needed in some cases to compute the pk (n − k) term of
the recurrence. Here are the first few rows of the triangle; at the left are the row numbers,
and at the right are the row sums, that is, the partition numbers. For the last row, each
entry is the sum of the like-colored numbers in the previous rows. Note that beginning
with p4 (7) = 3 in the last row, pk (7) = pk−1 (6), as pk (7 − k) = 0.
1 1 0
1
2 1 1 0 2
3 1 1 1 0 3
4 1 2 1 1 5
5 1 2 2 1 1 7
6 1 3 3 2 1 1 11
7 1 3 4 3 2 1 1 15

Yet another sometimes useful way to think of a partition is with a Ferrers diagram.
Each integer in the partition is represented by a row of dots, and the rows are ordered
from longest on the top to shortest at the bottom. For example, the partition 3 + 3 + 4 + 5
would be represented by
• • • • •
• • • •
• • •
• • •

The conjugate of a partition is the one corresponding to the Ferrers diagram produced
by flipping the diagram for the original partition across the main diagonal, thus turning
62 Chapter 3 Generating Functions

rows into columns and vice versa. For the diagram above, the conjugate is
• • • •
• • • •
• • • •
• •

with corresponding partition 1 + 2 + 4 + 4 + 4. This concept can occasionally make facts


about partitions easier to see than otherwise. Here is a classic example: the number of
partitions of n with largest part k is the same as the number of partitions into k parts,
pk (n). The action of conjugation takes every partition of one type into a partition of the
other: the conjugate of a partition into k parts is a partition with largest part k and vice
versa. This establishes a 1–1 correspondence between partitions into k parts and partitions
with largest part k.

Exercises 3.3.
1. Use generating functions to find p15 .
2. Find the generating function for the number of partitions of an integer into distinct odd
parts. Find the number of such partitions of 20.
3. Find the generating function for the number of partitions of an integer into distinct even
parts. Find the number of such partitions of 30.
4. Find the number of partitions of 25 into odd parts.
5. Find the generating function for the number of partitions of an integer into k parts; that is,
the coefficient of xn is the number of partitions of n into k parts.
6. Complete row 8 of the table for the pk (n), and verify that the row sum is 22, as we saw in
example 3.3.3.
7. A partition of n is self-conjugate if its Ferrers diagram is symmetric around the main diagonal,
so that its conjugate is itself. Show that the number of self-conjugate partitions of n is equal
to the number of partitions of n into distinct odd parts.

3.4 Recurrence Relations


A recurrence relation defines a sequence {ai }∞ i=0 by expressing a typical term an in
terms of earlier terms, ai for i < n. For example, the famous Fibonacci sequence is defined
by
F0 = 0, F1 = 1, Fn = Fn−1 + Fn−2 .

Note that some initial values must be specified for the recurrence relation to define a unique
sequence.
The starting index for the sequence need not be zero if it doesn’t make sense or some
other starting index is more convenient. We saw two recurrence relations for the number
3.4 Recurrence Relations 63

of derangements of [n]:
D1 = 0, Dn = nDn−1 + (−1)n .

and
D1 = 0, D2 = 1, Dn = (n − 1)(Dn−1 + Dn−2 ).

To “solve” a recurrence relation means to find a formula for an . There are a variety
of methods for solving recurrence relations, with various advantages and disadvantages in
particular cases. One method that works for some recurrence relations involves generating
functions. The idea is simple, if the execution is not always: Let


f (x) = ai xi ,
i=0

that is, let f (x) be the generating function for {ai }∞


i=0 . We now try to manipulate f (x),
using the recurrence relation, until we can solve for f (x) explicitly. Finally, we hope that
we can find a formula for the coefficients from the formula for f (x).

EXAMPLE 3.4.1 Solve F0 = 0, F1 = 1, Fn = Fn−1 + Fn−2 .


Let


f (x) = Fi xi
i=0

and note that



∑ ∞

xf (x) = Fi xi+1 = Fi−1 xi .
i=0 i=1

To get the second sum we have simply “re-indexed” so that the index value gives the
exponent on x, just as in the series for f (x). Likewise,

∑ ∞

x2 f (x) = Fi xi+2 = Fi−2 xi .
i=0 i=2

In somewhat more suggestive form, we have

f (x) = x + F2 x2 + F3 x3 + F4 x4 + · · ·
xf (x) = x2 + F2 x3 + F3 x4 + · · ·
x2 f (x) = x3 + F2 x4 + · · ·

and combining the three equations we get

f (x) − xf (x) − x2 f (x) = x + (F2 − 1)x2 + (F3 − F2 − 1)x3 + (F4 − F3 − F2 )x4 + · · ·


64 Chapter 3 Generating Functions

or in more compact form



∑ ∞
∑ ∞

f (x) − xf (x) − x f (x) =
2
Fi x −
i
Fi−1 x − i
Fi−2 xi
i=0 i=1 i=2


=x+ (Fi − Fi−1 − Fi−2 )xi
i=2
∑∞
=x+ 0 · xi
i=2
= x,

recalling that F0 = 0 and F1 = 1. Now

x −x
f (x) = = 2 .
1−x−x 2 x +x−1

If we can find an explicit representation for the series for this function, we will have solved
the recurrence relation. Here is where things could go wrong, but in this case it works out.
Let a and b be the roots of x2 + x − 1; using the quadratic formula, we get
√ √
−1 + 5 −1 − 5
a= ,b = .
2 2
Borrowing a technique from calculus, we write

−x A B
= + .
x2 +x−1 x−a x−b

Solving for A and B gives √ √


1− 5 −1 − 5
A= √ ,B = √ .
2 5 2 5
Then
−x A 1 B 1
=− − .
x2 +x−1 a 1 − x/a b 1 − x/b
From calculus we know that

∑ ∞ ∑ ∞
1 1
= (1/a)i xi and = (1/b)i xi .
1 − x/a i=0
1 − x/b i=0

Finally, this means the coefficient of xi in the series for f (x) is

A B
Fi = − (1/a)i − (1/b)i .
a b
3.4 Recurrence Relations 65

Simplifying gives √ √
1 ( 1 + 5 )i 1 ( 1 − 5 )i
Fi = √ −√ .
5 2 5 2

Here’s an interesting feature of this expression: since |(1 − 5)/2| < 1, the limit of

((1 − 5)/2)i as i goes to infinity is 0. So when i is large enough,
( √ ))
(
1 1+ 5 i
Fi = round √ ,
5 2

that is, the first term rounded to the nearest integer. As it turns out, this is true starting
with i = 0.
You can see how to do the entire solution in Sage.
We can also use this expression for Fn to compute limn→∞ Fn /Fn−1 .
(
√ )n (√ )n
√1 1+ 5
− √1 1− 5 √
Fn 5 2 5 2 1+ 5
lim
n→∞ Fn−1
= lim ( √ )n−1 ( √ )n−1 = .
n→∞ 1 2

5
1+ 5
2 − √1
5
1− 5
2

This is the so-called “golden ratio”.

Exercises 3.4.
1. Find the generating function for the solutions to hn = 4hn−1 − 3hn−2 , h0 = 2, h1 = 5, and
use it to find a formula for hn .
2. Find the generating function for the solutions to hn = 3hn−1 + 4hn−2 , h0 = h1 = 1, and use
it to find a formula for hn .
3. Find the generating function for the solutions to hn = 2hn−1 + 3n , h0 = 0, and use it to find
a formula for hn .
4. Find the generating function for the solutions to hn = 4hn−2 , h0 = 0, h1 = 1, and use it to
find a formula for hn . (It is easy to discover this formula directly; the point here is to see
that the generating function approach gives the correct answer.)
5. Find the generating function for the solutions to hn = hn−1 + hn−2 , h0 = 1, h1 = 3, and use
it to find a formula for hn .
6. Find the generating function for the solutions to hn = 9hn−1 − 26hn−2 + 24hn−3 , h0 = 0,
h1 = 1, h2 = −1, and use it to find a formula for hn .
7. Find the generating function for the solutions to hn = 3hn−1 + 4hn−2 , h0 = 0, h1 = 1, and
use it to find a formula for hn .
8. Find a recursion for the number of ways to place flags on an n foot pole, where we have red
flags that are 2 feet high, blue flags that are 1 foot high, and yellow flags that are 1 foot
high; the heights of the flags must add up to n. Solve the recursion.
9. In Fibonacci’s original problem, a farmer started with one (newborn) pair of rabbits at month
0. After each pair of rabbits was one month old, they produced another pair each month
in perpetuity. Thus, after 1 month, he had the original pair, after two months 2 pairs,
66 Chapter 3 Generating Functions

three months, 3 pairs, four months, 5 pairs, etc. The number of pairs of rabbits satisfies
hn = hn−1 + hn−2 , h0 = h1 = 1. (Note that this is slightly different than our definition, in
which h0 = 0.)
Suppose instead that each mature pair gives birth to two pairs of rabbits. The sequence
for the number of pairs of rabbits now starts out h0 = 1, h1 = 1, h2 = 3, h3 = 5, h4 = 11.
Set up and solve a recurrence relation for the number of pairs of rabbits. Show also that the
sequence statisfies hn = 2hn−1 + (−1)n .
10. Explain why
( √
)n ( √
)n
√1 1+ 5
2
− √1 1− 5
2

Fn 5 5 1+ 5
lim = lim ( √
)n−1 ( √
)n−1 = .
n→∞ Fn−1 n→∞ 2
√1
5
1+ 5
2
− √1
5
1− 5
2

3.5 Catalan Numbers


A rooted binary tree is a type of graph that is particularly of interest in some areas
of computer science. A typical rooted binary tree is shown in figure 3.5.1. The root is
the topmost vertex. The vertices below a vertex and connected to it by an edge are the
children of the vertex. It is a binary tree because all vertices have 0, 1, or 2 children. How
many different rooted binary trees are there with n vertices?

• •

• • •

•. •

Figure 3.5.1 A rooted binary tree.

Let us denote this number by Cn ; these are the Catalan numbers. For convenience,
we allow a rooted binary tree to be empty, and let C0 = 1. Then it is easy to see that
C1 = 1 and C2 = 2, and not hard to see that C3 = 5. Notice that any rooted binary tree
on at least one vertex can be viewed as two (possibly empty) binary trees joined into a
new tree by introducing a new root vertex and making the children of this root the two
roots of the original trees; see figure 3.5.2. (To make the empty tree a child of the new
vertex, simply do nothing, that is, omit the corresponding child.)
Thus, to make all possible binary trees with n vertices, we start with a root vertex, and
then for its two children insert rooted binary trees on k and l vertices, with k + l = n − 1,
3.5 Catalan Numbers 67

• + • = • •

• • • • • •

•. • • •

Figure 3.5.2 Producing a new tree from smaller trees.

for all possible choices of the smaller trees. Now we can write


n−1
Cn = Ci Cn−i−1 .
i=0

For example, since we know that C0 = C1 = 1 and C2 = 2,

C3 = C0 C2 + C1 C1 + C2 C0 = 1 · 2 + 1 · 1 + 2 · 1 = 5,

as mentioned above. Once we know the trees on 0, 1, and 2 vertices, we can combine them
in all possible ways to list the trees on 3 vertices, as shown in figure 3.5.3. Note that the
first two trees have no left child, since the only tree on 0 vertices is empty, and likewise
the last two have no right child.

• • • • •

• • • • • •

.• • • •

Figure 3.5.3 The 3-vertex binary rooted trees.

∑∞ i
Now we use a generating function to find a formula for Cn . Let f = i=0 Ci x .
∑ n
Now consider f 2 : the coefficient of the term xn in the expansion of f 2 is i=0 Ci Cn−i ,
corresponding to all possible ways to multiply terms of f to get an xn term:

C0 · Cn xn + C1 x · Cn−1 xn−1 + C2 x2 · Cn−2 xn−2 + · · · + Cn xn · C0 .


∑∞
Now we recognize this as precisely the sum that gives Cn+1 , so f 2 = n=0 Cn+1 xn . If we
multiply this by x and add 1 (which is C0 ) we get exactly f again, that is, xf 2 + 1 = f or
xf 2 − f + 1 = 0; here 0 is the zero function, that is, xf 2 − f + 1 is 0 for all x. Using the
68 Chapter 3 Generating Functions

quadratic formula, √

1 − 4x
f= ,
2x
as long as x ̸= 0. It is not hard to see that as x approaches 0,

1+ 1 − 4x
2x
goes to infinity while √
1− 1 − 4x
2x
goes to 1. Since we know f (0) = C0 = 1, this is the f we want.
Now by Newton’s Binomial Theorem 3.1.1, we can expand

∑∞ ( )
√ 1/2
1 − 4x = (1 + (−4x)) 1/2
= (−4x)n .
n=0
n

Then
√ ∞ ( ) ∞ ( )
1− 1 − 4x ∑ 1 1/2 ∑ 1 1/2
= − n n−1
(−4) x = − (−4)n+1 xn .
2x n=1
2 n n=0
2 n + 1

( 1/2 )
Expanding the binomial coefficient n+1 and reorganizing the expression, we discover that
( ) ( )
1 1/2 1 2n
Cn = − (−4) n+1
= .
2 n+1 n+1 n

In exercise 7 in section 1.2, we saw that the number of properly matched sequences of
( ) ( 2n )
parentheses of length 2n is 2n n − n+1 , and called this Cn . It is not difficult to see that

( ) ( ) ( )
2n 2n 1 2n
− = ,
n n+1 n+1 n

so the formulas are in agreement.


Temporarily let An be the number of properly matched sequences of parentheses of
( ) ( 2n )
length 2n, so from the exercise we know An = 2nn − n+1 . It is possible to see directly
that A0 = A1 = 1 and that the numbers An satisfy the same recurrence relation as do the
Cn , which implies that An = Cn , without manipulating the generating function.
There are many counting problems whose answers turns out to be the Catalan numbers.
Enumerative Combinatorics: Volume 2, by Richard Stanley, contains a large number of
examples.
3.5 Catalan Numbers 69

Exercises 3.5.
1. Show that ( ) ( ) ( )
2n 2n 1 2n
− = .
n n+1 n+1 n

2. Find a simple expression f (n) so that Cn+1 = f (n)Cn . Use this to compute C1 , . . . , C6 from
C0 .
3. Show that if An is the number of properly matched sequences of parentheses of length 2n,
then

n−1
An = Ai An−i−1 .
i=0

Do this in the same style that we used for the number of rooted binary trees: Given all the
sequences of shorter length, explain how to combine them to produce the sequences of length
2n, in such a way that the sum clearly counts the number of sequences. Hint: Prove the
following lemma: If s is a properly matched sequence of parentheses of length 2n, s may
be written uniquely in the form (s1 )s2 , where s1 and s2 are properly matched sequences of
parentheses whose lengths add to 2n−2. For example, (())() = ([()])[()] and ()(()) = ([ ])[(())],
with the sequences s1 and s2 indicated by [ ]. Note that s1 and s2 are allowed to be empty
sequences, with length 0.
4. Consider a “staircase” as shown below. A path from A to B consists of a sequence of edges
starting at A, ending at B, and proceeding only up or right; all paths are of length 6. One
such path is indicated by arrows. The staircase shown is a “3 × 3” staircase. How many
paths are there in an n × n staircase?

.....
B
..........
..
...
.
..............................
... .. ......
... . ...
... ..
... ...
. . ..
.....................................................................
.
. .
...... ..
. ...
..... ... ..
... ... ...
... .
. .
..
......................... ..................................................
. ...
.. . .
A
5. A convex polygon with n ≥ 3 sides can be divided into triangles by inserting n − 3 non-
intersecting diagonals. In how many different ways can this be done? The possibilities for
n = 5 are shown.

. . . . .

6. A partition of a set S is ∪ a collection of non-empty subsets Ai ⊆ S, 1 ≤ i ≤ k (the parts of


the partition), such that ki=1 Ai = S and for every i ̸= j, Ai ∩ Aj = ∅. For example, one
partition of {1, 2, 3, 4, 5} is {{1, 3}, {4}, {2, 5}}.
Suppose the integers 1, 2, . . . , n are arranged on a circle, in order around the circle. A
partition of {1, 2, . . . , n} is a non-crossing partition if it satisfies this additional property:
If w and x are in some part Ai , and y and z are in a different part Aj , then the line joining
w to x does not cross the line joining y to z. The partition above, {1, 3}, {4}, {2, 5}, is not
a non-crossing partition, as the the line 1–3 crosses the line 2–5.
70 Chapter 3 Generating Functions

Find the number of non-crossing partitions of {1, 2, . . . , n}.


Recall from section 1.4 that the Bell numbers count all of the partitions of {1, 2, . . . , n}.
Hence, this exercise gives us a lower bound on the total number of partitions.
7. Consider a set of 2n people sitting around a table. In how many ways can we arrange for
each person to shake hands with another person at the table such that no two handshakes
cross?

You might also like