You are on page 1of 4

CS201 : Discrete Mathematics

Semester II, 2010-11, CSE, IIT Kanpur


Lecture 9 (17 January)

1 Aim of the lecture


In continuation with the previous lecture, the aim of this lecture is to describe a general method of solving
recurrences using generating functions. Thereafter we illustrate the power of recurrence and generating
functions through an interesting and nontrivial counting problem. Designing recurrence involves analytical
and creative skills. However, designing just the recurrence wont solve every counting problem. This is
because we need tools for solving the recurrence. Here generating function proves to be very helpful. They
provide a very effective way to solve even very complicated looking recurrences.

2 Solving recurrences using generating functions


First we introduce some notation. Let G(x) be a generating function for a sequence hgn i. We shall use
{xi }G(x) as the coefficient of xi in G(x). It can be observed that gn = {xn }G(x). There are the following
steps for solving a recurrence using generating function.

1. Express the recurrence as a single equation/formula. Define a sequence hrn i corresponding to the
recurrence.

2. multiply rn by xn and sum it up for all integers n. Plug in the right hand side of the recurrence in
place of rn and do some manipulations. This gives the generating function R(x) for hrn i.

3. Usually R(x) = P (x)/Q(x) where P (x) and Q(x) are polynomials. One has to make use of partial
fractions and standard mathematical tools to express R(x) in such a form that you can easily extract
{xn }R(x) from it.

2.1 Some more examples of generating functions


In the previous lecture, we discussed many useful manipulations of a generating functions. We also discussed
generating functions for many well known sequences. We state a few more such examples below.

If G(x) is generating function for sequence hgn i, then xi0 G(x) is generating function for the sequence
hhn i where hn = gni0 for all n.

Generating function for the sequence h1, m


 m+1 m+2 m
1 , 2 , 3  , i is (1 x) . One can also infer that
m+1 m+2 m+3
the generating function for the sequence h1, 1 , 2 , 3 , i is (1 x)(m+1) . In general, it
will be useful to remember the following equality.

a X m + n
= abn xn
(1 bx)m+1 n
n0

1
2.2 Generating function for Fibonacci numbers
Recall that we derived the following recurrence for the Fibonacci numbers

fn = fn1 + fn2 + [n = 1]

Hence generating function F (x) for the sequence of Fibonacci numbers is obtained as follows.
X
F (x) = fn xn
n
X
= (fn1 + fn2 + [n = 1])xn
n
X X X
= fn1 xn + fn2 xn + [n = 1]xn
n n n
2
= xF (x) + x F (x) + x

Simplifying the above equality we get


x
F (x) =
1 x x2
Using partial fractions and elementary manipulations, the students are encouraged to show that
 
1 1 1
F (x) =
5 1 x 1 x

where = 1+2 5 and = 12 5 . The students are further asked to derive a closed form for nth Fibonacci
number from the above generating function.

2.3 Generating function for Catalan numbers


Let tn be the number of valid expressions consisting of n left parentheses and n right parentheses. Recall
that in the previous class, we derived the following recurrence
X
tn = ti tn1i + [n = 0]
i

Hence generating function T (x) for the sequence htn i can be obtained as follows.
X
T (x) = tn xn
n
!
X X X
= ti tn1i xn + [n = 0]xn
n i n
X X
n
= hn1 x + 1 where hm = ti tmi
n i
= xH(x) + 1

where H(x) is generating function for hhn i. Now observe that hhn i is convolution of htn i and htn i. Hence,
using the product rule mentioned in the previous lecture, H(x) = T (x)2 . Plugging this expression for H(x)
in the above equality and doing simple manipulations, we get

1 1 4x
T (x) =
2x
1 2n

It was left as a homework exercise to infer that {xn }T (x) is n+1 n .

2
3 Solving an interesting counting problem using recurrences and
generating functions
The counting problem of this lecture is defined for a fan which is an undirected unweighted graph defined as
follows. For any positive integer n, a fan of order n is a graph on n + 1 vertices and 2n 1 edges as follows.
The vertex set is {0, 1, ..., n}, and the edge set is {(0, i)|1 i n} {(i, i + 1)|1 i < n}.
Figure 1 gives a pictorial description of a fan of order 7.
0

1 2 3 4 5 6 7

Figure 1: Fan of order 7.

We address the following counting problem of fan graphs.


Problem 1 : What is number of spanning trees of a fan graph of order n ?

Let Sn be the set of spanning trees of fan graph of order n, and let tn = |Sn |. It is easy to observe that
t0 = 0 since the number of edges 2n 1 is -1 for n = 0, so fan graph of order 0 is not even defined, and so
t0 = 0. It is also easy to observe that t1 = 1.
we shall now devise two solutions for calculating tn for any n > 0. Both of them first devise a recurrence
for tn .

4 Solution 1
4.1 finding a recurrence of tn
This solution is based on the following key idea about the spanning tree.
Consider the vertex n. It has 2 edges incident on it. Certainly it must have at least one of these edges in
the spanning tree. This implies that if (0, n) is not in a spanning tree of Fn , then the other edge (n 1, n)
must be there in the spanning tree. This observation motivates us to partition the set Sn of spanning trees
into the following 2 categories.

1. The set of spanning trees in which (0, n) is not present :


As mentioned above, in this case, the edge (n 1, n) must be in the spanning tree. In fact the entire
spanning tree looks like a spanning tree of order n 1 with vertex n joined to the vertex n 1 in this
tree. Hence, the cardinality of this subset will be tn1 .
0

1 2 n
spanning tree from Sn1

Figure 2: The spanning tree with (0, n) edge missing.

3
2. The set of spanning trees in which (0, n) is present :
In this case, we cant say whether the edge (n 1, n) is or is not necessarily present in the spanning
tree. All such spanning trees can be categorized into the groups as shown in Figure 3. Hence the
0 0 0

1 2 n 1 2 n 1 2 n
spanning tree from Sn1
spanning tree from Sn2

Figure 3: The different categories of spanning trees in which (0, n) is present.

number of spanning trees of fan of order n where edge (0, n) is present is equal to

1 + t1 + ...tn2 + tn1

Combined together the above two cases, we get the following recurrence which holds for each value of n.
X
tn = ti + tn1 + [n > 0] (1)
i<n

4.2 solving the recurrence of tn


We use the following rules for solving the recurrence 1.
P
1. If hn = i<n gn , then H(x) = xG(x)/(1 x)

2. If hn = gn1 , then H(x) = xG(x)

3. If hn = [n > 0], then H(x) = x/(1 x)

Hence we get the following equation which governs the generating function T (x) for the sequence < tn >.

T (x) = xT (x)/(1 x) + xT (x) + x/(1 x)

Hence
x
T (x) =
1 3x + x2
As a homework, try to get an expression for tn from the above generating function.

You might also like