Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
73 views

Generating Functions

This document discusses generating functions and recurrence relations. It provides examples of using generating functions to solve linear recurrence relations. The key steps are: (1) deduce an equation for the generating function from the recurrence relation, (2) solve the equation to get an explicit expression for the generating function, (3) extract coefficients to get the terms of the sequence. Examples include the Fibonacci sequence, towers of Hanoi problem, and derangements.

Uploaded by

computerstudent
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Generating Functions

This document discusses generating functions and recurrence relations. It provides examples of using generating functions to solve linear recurrence relations. The key steps are: (1) deduce an equation for the generating function from the recurrence relation, (2) solve the equation to get an explicit expression for the generating function, (3) extract coefficients to get the terms of the sequence. Examples include the Fibonacci sequence, towers of Hanoi problem, and derangements.

Uploaded by

computerstudent
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

GENERATING FUNCTIONS AND RECURRENCE

RELATIONS
Generating Functions
Recurrence Relations
Suppose a
0
, a
1
, a
2
, . . . , a
n
, . . . ,is an innite sequence.
A recurrence recurrence relation is a set of equations
a
n
= f
n
(a
n1
, a
n2
, . . . , a
nk
). (1)
The whole sequence is determined by (1) and the values of
a
0
, a
1
, . . . , a
k1
.
Generating Functions
Linear Recurrence
Fibonacci Sequence
a
n
= a
n1
+ a
n2
n 2.
a
0
= a
1
= 1.
Generating Functions
b
n
= |B
n
| = |{x {a, b, c}
n
: aa does not occur in x}|.
b
1
= 3 : a b c
b
2
= 8 : ab ac ba bb bc ca cb cc
b
n
= 2b
n1
+ 2b
n2
n 2.
Generating Functions
b
n
= 2b
n1
+ 2b
n2
n 2.
Let
B
n
= B
(b)
n
B
(c)
n
B
(a)
n
where B
()
n
= {x B
n
: x
1
= } for = a, b, c.
Now |B
(b)
n
| = |B
(c)
n
| = |B
n1
|. The map f : B
(b)
n
B
n1
,
f (bx
2
x
3
. . . x
n
) = x
2
x
3
. . . x
n
is a bijection.
B
(a)
n
= {x B
n
: x
1
= a and x
2
= b or c}. The map
g : B
(a)
n
B
(b)
n1
B
(c)
n1
,
g(ax
2
x
3
. . . x
n
) = x
2
x
3
. . . x
n
is a bijection.
Hence, |B
(a)
n
| = 2|B
n2
|.
Generating Functions
Towers of Hanoi
Peg 1
Peg 2 Peg 3
H
n
is the minimum number of moves needed to shift
n rings from Peg 1 to Peg 2. One is not allowed to
place a larger ring on top of a smaller ring.
Generating Functions
Hn-1 moves
1 move
Hn-1 moves
H
n
= 2H
n1
+ 1
Generating Functions
A has n dollars. Everyday A buys one of a Bun (1 dollar), an
Ice-Cream (2 dollars) or a Pastry (2 dollars). How many ways
are there (sequences) for A to spend his money?
Ex. BBPIIPBI represents Day 1, buy Bun. Day 2, buy Bun etc..
u
n
= number of ways
= u
n,B
+ u
n,I
+ u
n,P
where u
n,B
is the number of ways where A buys a Bun on day
1 etc.
u
n,B
= u
n1
, u
n,I
= u
n,P
= u
n2
.
So
u
n
= u
n1
+ 2u
n2
,
and
u
0
= u
1
= 1.
Generating Functions
If a
0
, a
1
, . . . , a
n
is a sequence of real numbers then its
(ordinary) generating function a(x) is given by
a(x) = a
0
+ a
1
x + a
2
x
2
+ a
n
x
n
+
and we write
a
n
= [x
n
]a(x).
Generating Functions
a
n
= 1
a(x) =
1
1 x
= 1 + x + x
2
+ + x
n
+
a
n
= n + 1.
a(x) =
1
(1 x)
2
= 1 + 2x + 3x
2
+ + (n + 1)x
n
+
a
n
= n.
a(x) =
x
(1 x)
2
= x + 2x
2
+ 3x
3
+ + nx
n
+
Generating Functions
Generalised binomial theorem:
a
n
=
_

