You are on page 1of 100

Generating function

Defn : generating function of


a sequence q0, q1,…, qr ,………
is 
A( x)   qr x r

r 0

For example
1 Is generating function
for sequence
1  x 1,1,1,…………………..
1
1 x
is generating function
for sequence
1,-1,1,-1,… (-1)r+1,………
m m!
   C (m, r )  ,
r r! (m-r)!
0!  1
(1+x) -m
= 1-mx+(-m(-m-1)/2)x2 +….
+[(-m)(-m-1) (-m-r+1)]/r!)xr
+……………….


 m 1  r 
  ( x)
r

r 0  r 
n 
 n 1  r  r
(1  x)   
r 0  r 
x
7 article 3.1 : If we are given
integers from 1 to 34 find the
number of ways of selecting 3
nonconsecutive integers through
generating function.
Solution :manual not simple
Can generating function help
Let numbers be q1 , q2 , q3
number of integers
between q1 & q2

umber of number of integers after q3


ntegers before q1number of integers
between q2 & q3
(1+x+….)(x+x2+…. )( x+x2+…. ) (1+x+….)
Which coefficient in above expression ?
Is the generating function
(1+x+….)2(x+x2+…. )2

how do we justify that?


Coefficient of x31 will give that answer?
think :Find a generating function for
selecting 4 non consecutive integers
Between 3 & 31 Which
Coefficient will give the answer?
4 Find a generating function for solution of

X1 +X2 + X3 + X4 + X5 =20
Where
0  X2 3, 0 X3 3, 0 X4 3

Can A(x) be generating function ?

If A(x)=
(1+x+……+x20)2 (1+x+x2+x3 )3 ?
Shifting property of
generating functions
If A(x) generates the sequence
(q0, q1,…, qn,………………)
Then xA(x) generates the sequence
(0,q0, q1,…, qn,………………)
Then x2 A(x) generates the sequence
(0,0,q0, q1,…, qn,………………)
Then x3 A(x) generates the sequence
(0,0,0, q0, q1,…, qn,………………)
think : Write the generating
function for sequence defined as
{qr }= { r} sequence
0,1,2,3,4,………..

What was generating function of


sequence 1,2,3,4,………..
i.e. 1+2x+3x2+.........................
Answer : (1-x)-2
hence shifting property of
generating function will
give answer as
x(1-x)-2
Q. 3 Through partial fractions find
coefficients qr for generating
function .

1
1  7 x  10 x 2
Through partial fractions
1 1

1  7 x  10 x 2
(1  2 x)(1  5 x)
A C
 
1  2x 1  5x
2 1 5 1
  (1  2 x)  (1  5 x)
3 3
 
2 5
   2x   5x 
r r

3 r 0 3 r 0
 
2 5
   2x   5x 
r r

3 r 0 3 r 0

Ans :
qr = (5/3) 5 - (2/3) 2
r r
Q. 4 (vii) Write the generating
function for sequence defined
as qr = r2
  
A( x)   r x   r x  [r(r  1)-r]x
2 r 2 r r

r 0 r 1 r 1


A( x)   [(r  1)(r  2)-(r  1)]x r 1

r 0

A( x)   [(r  1)(r  2)-(r  1)]x r 1

r 0
 
 x [(r  1)(r  2)x ]-x  (r  1)x
r r

r 0 r 0

 r  2 r 
 r  1 r
 x [2   x ]-x   x
r 0  r  r 0  r 


A( x)  x  [(r  1)(r  2)-(r  1)]x r

r 0

 r  2  r 
 r  1 r
A( x)  x  [2   x ]-x   x
r 0  r  r 0  r 

2x 2
 3
 x (1  x )
(1-x)
2x-x(1-x) x(1  x)
 3
 3
(1-x) (1-x)
How to find generating
function of r ?
3
(iii) (r+1) r(r-1)=r3 -r

Solution:A(x)   (r  1)r(r-1)x r

0

  (r  1)r(r-1)x r
2


  (r  3)(r  2)(r  1)x r  2
0

2
6x
 4
(1-x)
(iii) (r+1) r(r-1)=r3 -r


