You are on page 1of 7

COMP2101 / CS20S Discrete Mathematics

Generating Functions and Recurrence Relations




Question 1
Find the generating function for the sequence {0, 1, 2, 3, 4, 5, }

Solution 1
We have {1, 1, 1, 1, } 1 + x + x
2
+ x
3
+ x
4
+
x 1
1


By differentiating
{1, 2, 3, 4, }
2
) 1 (
1
x

By right shifting, i.e. multiplying by x
1

{0, 1, 2, 3, 4, }
2
) 1 ( x
x


Therefore the generating function for the sequence {0, 1, 2, 3, 4, 5, } is
2
) 1 ( x
x




Question 2
Find the generating function for the sequence {2, 6, 12, 20, }

Solution 2
We have {1, 1, 1, 1, } 1 + x + x
2
+ x
3
+ x
4
+
x 1
1


By differentiating
{1, 2, 3, 4, }
2
) 1 (
1
x

By differentiating, again
For LHS
{2, 6, 12, 20, }
For RHS
2

2
2
) 1 (
) 1 (
1

=

= x
x
y Let


3
3
3
3
2
2
) 1 (
2
) 1 ( 2
) 1 ( ) 1 ( 2
) 1 ( 2
) 1 ( ) (
1
x
x
x
p
dx
x d
dp
p d
dx
dp
dp
dy
dx
dy
then
p y x p Let

=
=
=
=

= =
= =


Therefore
{2, 6, 12, 20, }
3
) 1 (
2
x

Therefore the generating function for the sequence {2, 6, 12, 20, } is
3
) 1 (
2
x



Question 3
Solve the following recurrence relation:
s
0
= 0
s
1
= 1
s
n
= 2s
n-1
s
n-2
for n 2

Solution 3
Let S = s
0
+ s
1
x + s
2
x
2
+ s
3
x
3
+ ... + s
n
x
n
+ ...
2xS = 2s
0
x + 2s
1
x
2
+ 2s
2
x
3
+ ... + 2s
n-1
x
n
+ ...
x
2
S = s
0
x
2
+ s
1
x
3
+ ... + s
n-2
x
n
+ ...

By Subtraction and Addition
S(1- 2x+x
2
) = s
0
+ (s
1
- 2s
0
)x + (s
2
-2s
1
+s
0
)x
2
+ ... + (s
n
-2s
n-1
+ s
n-2
)x
n
+ ...

As s
n
-2s
n-1
+ s
n-2
= 0
S(1-x)
2
= x
S = x / (1-x)
2


3
As 1/(1-x)
2
= 1 + 2x + 3x
2
+ 4x
3
+ ... + (n+1)x
n
+ ...

S = x[1 + 2x + 3x
2
+ 4x
3
+ ... + (n+1)x
n
+ ...]
= x + 2x
2
+ 3x
3
+ 4x
4
+ ... + nx
n
+ (n+1)x
n+1
+ ... +

Therefore the closed form solution of the recurrence relation is
[ n ]



Question 4
Solve the following recurrence relation:
s
0
= 1
s
n
= 2s
n-1
+ 1 for n 1

Solution 4
Given
s
0
= 1
s
n
= 2s
n-1
+ 1 for n 1
Consider the generating function
S = s
0
+ s
1
x + s
2
x
2
+ + s
n
x
n
+
2xS = 2s
0
x + 2s
1
x
2
+ + 2s
n-1
x
n
+

Subtracting
S - 2xS = s
0
+ (s
1
- 2s
0
)x + (s
2
- 2s
1
)x
2
++ (s
n
- 2s
n-1
)x
n
+

As s
n
= 2s
n-1
+ 1
Now Substituting s
0
= 1, s
1
= 2s
0
+ 1

,, s
n
- 2s
n-1
= 1
S(1 - 2x) = 1 + x + x
2
++ x
n
+
= 1 / (1 x)
S = (1 / (1 x)) * (1 / (1 - 2x))
S = (1 + x + x
2
++ x
n
+) * (1 + 2x + 2
2
x
2
+ 2
3
x
3
+ + 2
n
x
n
+)

f(x) = 1 * (1 + 2x + 2
2
x
2
+ 2
3
x
3
+ + 2
n
x
n
+)
+ x * (1 + 2x + 2
2
x
2
+ 2
3
x
3
+ + 2
n
x
n
+)
+ x
2
* (1 + 2x + 2
2
x
2
+ 2
3
x
3
+ + 2
n
x
n
+)

+ x
n
* (1 + 2x + 2
2
x
2
+ 2
3
x
3
+ + 2
n
x
n
+)

f(x) = 1 + (2+1)x + (2
2
+2+1)x
2
+ (2
3
+2
2
+2+1)x
3
+ + (2
n
+2
n-1
++2
2
+2+1)x
n
+

4
Therefore closed form solution is
[(2
n
+2
n-1
++2
2
+2+1) ]
or

(

=
n
k
k
0
2


Recall that
(

=
n
k
k
0
2
is a GP with first term, a = 1 and common ratio, r = 2

Considering the GP formula for summing to the term with nth index
The closed form solution is
[2
n+1
- 1]
5
Question 5
Solve the following recurrence relation:
s
0
= 3
s
n
= s
n-1
+ 2 for n 1

Solution 5
Given
s
0
= 3
s
n
= s
n-1
+ 2 for n 1

Consider the generating function
f(x) = s
0
+s
1
x+ s
2
x
2
++ s
n
x
n
+
xf(x) = s
0
x+ s
1
x
2
++ s
n-1
x
n
+

Adding
f(x) + xf(x) = s
0
+ (s
1
+ s
0
)x + (s
2
+ s
1
)x
2
++ (s
n
+ s
n-1
)x
n
+
Now Substituting s
0
= 3, s
1
= s
0
+ 2

,, s
n
= s
n-1
+ 2
(1+x)f(x) = 3 + 2x + 2x
2
++ 2x
n
+

f(x) = (3 + 2x + 2x
2
++ 2x
n
+) * (1 / (1+x))
f(x) = (3 + 2x + 2x
2
++ 2x
n
+) + (1 - x + x
2
- x
3
+ (-1)
n
x
n
+)

f(x) = 3 - 3x + 3x
2
- 3x
3
+ 3(-1)
n
x
n
+
+ 2x - 2x
2
+ 2x
3
- 2x
4
+ 2(-1)
n-1
x
n
+
+2x
2
- 2x
3
+ 2x
4
- 2x
5
+ 2(-1)
n-2
x
n
+

+ 2(-1)
0
x
n

f(x) = [(-1)
n
+ 2 * ((-1)
n
+(-1)
n-1
++(-1)
2
+(-1)
1
+(-1)
0
] x
n
+

Therefore closed form solution is
[ (-1)
n
+ 2 ((-1)
n
+(-1)
n-1
++(-1)
2
+(-1)
1
+(-1)
0
) ]
or

(

+

=
n
k
k n
0
) 1 ( 2 ) 1 (







6
FOR ADDITIONAL PRACTICE
Question 6
Solve the following recurrence relation:
s
0
= 1
s
1
= 1
s
n
= -2s
n-1
s
n-2
for n 2

Solution 6
Let G = s
0
+ s
1
x + s
2
x
2
+ s
3
x
3
+ ... + s
n
x
n
+ ...
2xG = 2s
0
x + 2s
1
x
2
+ 2s
2
x
3
+ ... + 2s
n-1
x
n
+ ...
x
2
G = s
0
x
2
+ s
1
x
3
+ ... + s
n-2
x
n
+ ...

By Addition
S(1+2x+ x
2
) = s
0
+ (s
1
+2s
0
)x + (s
2
+2s
1
+ s
0
)x
2
+ ... + (s
n
+2s
n-1
+ s
n-2
)x
n
+ ...

As s
n
+2s
n-1
+ s
n-2
= 0
S(1+x)
2
= 1 + (1+2)x
S = (1+3x) / (1+x)
2


As 1/(1+x)
2
= 1 - 2x + 3x
2
- 4x
3
+ ... + (-1)
n
(n+1)x
n
+ ...

S = 1 * (1 - 2x + 3x
2
- 4x
3
+ ... + (-1)
n
(n+1)x
n
+ ...)
+ 3x * (1 - 2x + 3x
2
- 4x
3
+ ... + (-1)
n
(n+1)x
n
+ ...)

= 1 - 2x + 3x
2
- 4x
3
+ ... + (-1)
n
(n+1)x
n
+ ...
+ 3x - 6x
2
+ 9x
3
- 12x
4
+ ... + 3(-1)
n-1
(n)x
n
+ ...

= 1 + x - 3x
2
+ 5x
3
- 7x
4
+ ... + [(-1)
n
(n+1) + 3(-1)
n-1
(n) ]x
n
+ ...

Therefore the closed form solution of the recurrence relation is
[(-1)
n
(n+1) + 3(-1)
n-1
(n) ]

or simplified to
[ (-1)
n
[(n+1) + 3(-1)
-1
] ]
or
[ (-1)
n
(n - 2) ]











7


Question 7
Solve the following recurrence relation:
s
0
= 3
s
n
= 3s
n-1
+ 2 for n 1

Solution 7
Given
s
0
= 3
s
n
= 3s
n-1
+ 2 for n 1

Consider the generating function
f(x) = s
0
+s
1
x+ s
2
x
2
++ s
n
x
n
+
3xf(x) = 3s
0
x+3s
1
x
2
++3s
n-1
x
n
+

Adding
f(x) + 3xf(x) = s
0
+ (s
1
+ 3s
0
)x + (s
2
+ 3s
1
)x
2
++ (s
n
+ 3s
n-1
)x
n
+
Now Substituting s
0
= 3, s
1
= 3s
0
+ 2

,, s
n
= 3s
n-1
+ 2
(1+3x)f(x) = 3 + 2x + 2x
2
++ 2x
n
+
= 1 + 2 (1 + x + x
2
++ x
n
+)

f(x) = (1 + 2 (1 + x + x
2
++ x
n
+)) * (1 / (1+3x))
f(x) = (1 + 2 (1 + x + x
2
++ x
n
+)) * (1 - 3x + 3
2
x
2
- 3
3
x
3
+ (-3)
n
x
n
+)

f(x) = 1 * (1 - 3x + 3
2
x
2
- 3
3
x
3
+ (-3)
n
x
n
+)
+ 2 [ 1 * (1 - 3x + 3
2
x
2
- 3
3
x
3
+ (-3)
n
x
n
+)
+ x * (1 - 3x + 3
2
x
2
- 3
3
x
3
+ (-3)
n
x
n
+)
+ x
2
* (1 - 3x + 3
2
x
2
- 3
3
x
3
+ (-3)
n
x
n
+)

+ x
n
* (1 - 3x + 3
2
x
2
- 3
3
x
3
+ (-3)
n
x
n
+) ]
f(x) = 1 * (1 - 3x + 3
2
x
2
- 3
3
x
3
+ (-3)
n
x
n
+)
+ 2 [ 1 + (-3 + 1)x + (3
2
-3+1)x
2
+ + ((-3)
n
+(-3)
n-1
++3
2
-3+1) x
n
+ ]

Therefore closed form solution is
[ (-3)
n
+ 2 ((-3)
n
+(-3)
n-1
++3
2
-3+1) ]
or

(

+

=
n
k
k n
0
) 3 ( 2 ) 3 (

You might also like