n
_
a(x) = (1 + x)

n=0
_

n
_
x
n
.
where
_

n
_
=
( 1)( 2) ( n + 1)
n!
.
a
n
=
_
m+n1
n
_
a(x) =
1
(1 x)
m
=

n=0
_
m
n
_
(x)
n
=

n=0
_
m + n 1
n
_
x
n
.
Generating Functions
General view.
Given a recurrence relation for the sequence (a
n
), we
(a) Deduce from it, an equation satised by the generating
function a(x) =

n
a
n
x
n
.
(b) Solve this equation to get an explicit expression for the
generating function.
(c) Extract the coefcient a
n
of x
n
from a(x), by expanding a(x)
as a power series.
Generating Functions
Solution of linear recurrences
a
n
6a
n1
+ 9a
n2
= 0 n 2.
a
0
= 1, a
1
= 9.

n=2
(a
n
6a
n1
+ 9a
n2
)x
n
= 0. (2)
Generating Functions

n=2
a
n
x
n
= a(x) a
0
a
1
x
= a(x) 1 9x.

n=2
6a
n1
x
n
= 6x

n=2
a
n1
x
n1
= 6x(a(x) a
0
)
= 6x(a(x) 1).

n=2
9a
n2
x
n
= 9x
2

n=2
a
n2
x
n2
= 9x
2
a(x).
Generating Functions
a(x) 1 9x 6x(a(x) 1) + 9x
2
a(x) = 0
or
a(x)(1 6x + 9x
2
) (1 + 3x) = 0.
a(x) =
1 + 3x
1 6x + 9x
2
=
1 + 3x
(1 3x)
2
=

n=0
(n + 1)3
n
x
n
+ 3x

n=0
(n + 1)3
n
x
n
=

n=0
(n + 1)3
n
x
n
+

n=0
n3
n
x
n
=

n=0
(2n + 1)3
n
x
n
.
a
n
= (2n + 1)3
n
.
Generating Functions
Fibonacci sequence:

n=2
(a
n
a
n1
a
n2
)x
n
= 0.

n=2
a
n
x
n

n=2
a
n1
x
n

n=2
a
n2
x
n
= 0.
(a(x) a
0
a
1
x) (x(a(x) a
0
)) x
2
a(x) = 0.
a(x) =
1
1 x x
2
.
Generating Functions
a(x) =
1
(
1
x)(
2
x)
=
1

1

2
_
1

1
x

1

2
x
_
=
1

1

2
_

1
1
1 x/
1


1
2
1 x/
2
_
where

1
=

5 + 1
2
and
2
=

5 1
2
are the 2 roots of
x
2
+ x 1 = 0.
Generating Functions
Therefore,
a(x) =

1
1

1

2

n=0

n
1
x
n


1
2

1

2

n=0

n
2
x
n
=

n=0

n1
1

n1
2

1

2
x
n
and so
a
n
=

n1
1

n1
2

1

2
=
1

5
_
_
_

5 + 1
2
_
n+1

_
1

5
2
_
n+1
_
_
.
Generating Functions
Inhomogeneous problem
a
n
3a
n1
= n
2
n 1.
a
0
= 1.

n=1
(a
n
3a
n1
)x
n
=

n=1
n
2
x
n

n=1
n
2
x
n
=

n=2
n(n 1)x
n
+

n=1
nx
n
=
2x
2
(1 x)
3
+
x
(1 x)
2
=
x + x
2
(1 x)
3

n=1
(a
n
3a
n1
)x
n
= a(x) 1 3xa(x)
= a(x)(1 3x) 1.
Generating Functions
a(x) =
x + x
2
(1 x)
3
(1 3x)
+
1
1 3x
=
A
1 x
+
B
(1 x)
2
+
C
(1 x)
3
+
D + 1
1 3x
where
x + x
2

= A(1 x)
2
(1 3x) + B(1 x)(1 3x)
+ C(1 3x) + D(1 x)
3
.
Then
A = 1/2, B = 0, C = 1, D = 3/2.
Generating Functions
So
a(x) =
1/2
1 x

1
(1 x)
3
+
5/2
1 3x
=
1
2

n=0
x
n

n=0
_
n + 2
2
_
x
n
+
5
2

n=0
3
n
x
n
So
a
n
=
1
2

_
n + 2
2
_
+
5
2
3
n
=
3
2