x
0 r x  (1-x)2
r
12
Q.7 Find the coefficient of x in
1-x  x  x
4 7 11

5
(1-x)

5  5 1  r  r
(1  x) 

 
r 0  r 
x
1-x  x  x
4 7 11

5
(1-x)
 5 1  r  r

 (1-x  x  x ) 
4 7 11
x
r 0  r 

 4  r  r   4  r  r 4
  x    x
r 0  r  r 0  r 


 4  r  r  7   4  r  r 11
  x    x
r 0  r  r 0  r 

 4  r  r   4  r  r 4
  x    x
r 0  r  r 0  r 


 4  r  r  7   4  r  r 11
  x    x
r 0  r  r 0  r 

Coefficient of x12 is

16  12   9   5 
    
12   8   5   1 
13
Q.8 (ii) Find the coefficient of x in

1  x  x 2
x 
3 10

1  x 
4 10

(1` x)10

 10 10  4 r   10  1  s  s 
    ( x )    x 
 r  0  r   s  0  s  
 10 10   
9  s s 
    (1) x   
r 4r
x 
 r 0  r   s 0  s  

 22  10 18  10 14  10 10 


Answer :              
 13   1  9   2  5   3  1 
50
Q.10 Find the coefficient of x in
A(x)  x 10
 x  ........  x
11 25

 x  x  x  .........x 
2 3 15

 x  x  ........  x 
20 21 45
(1  x ) (1  x ) (1  x )
16 15 26
x 31

(1  x) (1  x) (1  x)
 
 3 1 r  r 
 x (1  x )(1  x )(1  x )   
31 16 15 26
x 
 r 0  r  
(1  x ) (1  x ) (1  x )
16 15 26
x 31

(1  x) (1  x) (1  x)
 
 3 1  r  r 
 x (1  x )(1  x )(1  x )   
31 16 15 26
x 
 r 0  r  
 
 3 1  r  r 
 ( x  x )(1  x )(1  x )   
31 47 15 26
x 
 r 0  r  
 
 3 1 r  r 
 ( x  x -x  x )(1  x )   
31 46 47 62 26
x 
 r 0  r  
 
 3 1 r  r 
 ( x  x -x  powers of x  50)   
31 46 47
x 
 r 0  r  
 
 3 1 r  r 
 ( x  x -x  x )(1  x )   
31 46 47 62 26
x 
 r 0  r  
 
 3 1 r  r 
 ( x  x -x  powers of x  50)   
31 46 47
x 
 r 0  r  

 21  5   6 
   
 19   3   4 
4 Find a recurrence relation to
find number of way put flags on a “n”
meter length pole taking help of
four type of flags red blue black &
orange, red flags of 2 meter and
rest other three color flags of
1 meter.
?: Let qn represent the number of ways to
arrange flags on pole of length n
Solution. We partition the set of all such
ways into two types –
I: those that end with red color,
II :those that end with other 3 colors
for of type I : rest of flags are to be put for
length n − 2 ,i.e qn−2 ways as red flag is
of 2 feet.

For other type consist of a length n -1


there are 3qn−1 ways
We thus obtain the recurrence relation:
qn = 3qn−1 + qn−2 for all n  2

It is left to specify the two initial values:


q1 = 3 q2 = 10 ?
Think :Find a recurrence relation to
find number of way put flags on a “n”
meter length pole taking help of
four color of flags red ,black, blue,
& orange , red and orange
flags of 2 meter , black of one meter
blue color flags of 3 meter.
8 article 3.3 : Let qn represent the number of
those strings of length n (formed from digits 0,
1)which do not contain three consecutive zeros.
Set up a recurrence relation for qn – include the
initial conditions. Justify your reasoning briefly.
Solution. We partition the set of all such
strings into three types –
those that do not end with 0,
those that end with exactly one 0 and
those that end with exactly two 0’s.
There can not exist strings that end in
three or more zeros, given the
condition
Strings of type 1 consist of a length n − 1
string without three consecutive zeros, with
1 added on as the n-th digit, so there are
qn−1 strings of this type.

Strings of type 2 consist of a length n − 2


string without three consecutive zeros, with
10 added on as the final two digits, so
there are qn−2 strings of this type.
Strings of type 3 consist of a length n − 3
string without three consecutive zeros, with
100 added on as the final three digits, so
there are qn−3 strings of this type.

We thus obtain the recurrence relation:


qn = qn−1 + qn−2 + qn−3 for all n  4
It is left to specify the three initial values:
q1 = 2 q2 = 4
q3 = 8 − 1 = 7 where the string 000 has to be excluded
Recurrence relation &
generating functions 3.4
General first-degree linear
recurrence relation with constant
coefficients
The general first-degree linear
recurrence relation with constant
coefficients has the form
qn=cqn-1 + f(n).
If f(n)=0, the relation is called
homogeneous. Otherwise, it is called
non homogeneous.
Corr : If qn = cqn -1+f(n) for
n>0 through method of forward
substitution.
n
q n  c q 0   c f(r)
n n r

r 1

Solved in book ?
The second-degree linear
homogeneous recurrence
relation with constant
coefficients , general form is ,
r0qn+r1qn-1+r2qn-2=0, n2.
r2  0 r0  0
where q0 & q1 are known
First order Linear inhomogeneous
recurrence relation and generating
function
tested : Solve the recurrence
relation
qr-2qr-1+qr-2 , = 2r+r, r≥2 ,
q0=0=q1
With the help of generating
functions.
qr-2qr-1+qr-2 = 2r+r, r2

  


2
q r x -2 q r-1 x   q r-2 x
r

2
r

2
r

 
  2 x   rx ,
r r r

2 2
 
(A(x)-q 0 -q1x )-2x 
1
qr x  x
r 2

0
qr x r

 
  
   2 x -1-2x     rx -x 
r r r

 0   0 
 A(x)-2x(A(x)-q0 )  x A(x) 2

1 2
 (1  2 x)  (1  3x)  x(1  x)

 A(x)(1-2x  x ) 2

1 2
 (1  2 x)  (1  3x)  x(1  x)
 A(x)
1 2 2 4
 (1  2 x) (1  x)  (1  3x)(1  x)  x(1  x)
Now find partial fractions of
(1-2x)-1(1-x)-2
1 L C M
  
(1  2 x)(1  x) 2
(1  2 x) (1  x) (1  x) 2

we find
1 4 2 1
  
(1  2 x)(1  x) 2
(1  2 x) (1  x) (1  x) 2
1 2 4
A( x)   (1  3x)(1  x)  x(1  x)
(1  2 x)(1  x) 2

4 2 1 1  3x x
    
(1  2 x) (1  x) (1  x) (1  x) (1  x)
2 2 4

4 2 2 3x x
    
(1  2 x) (1  x) (1  x) (1  x) (1  x)4
2 2

   
A( x)   (4)2 x - 2x  2 (r  1)x  3 (r)x
r r r r r

0 0 0 0

 4-1  r  r 1

  x
0  r 
   
A( x)   (4)2 x - 2x  2 (r  1)x  3 (r)x
r r r r r

0 0 0 0

 4-1  r  r 1

  x
0  r 

 4-1  r  r 1 
2 r r
0  r x    x
  r 1  r-1 

(r  2)(r  1)r r
 x
r 1 6

(r  2)(r  1)r r

 x
r 0 6
   
A( x)   (4)2 x - 2x  2 (r  1)x  3 (r)x
r r r r r

0 0 0 0

(r  2)(r  1)r r
  x
r 0 6
r (r  1)(r  2)
q r  4(2)  2  2(r  1)  3r 
r

6
r (r  1)(r  2)
 4(2)  4  5r 
r

6
Thm : Generating function A(x) for solution
of degree three linear homogenous recurrence
relation with constant coefficients
q n  r1q n-1  r2 q n-2  r3q n-3  0 , n  3
q 0  (q1  r1q 0 ) x  (q 2  r1q1  r2 q 0 ) x 2
is A(x) 
1  r1x  r2 x  r3 x
2 3
Q.10 Solve the divide & conquer 10
8 Solve relation qn=qn/2+2n-1, n2,
q1=1,For n=2r

Solution : q 2r  q 2r-1 2r1 1 Qr  q 2r


transformed recurrence relation is
Q r=Qr-1+2r+1 -1, r≥1, Q0=1
r 1
Q r -Qr-1  2 -1, r  1 Q 1 -Q0  2 -1, ....(1)
2

Q 2 -Q1  2 -1,
3
...(2) Qr=4(2r-1)-r+1

Q 3 -Q2  2 -1,
4
...(3)

r 1
Q r -Q r-1  2 -1, ...(r) Add all we get

r 1
Q r -Q0  2  2  ...........2 -r
2 3

r 1
Q r -1  2  2  ...........2 -r
2 3

Qr=4(1+2+…….2r-1)-r+1
Q r  4(2)  3  ( r )
r

q 2r  4(2)  3  ( r )
r

q n  4n  3  log 2 n for n  2 r
Method of Characteristic
polynomial roots to solve linear
homogenous recurrence relation
The second-degree linear
homogeneous recurrence relation
with constant coefficients
qn+r1qn-1+r2qn-2=0, n2. r20
If we take qn=cn ,c0 ,  0
then we get c n-2 ( 2+r1+r2 )=0
C()2+r1+r2=0
C() is called characteristic
polynomial of recurrence relation
C()2+r1+r2=0
C() is called characteristic polynomial
of recurrence relation
qn+r1qn-1+r2qn-2=0, n2.
The roots 1, 2 of this equation are called
characteristic roots.
Three possibilities for the roots:
(1) distinct real roots,
(2) repeated real roots,
(3) complex roots
qn+r1qn-1+r2qn-2=0, n2. -------(a)

Characteristic polynomial
2+r1+r2=0 -----------(i)
(I ) 1 & 2 are real and distinct roots
Then qn= 1(1 )n+ 2(2 )n
is general solution of (a) , where
1 & 2 are arbitrary constants.
(II) If 1 = 2 = is double root of
(i)
Then qn= 1( )n+ 2 n( )n
is general solution of (a)
Third degree linear
homogenous recurrence
relation
qn+ r1 qn-1+ r2 qn-2+ r3 qn-3 =0,n3, r30
---------(*)
Characteristic equation is
3+r12+r2  + r3 = 0 --------(i)
Different possibilities
(I ) 1 , 2 and 3 are real and
distinct roots of (i)
Then qn=L(1 )n+C(2 )n +M(3 )n
is general solution of (*)
(II) 1 is a double root & 2 is
a simple root of (i) Then
qn=L(1 )n+ C n(1 )n +M(2 )n
Is general solution of (*)
(III) 1 = 2 = 3 = is root of
multiplicity 3 of characteristic
polynomial (i), then
qn=L( ) +C
n n( )n +M n ()
2 n

Is general solution of (*)


The linear nonhomogeneous
recurrence relation of degree one &
two
qn+r1qn-1=f(n), n>o,
qn+r1qn-1+r2qn-2=f(n), n2
how to find general solution of
non homogenous recurrence relation
through method of characteristic roots
& method of undetermined coefficients
Let qn(h) denote the general
solution of the associated
homogeneous relation.
Let qn(p) denote a particular
solution of the given
nonhomogeneous relation.
(particular solution)
Then qn= qn(h)+ qn(p) is the general
solution of the problem.
f(n) Characteristic polynomial Form of particular solution
C()

Dn C()0 An

Dn C()=0 ,  is root of Bns n


multiplicity s of C()

Dnp n C()0 (Q0 + Q1 n +…….Qp np ) n

Dnp n C()=0 ,  is root of ns (Q0 + Q1 n +…….Qp np ) n


multiplicity s of C()

Dnp C(1)0 (Q0 + Q1 n +…….Qp np )

Dnp C(1)=0 , 1 is root of ns (Q0 + Q1 n +…….Qp np )


multiplicity s of C()
Rajiv Kumar I semester 2012-
2013 Discrete math
Comment

In last four types of table form of the


particular solution is same if Dnp
is replaced with (R0 + R1 n +…….Rp np )
Simple : Solve the recurrence
relation qr-3qr-1=5(7 ) for r1
r

and q0=2.
The solution for qr-3qr-1=0
C()= -3
=3 is root, qr(h)=A(3r)
Now f(r)=5 (7r)
=7 , C(7)0
(Hence qr(p)= D 7r
qr(p) -3 qr-1(p)=5(7r)
D 7r -3 D 7r-1 =5(7r) D= 35/4
The particular solution is
qr(p)=(5/4)7r+1.
The general solution to the problem is
qr= A(3r)+ (5/4)7r+1
Finally, we have q0=2 A=-(27/4)
qr= -(1/4)(3r+3)+ (5/4)7r+1
Simple: Find the form of particular
solution qn(p) (do not solve for constants)

to the following recurrence relations


(i) qn -4qn-1+4qn-2= n+n3 n2
(ii) qn -3qn-1+2qn-2=n3 n2
(iii) qn -2qn-1+qn-2=n3 n2
tested : Find general solution
of recurrence relation
qn -2qn-1+qn-2=4 n2

Solution : C()= (-1) (-1) ,


qn(h) = A+Cn
f(n)=4 form of particular solution
1 is double root of C()
qn(p) = Q0 n2
qn(p) -2 qn-1(p) + qn-2(p) =4
Q0 n2 -2Q0 (n-1)2 + Q0 (n-2)2 =4

-2Q0 + 4Q0 =4Q0 =2

qn = A+Cn+2n2
4 : Solve the recurrence relation
qr-5qr-1+6qr-2 , = 4r-2 r≥2 ,
q0=1,5=q1
(i)first taking help of generating
functions
(ii) taking help of undetermined
Coefficients
qr-5qr-1+6qr-2 = 4r-2
   

 2
q r x -5 q r-1 x  6 q r-2 x   4 x
r

2
r

2
r

2
r-2 r

   


2
q r x -5x  q r x  6 x
r

1
r 2

0
qr x  x
r 2

0
4xr r
2
x
(A(x)-q 0 -q1x)-5x(A(x)-q 0 )  6 x A( x)  2

1  4x
2
x
A( x)(1  5 x  6 x ) 
2
 1 q 0  1& q1  5
1 4x
1  x2  4x L M C
A( x)    
(1  4 x)(1  2 x)(1  3x) 1  4 x 1  2 x 1  3x
1  x  4 x  L(1  2 x)(1  3x)  M (1  4 x)(1  3x)  C (1  2 x)(1  4 x)
2
1 3 2
A( x)   
2(1  4 x) 2(1  2 x) (1  3x)
  
1 r r 3
A( x)   4 x -  2 x  2 (3 )x
r r r r

2 0 2 0 0

1 r r 1
q r  (4)  3(2 )  2(3 )
r

2
tested : qn -3qn-1+2qn-2 =n2n

n2
solve for q0 =q1 =1
Solution : homogenous equation
qn-3qn-1+2qn-2 = 0
C()= 2 -3+2=(-2) (-1)

=2 & =1


qn(h) = C(2n)+ D
As C(1)=0 & 1 is simple root

qn(p)=(0 + 1n)n2n
qn(p) -3 qn-1(p)+ 2qn-2(p) = n2n
(0 + 1n)n2n-3{0+ 1(n-1)}(n-1) 2n-1
+2 {0 + 1(n-2)}(n-2) 2n-2=n2n

(0 n +1n2 ) (4) -6 0 (n-1) - 6 1(n-1)2


+ 4 0 (n-2) +4 1(n-2)2 = 4n
4(0 n +1n2 ) -6 0 (n-1) -6 1(n-1)2
+ 2 0 (n-2) +2 1(n-2)2 = 4n
4(0 n +1n2 )+6 0 -6 0n- 61n2
+12 1n- 61 +2 0 n -4 0
+2 1n2 - 8 1n + 81 = 4n
equating Coefficients of n
i.e, 40 -6 0 +12 1+2 0 -81 =4

 4 1 =4  1 =1
& 20 +2 1 =0  0 = -1
qn(p)=(-1+n)n2n

qn = C(2n)+ D +(-1+n)n2n
q0 = C+ D=1
q1 = 2C+ D =1 i.e C=0 &
D=1
qn = 1 +(-1+n)n2n
tested: Find particular solution to the recurrence
relation qn-3qn-1+2qn-2 = 5n+3, n2 ,
using method of undetermined coefficients

Solution : Homogenous equation


qn-3qn-1+2qn-2 = 0
C()= 2 -3+2=(-2) (-1)
=2 & =1
As C(1)=0 & 1 is simple root
& f(n) is a polynomial , we have
qn(p)  0 + 1n
but for reasons that 1 is simple
root of C()
qn(p)=(0 + 1n)n
qn(p) -3 qn-1(p)+ 2qn-2(p) = 5n+3
(0 + 1n)n -3 {0 + 1(n-1)}(n-1)
+2 {0 + 1(n-2)}(n-2)=5n+3
(0 + 1n)n -3 {0 + 1(n-1)}(n-1)
+2 {0 + 1(n-2)}(n-2)=5n+3
(0 n +1n2 ) -3 0 (n-1)-3 1(n-1)2
+ 2  (n-2)+2  (n-2)2 = 5n+3
0 1

(0 n +1n2 )+3 0 -3 0n- 31n2


+6 1n- 31 +2 0 n-4 0
+2 1n2 - 8 1n + 81 = 5n+3
(0 n +1n2 )+ 3 0 -3 0n- 31n2
+6 1n- 31 +2 0 n-4 0
+2 1n2 - 8 1n + 81 = 5n+3
equating coefficients of n on left and right

i.e, 0 n -3 0 n +6 1n+2 0 n -81n =5n

 -2 1 =5  1 =-5/2
& 51 - 0 =3  0 = -31/2
qn(p)={-(31/2)–(5/2)n)}n
recurrence relation that can be
transformed to linear recurrence
relation with constant coefficients

18 : Solve the following recurrence relations


by making an appropriate substitution to
transform the relations into recurrences
with constant coefficients
(ii) nqn  nqn-1  qn-1  2 n
, q0  10

Solution : nq n  nq n-1  q n-1  2 n


, q 0  10
First transform to linear recurrence relation
nq n  (n  1)q n-1  2 ...............(*)
n

rn nq n
(iii)q  2qn-1  0, q0  8
3
n

Solution : q  2q n-1  0, q 0  8
3
n

q  2q n-1  0  q
3
n
3
n  2q n-1
3log 2 q n  1  log 2 q n-1

log 2 q n  rn
3rn  rn1  1, log 2 q 0  r0  log 2 8  3
(ix)nq n  (n  1)q n-1  2n, q 0  1

rn  rn-1  2n, r0  0
(h)
r
n  A(1) , r
n (p)
n  w0  w1n
hence w0  w1n  w0  w1 (n  1)  2n
 w1  1& 2w0  w1  0  w0  1/ 2
rn 1 1
rn   , r0  3
3 3
F 1
F 
3 3
2 1 1
F  F 
3 3 2
1 n 1
rn  w( ) 
3 2
1 5
3  w w
2 2

n
51 1
log 2 qn     Check q1 =(2)4/3
23 2
(iv)q n  nq n-1  n !, q 0  2

qn q n-1
Solution :   1, q 0  2
n ! (n  1)!

r n  r n 1  1, r0  2
(vi ) q n  5nq n-1  6n(n  1)q n-2  0, q 0  6 &q1  17

Solution:
q n  5nq n-1  6n(n  1)q n-2  0, q 0  6 &q1  17
q n  5nq n-1  6n(n  1)q n-2  0,
qn n 6n(n  1)
(n!)  0,  5 q n-1  q n-2  0
(n !) n ! n!
qn
rn 
(n !)
(viii)nq n  (n  2)q n-1  2n, q 0  5

n(n-1)q n  (n  1)(n  2)q n-1


 2n(n  1),
n(n-1)q n  rn
transformed relation
rn - rn-1  2n(n  1)
q n-1
(v)q n  2 , q 0  1, q1  1
q n-2

1
ln(q n )  ln(q n-1 )-2ln(q n-2 ) q 0  1, q1  1
2

You might also like