3n
2

n
2
2
+
5
2
3
n
.
Generating Functions
General case of linear recurrence
a
n
+ c
1
a
n1
+ + c
k
a
nk
= u
n
, n k.
u
0
, u
1
, . . . , u
k1
are given.

(a
n
+ c
1
a
n1
+ + c
k
a
nk
u
n
) x
n
= 0
It follows that for some polynomial r (x),
a(x) =
u(x) + r (x)
q(x)
where
q(x) = 1 + c
1
x + c
2
x
2
+ + c
k
x
k
=
k

i =1
(1
i
x)
and
1
,
2
, . . . ,
k
are the roots of p(x) = 0 where
p(x) = x
k
q(1/x) = x
k
+ c
1
x
k1
+ + c
0
.
Generating Functions
Products of generating functions
a(x) =

n=0
a
n
x
n
, b(x)) =

n=0
b
n
x
n
.
a(x)b(x) = (a
0
+ a
1
x + a
2
x
2
+ )
(b
0
+ b
1
x + b
2
x
2
+ )
= a
0
b
0
+ (a
0
b
1
+ a
1
b
0
)x +
(a
0
b
2
+ a
1
b
1
+ a
2
b
0
)x
2
+
=

n=0
c
n
x
n
where
c
n
=
n

k=0
a
k
b
nk
.
Generating Functions
Derangements
n! =
n

k=0
_
n
k
_
d
nk
.
Explanation:
_
n
k
_
d
nk
is the number of permutations with
exactly k cycles of length 1. Choose k elements (
_
n
k
_
ways) for
which (i ) = i and then choose a derangement of the
remaining n k elements.
So
1 =
n

k=0
1
k!
d
nk
(n k)!

n=0
x
n
=

n=0
_
n

k=0
1
k!
d
nk
(n k)!
_
x
n
. (3)
Generating Functions
Let
d(x) =

m=0
d
m
m!
x
m
.
From (3) we have
1
1 x
= e
x
d(x)
d(x) =
e
x
1 x
=

n=0
n

k=0
_
(1)
k
k!
_
x
n
.
So
d
n
n!
=
n

k=0
(1)
k
k!
.
Generating Functions
Triangulation of n-gon
Let
a
n
= number of triangulations of P
n+1
=
n

k=0
a
k
a
nk
n 2 (4)
a
0
= 0, a
1
= a
2
= 1.
+1
1
n+1
k
Generating Functions
Explanation of (4):
a
k
a
nk
counts the number of triangulations in which edge
1, n + 1 is contained in triangle 1, k + 1, n + 1.
There are a
k
ways of triangulating 1, 2, . . . , k + 1, 1 and for
each such there are a
nk
ways of triangulating
k + 1, k + 2, . . . , n + 1, k + 1.
Generating Functions
x +

n=2
a
n
x
n
= x +

n=2
_
n

k=0
a
k
a
nk
_
x
n
.
But,
x +

n=2
a
n
x
n
= a(x)
since a
0
= 0, a
1
= 1.

n=2
_
n

k=0
a
k
a
nk
_
x
n
=

n=0
_
n

k=0
a
k
a
nk
_
x
n
= a(x)
2
.
Generating Functions
So
a(x) = x + a(x)
2
and hence
a(x) =
1 +

1 4x
2
or
1

1 4x
2
.
But a(0) = 0 and so
a(x) =
1

1 4x
2
=
1
2

1
2
_
1 +

n=1
(1)
n1
n2
2n1
_
2n 2
n 1
_
(4x)
n
_
=

n=1
1
n
_
2n 2
n 1
_
x
n
.
So
a
n
=
1
n
_
2n 2
n 1
_
.
Generating Functions
Exponential Generating Functions
Given a sequence a
n
, n 0, its exponential generating function
(e.g.f.) a
e
(x) is given by
a
e
(x) =

n=0
a
n
n!
x
n
a
n
= 1, n 0 implies a
e
(x) = e
x
.
a
n
= n!, n 0 implies a
e
(x) =
1
1 x
Generating Functions
Products of Exponential Generating Functions
Let a
e
(x), b
e
(x) be the e.g.f.s respectively for (a
n
), (b
n
)
respectively. Then
c
e
(x) = a
e
(x)b
e
(x) =

n=0
_
n

k=0
a
k
k!
b
nk
(n k)!
_
x
n
=
n

k=0
c
n
n!
x
n
where
c
n
=
_
n
k
_
a
k
b
nk
.
Generating Functions
Interpretation
Suppose that we have a collection of labelled objects and each
object has a size k, where k is a non-negative integer. Each
object labelled by a set of size k.
Suppose that the number of labelled objects of size k is a
k
.
Examples:
(a): Each object is a directed path with k vertices and its
vertices are labelled by 1, 2, . . . , k in some order. Thus a
k
= k!.
(b): Each object is a directed cycle with k vertices and its
vertices are labelled by 1, 2, . . . , k in some order. Thus
a
k
= (k 1)!.
Generating Functions
Now take example (a) and let a
e
(x) =
1
1x
be the e.g.f. of this
family. Now consider
c
e
(x) = a
e
(x)
2
=

n=0
(n + 1)x
n
with c
n
= (n + 1) n!.
c
n
is the number of ways of choosing an object of weight k and
another object of weight n k and a partition of [n] into two
sets A
1
, A
2
of size k and labelling the rst object with A
1
and
the second with A
2
.
Here (n +1) n! represents taking a permutation and choosing
0 k n and putting the rst k labels onto the rst path and
the second n k labels onto the second path.
Generating Functions
We will now use this machinery to count the number s
n
of
permutations that have an even number of cycles all of which
have odd lengths:
Cycles of a permutation
Let : D D be a permutation of the nite set D. Consider the
digraph

= (D, A) where A = {(i , (i )) : i D}.

is a
collection of vertex disjoint cycles. Each x D being on a
unique cycle. Here a cycle can consist of a loop i.e. when
(x) = x.
Example: D = [10].
i 1 2 3 4 5 6 7 8 9 10
(i ) 6 2 7 10 3 8 9 1 5 4
The cycles are (1, 6, 8), (2), (3, 7, 9, 5), (4, 10).
Generating Functions
In general consider the sequence i , (i ),
2
(i ), . . . ,.
Since D is nite, there exists a rst pair k < such that

k
(i ) =

(i ). Now we must have k = 0, since otherwise putting


x =
k1
(i ) = y =
1
(i ) we see that (x) = (y),
contradicting the fact that is a permutation.
So i lies on the cycle C = (i , (i ),
2
(i ), . . . ,
k1
(i ), i ).
If j is not a vertex of C then (j ) is not on C and so we can
repeat the argument to show that the rest of D is partitioned
into cycles.
Generating Functions
Now consider
a
e
(x) =

m=0
(2m)!
(2m + 1)!
x
2m+1
Here
a
n
=
_
0 n is even
(n 1)! n is odd
Thus each object is an odd length cycle C, labelled by [|C|].
Note that
a
e
(x) =
_
x +
x
2
2
+
x
3
3
+
x
4
4
+
_

_
x
2
2
+
x
4
4
+
_
= log
_
1
1 x
_

1
2
log
_
1
1 x
2
_
= log

_
1 + x
1 x
_
Generating Functions
Now consider a
e
(x)

. The coefcient of x
n
in this series is
c
n
n!
where c
n
is the number of ways of choosing an ordered
sequence of cycles of lengths a
1
, a
2
, . . . , a

where
a
1
+ a
2
+ + a

= n. And then a partition of [n] into


A
1
, A
2
, . . . , A

where |A
i
| = a
i
for i = 1, 2, . . . , . And then
labelling the i th cycle with A
i
for i = 1, 2, . . . , .
We looked carefully at the case = 2 and this needs a simple
inductive step.
It follows that the coefcient of x
n
in
a
e
(x)

!
is
c
n
n!
where c
n
is the
number of ways of choosing a set (unordered sequence) of
cycles of lengths a
1
, a
2
, . . . , a

. . .
What we therefore want is the coefcient of x
n
in
1 +
a
e
(x)
2
2!
+
a(x)
4
4!
+ .
Generating Functions
Now

k=0
a
e
(x)
2k
k!
=
e
a
e
(x)
+ e
a
e
(x)
2
=
1
2
_
_
1 + x
1 x
+
_
1 x
1 + x
_
=
1

1 x
2
Thus
s
n
= n![x
n
]
1

1 x
2
=
_
n
n/2
_
n!
2
n
Generating Functions

You might also like