Recurrence Relations Solving Linear Recurrence Relations€¦ · Recurrence Relations Dr Patrick...

41
4.1 Recurrence Relations Dr Patrick Chan School of Computer Science and Engineering South China University of Technology Discrete Mathematic Chapter 4: Advanced Counting Techniques 4.2 Solving Linear Recurrence Relations 4.4 Generating Functions 2 Ch. 4.1, 4.2 & 4.5 Agenda Recurrence Relations Modeling with Recurrence Relations Linear Nonhomogeneous Recurrence Relations with Constant Coefficients Generating Functions Useful Facts About Power Series Extended Binomial Coefficient Extended Binomial Theorem Counting Problems and Generating Functions Using Generating Functions to Solve Recurrence Relations

Transcript of Recurrence Relations Solving Linear Recurrence Relations€¦ · Recurrence Relations Dr Patrick...

4.1

Recurrence Relations

Dr Patrick ChanSchool of Computer Science and Engineering

South China University of Technology

Discrete Mathematic

Chapter 4: Advanced Counting Techniques

4.2

Solving Linear Recurrence Relations4.4

Generating Functions

2Ch. 4.1, 4.2 & 4.5

Agenda

� Recurrence Relations

� Modeling with Recurrence Relations

� Linear Nonhomogeneous Recurrence Relations with Constant Coefficients

� Generating Functions

� Useful Facts About Power Series

� Extended Binomial Coefficient

� Extended Binomial Theorem

� Counting Problems and Generating Functions

� Using Generating Functions to Solve Recurrence Relations

3Ch. 4.1, 4.2 & 4.5

Recursion

How many i-products the

families of students in our

school have?

0 0 1 1 1 1 1 0 1 0 00 1 0

2 4 1

16

7How many i-products?

How many

i-pr oduc ts?How many i-pr oduc ts?

How m any

i -produc t s?

How m any

i- produc t s?

How m any

i -produc t s?

4Ch. 4.1, 4.2 & 4.5

Recurrence Relations

� A recurrence relation for a sequence {an} is an equation that expresses an in terms of one or more previous elements (a0, …, an−1)

� A sequence is called a solution of a recurrence relation if its terms satisfy the recurrence relation

5Ch. 4.1, 4.2 & 4.5

Recurrence Relations

Example 1

� Let {an} be a sequence that satisfies the recurrence relation an = an-1 - an-2 for n = 2, 3, 4, . . . , and suppose that a0 = 3 and a1 = 5. What are a2 and a3?

� From the recurrence relation:

� a2

� a3

= a1 – a0 = 5 - 3 = 2

= a2 – a1 = 2 - 5 = -3

6Ch. 4.1, 4.2 & 4.5

Recurrence Relations

Example 2

� Consider the recurrence relation

an = 2an−1 − an−2, where n ≥ 2

� Which of the following are solutions?� an = 3n

� 2an−1 − an−2 = 2(3(n - 1)) - 3(n - 2) = 3n = an

� an = 2n

� 2an−1 − an−2 = 2(2n-1) – nn-2 = 2n ≠ an

� an = 5

� 2an−1 − an−2 = 2 x 10 – 5 = 5 = an

����

����

����

7Ch. 4.1, 4.2 & 4.5

Recurrence Relations

� The initial conditions for a sequence specify the terms that precede the first term where the recurrence relation takes effect

� For examplean = an-1 + an-2, what is the value of a3?

Answer depends on a0 and a1 (initial conditions)

� a0 = 3 and a1 = 5 :

� a0 = 1 and a1 = 2 :

� A sequence is determined uniquely by

� Recurrence relation

� Initial conditions

a2 = 8, a3 = 13

a2 = 3, a3 = 5

8Ch. 4.1, 4.2 & 4.5

Modeling with Recurrence Relations

Compound Interest

� Growth of saving in a bank account with r% interest per given period

� Sn = Sn-1 + r · Sn-1 = (r+1) · Sn-1

� Example:� Suppose that a person deposits $10,000 in a savings

account at a bank yielding 11 % per year with interest compounded annually. How much will be in the account after 30 years?

� S30 = 1.11S29 = 1.11(1.11S28) = …= (1.11)30 10,000

9Ch. 4.1, 4.2 & 4.5

Modeling with Recurrence Relations

Fibonacci (Rabbits) Numbers � A young pair of rabbits

(one of each sex) is placed on an island

� A pair of rabbits does not breed until they are 2 months old

� After they are 2 months old, each pair of rabbits produces another pair each month

� Pn = Pn−1 + Pn−2

1

1

1.11

1 1.21.1

1 1.3

1.1.11.1

1.2

Younger than two months

At least two

months old

1

2

3

4

5

10Ch. 4.1, 4.2 & 4.5

Modeling with Recurrence Relations

Tower of Hanoi

� Objective

� Get all disks from peg 1 to peg 3

� Rules

� Only move 1 disk at a time

� Never put a larger disk on a smaller one

1 2 3

11Ch. 4.1, 4.2 & 4.5

Modeling with Recurrence Relations

Tower of HanoiMore than 1 steps

More than 1 steps 1 step More than 1 steps

Break Down

Recursive Call Recursive Call

12Ch. 4.1, 4.2 & 4.5

Modeling with Recurrence Relations

Tower of HanoiMore than 1 steps

More than 1 steps 1 step More than 1 steps

Break Down

Recursive Call Recursive Call

13Ch. 4.1, 4.2 & 4.5

Modeling with Recurrence Relations

Tower of HanoiMore than 1 steps

1 step 1 step 1 step

Break Down

Base Case Base Case

14Ch. 4.1, 4.2 & 4.5

Modeling with Recurrence Relations

Tower of Hanoi

The solution

15Ch. 4.1, 4.2 & 4.5

Modeling with Recurrence Relations

Tower of Hanoi

� Let Hn be the number of moves for a stack of n disks.

� Strategy:

� Move top n−1 disks (Hn−1 moves)

� Move bottom disk (1 move)

� Move top n−1 to bottom disk (Hn−1 moves)

� Hn = 2Hn-1 + 1

16Ch. 4.1, 4.2 & 4.5

Modeling with Recurrence Relations

Example � Find a recurrence relation and give initial conditions for the

number of bit strings of length n that do not have two consecutive 0s.

� Let Pn denote the number of bit strings of length n that do not have two consecutive 0s

� Pn = Pn-1 + Pn-2 , n ≥ 3

� P1 = 2, P2 = 3

1

Any bit string of length n - 1 with no two consecutive 0s

10

Any bit string of length n - 2 with no two consecutive 0s

Pn-1

Pn-2

0101 0110

0111 1010

1011 1110

1111

For P4

P3

P21101

17Ch. 4.1, 4.2 & 4.5

Solving Linear Recurrence Relations

� Given Pn = Pn−1 + Pn−2, what is P100?

� It is not easy to calculate

� Need a better solutionwhich is not in

relation form

E.g. Pn = n*10 -1

18Ch. 4.1, 4.2 & 4.5

Solving Linear Recurrence Relations

� Linear Homogeneous Recurrence of Degree k with Constant Coefficients is a recurrence of the form

an = c1an−1 + … + ckan−k

where the ci are all real numbers, and ck ≠ 0

� Linear: the power of all a i term is one

� Homogeneo us: no constant term (no team without ai)

� Recurrence: a sequence {an} which a

nin terms of a

n-1, a

n-2,…

� Degree k: refer to k previous terms an-k

� Constant Coefficients: c1, c2, … independent from n

� The short name is “k-LiHoReCoCo”

∑=

−=k

i

iniac

1

19Ch. 4.1, 4.2 & 4.5

Solving Linear Recurrence Relations

Example

� Mn = Mn−1 + (1.11)Mn−1

� 1-LiHoReCoCo

� Pn = Pn−1 + Pn−2

� 2-LiHoReCoCo

� an = an-5

� 5-LiHoReCoCo

� an =an-1 + (an-2)2

� Not linear

� Hn = 2Hn−1 + 1

� Not homogeneous

� Bn = nBn-1

� Non-constant coefficient

(n is a variable)k-LiHoReCo Co

� Linear: the power of a ll a i term is one

� Homogeneous: no constant term (no team wi thout ai)

� Recurrence: a sequence {an} which an in terms of an-1 , an-2,…

� Degree k: refer to k previous terms an -k

� Constant Coefficients: c1, c2, … independent from n

20Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

� Given 2-LiHoReCoCo: an = c1an−1 + c2an−2

� Assume an = w1r1n + w2r2

n for n ≥ 0, r1 and r2 are different and some constants w1, w2

21Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

� Given 2-LiHoReCoCo: an

= c1a

n−1+ c

2a

n−2 , and

a0 = c and a1 = d

� Assume an = w1r1n + w2r2

n for

r1 and r2 are different and some constants w1, w2

an = w1r1n + w2r2

n

c1an-1 = c1(w1r1n-1 + w2r2

n-1)

c2an-2 = c2(w1r1n-2 + w2r2

n-2)

an - c1an−1 - c2an−2w1 (r1

n - c1r1n-1 - c2r1

n-2)

+ w2 (r2n - c1r2

n-1 - c2r2n-2)

=

w1 (r1n - c1r1

n-1 - c2r1n-2) + w2 (r2

n - c1r2n-1 - c2r2

n-2) = 0

Equal to 0

w1 r1n-2 (r1

2 - c1r1 - c2) + w2 r2n-2 (r2

2 - c1r2 - c2) = 0

22Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

� Assume w1, w2, r1 and r2 are not 0

� This formula is hold for any n, therefore,

w1 r1n-2 (r1

2 - c1r1 - c2) + w2 r2n-2 (r2

2 - c1r2 - c2) = 0

w1 r1n-2 (r1

2 - c1r1 - c2) + w2 r2n-2 (r2

2 - c1r2 - c2) = 0

w1 r1n-2

w2 r2n-2

(r12 - c1r1 - c2) + (r2

2 - c1r2 - c2) = 0

r12 - c1r1 - c2 = 0 r2

2 - c1r2 - c2 = 0and

an = w1r1n + w2r2

n

23Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

� If w1 and w2 are both 0,

� an is a special sequence and all values are 0

� If either w1 or w2 is 0, or either r1 or r2 is 0 (as r1 and r2 are different)

an = w1r1n + w2r2

n

w1 r1n-2 (r1

2 - c1r1 - c2) + w2 r2n-2 (r2

2 - c1r2 - c2) = 0

w1 r1n-2 (r1

2 - c1r1 - c2) = 0

w2 r2n-2 (r2

2 - c1r2 - c2) = 0

r12 - c1r1 - c2 = 0

r22 - c1r2 - c2 = 0

w1 or r1 is 0 (w2 and r2 are non-zero)

w2 or r2 is 0 (w1 and r1 are non-zero)

(w1 and r2) or (w2 and r1) is 0

an is a special sequence and all values are 0

24Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

� Given 2-LiHoReCoCo: an = c1an−1 + c2an−2 , and a0 = c and a1 = d

� Assume an = w1r1n + w2r2

n for r

1and r

2are different and some constants w

1, w

2

� We know that r1

2 - c1r

1- c

2= 0 and r

22 - c

1r

2- c

2= 0

� Characteristic Equation: r2 - c1r - c2 = 0

� Characteristic Roots: r1 and r2

� w1 and w2 can be calculated by using c and d

a0 = c = w1r10 + w2r2

0

a1 = d = w1r11 + w2r2

1

25Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

Theorem

� Consider an arbitrary 2-LiHoReCoCo:

an = c1an−1 + c2an−2

� By substituting an = rn, we have the characteristic equation:

r2 − c1r − c2 = 0

� If there has two different roots r1 and r2, then an = w1r1

n + w2r2n

for n ≥ 0 and some constants w1, w2

26Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

� Proof

Given r1, r2 are the characteristic root

where and w1, w2 are constants

�Two steps for the proof

1. Show if an = w1r1n + w2r2

n , {an} is a solution of the recurrence relation

2. Show if {an} is the solution of the recurrence

relation, an = w1r1n + w2r2

n

an = c1an−1 + c2an−2 an = w1r1n + w2r2

n⇔⇔⇔⇔

27Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

� Step 1Show if an = w1r1

n + w2r2n , {an} is a solution of the

recurrence relation

2211 −− + nnacac ( ) ( )2

22

2

122

1

22

1

111

−−−− +++= nnnnrwrwcrwrwc

( ) ( )221

2

22211

2

11 crcrwcrcrwnn +++= −−

2

2

2

22

2

1

2

11 rrwrrwnn −− +=

nnrwrw 2211 +=

na=

021

2 =−− crcrr1 and r2 are the so lu tion of

28Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

� Step 2Show if {an} is the solution of the recurrence relation, an = w1r1

n + w2r2n

� Suppose that {an} is a solution of the recurrence relation, and the initial conditions a0 = C0 and a1 = C1 hold

� We want to show that there are constants w1 and w2 such that the sequence {an} with an = w1r1

n + w2r2n satisfies these same initial

conditions

� a0 = C0 = w1 + w2 and a1 = C1 = w1r1 + w2r2

� By solving these two equations:

� When r1 ≠ r2, {an} with w1r1n + w2r2

n satisfy the 2 initial conditions

21

2011

rr

rCCw

−=

21

1202

rr

CrCw

−=

29Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

� We know that {an} and {α1r1n + α2r2

n} are both solutionsof the recurrence relation an = c1an−1 + c2an−2 and both

satisfy the initial conditions when n = 0 and n = 1

� Because there is a unique solution of 2-LiHoReCoCo

with two initial conditions, it follows that the two

solutions are the same, that is, an = α1r1n + α2r2

n for all nonnegative integers n

� We have completed the proof

30Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

Example 1� Solve the recurrence an = an−1 + 2an−2 given the initial

conditions a0 = 2, a1 = 7

� Characteristic Equation: r2 − r − 2 = 0

� Characteristic Root:

� r = (1 ± 3) / 2

� r = 2 or r = −1

� Therefore, an = w1 2n + w2 (−1)n

� By using a0 = 2, a1 = 7

� a0 = 2 = w120 + w2 (−1)0

� a1 = 7 = w121 + w2 (−1)1

� w1 = 3 and w2 = 1

� Therefore, an = 3·2n − (−1)n

a

acbbx

2

42 −±−

=

2-LiHoReCoCo: an = c1an−1 + c2an−2 ,

Characteristic Equation: r2 - c1r - c2 = 0

an = w1r1n + w2r2

n (r1 and r2 are different)

31Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

Example 2� Find an explicit formula for the Fibonacci numbers

� Recall fn = fn-1 + fn-2

� Characteristic equation: r2 - r - 1 = 0

� Characteristic roots:

� Initial conditions f0 = 0 and f 1 = 1

2/)51(1 +=r 2/)51(2 −=rnn

nwwf

−+

+=

2

51

2

5121

2100 wwf +==

−+

+==

2

51

2

511 211 wwf 5

12

−=w5

11=w

nn

nf

−−

+=

2

51

5

1

2

51

5

1

2-LiHoReCoCo: an = c1an−1 + c2an−2 ,

Characteristic Equation: r2 - c1r - c2 = 0

an = w1r1n + w2r2

n (r1 and r2 are different)

32Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos with two same roots

Theorem

� Let c1 and c2 be real numbers with c2 ≠ 0. Suppose that r2 – c

1r - c

2= 0 has only one

root r0

� A sequence {an} is a solution of the recurrence relation an = c1an-1 + c2an-2 if and only if an = w1r0

n + w2nr0n, for n = 0, 1, 2, ...,

where w1 and w2 are constants

33Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos with two same roots

Example 1� What is the solution of the recurrence relation

an = 6an-1 - 9an-2 with initial conditions a0 = 1 and a1 = 6?

� Characteristic equation: r2 - 6r + 9 = 0

� Only one characteristic root: r = 3

� Hence, the solution to this recurrence relation is

an = w13n + w2n3n

for some constants α1 and α2

� By using the initial conditions,

a0 = 1 = w1, a1 = 6 = 3w1 + 3w2, so w1=1 and w2 = 1

� Consequently, an = 3n + n3n

2-LiHoReCoCo: an = c1an−1 + c2an−2 ,

Characteristic Equation: r2 - c1r - c2 = 0

an = w1r0n + w2 n r0

n

34Ch. 4.1, 4.2 & 4.5

Solving 2-LiHoReCoCos

Summary

� Given : an = c1an−1 + c2an−2 and a0 = c and a1 = d

1. Characteristic equation: r2 − c1r − c2 = 0

2a. If Characteristic Root (r1 and r2) are different

1. an = w1r1n + w2r2

n is the solution

2. Use a0 = w1 + w2 = c and a1 = w1r1 + w2r2 = d to

solve w1 and w2

2b. If Characteristic Root (r 1 and r2) are the same

1. an = w1rn + w2 n rn is the solution

2. Use a0 = w1 = c and a1 = w1r1 + w2r2 = d to solve w1 and w2

35Ch. 4.1, 4.2 & 4.5

☺☺☺☺ Small Exercise ☺☺☺☺

� What is the solution of the recurrence relation a

n= - a

n + 6a

n-2with initial conditions a

0= 0

and a1 = 5?

� What is the solution of the recurrence relation an = - 2an - an-2 with initial conditions a0 = 5 and a1 = -6?

36Ch. 4.1, 4.2 & 4.5

☺☺☺☺ Small Exercise ☺☺☺☺

� the recurrence relation: an = - an + 6an-2

� Initial conditions a0 = 0 and a1 = 5

� Characteristic Equation:

� Characteristic Root:

� Therefore,

� Using the initial condition� a0 = 0 = w1 + w2

� a1 = 5 = -3w1 + 2w2

� w1 = -1, w2 = 1

� Therefore,

(r + 3)(r – 2) = 0r2 + r - 6 = 0

r1 = -3, r2 = 2

an = w1 (-3)n + w2 (2)n

an = - (-3)n + (2)n

37Ch. 4.1, 4.2 & 4.5

☺☺☺☺ Small Exercise ☺☺☺☺

� the recurrence relation: an = - 2an - an-2

� Initial conditions a0 = 5 and a1 = -6

� Characteristic Equation:

� Characteristic Root:

� Therefore,

� Using the initial condition� a0 = 5 = w1

� a1 = -6 = -w1 - w2

� w1 = 5 , w2 = 1

� Therefore,

(r + 1)(r + 1) = 0r2 + 2r + 1 = 0

r1 = -1

an = w1 (-1)n + w2 n (-1)n

an = 5 (-1)n + n (-1)n

38Ch. 4.1, 4.2 & 4.5

Solving k-LiHoReCoCos

� k-LiHoReCoCo:

� Characteristic Equation is:

� TheoremIf there are k distinct roots ri , then the solutions to the recurrence are of the form:

for all n ≥ 0, where the wi are constants

∑=

−=k

i

inin aca1

01

=−∑=

−k

i

ik

i

krcr

∑=

=k

i

n

iin rwa1

an = c1an−1 + c2an−2

r2 − c1r − c2 = 0

an = w1r1n + w2r2

n

2-kiHoReCoCo

39Ch. 4.1, 4.2 & 4.5

Solving k-LiHoReCoCos

Example� Find the solution to the recurrence relation

an = 6an-1 – 11an-2 + 6an-3

with the initial conditions a0 = 2, a1 = 5, and a2 = 15.

� The characteristic equation is:

r3 - 6r2 + 11r – 6 = (r - 1)(r - 2)(r - 3)� The characteristic roots are r = 1, r = 2, and r = 3

� an = w11n + w22

n + w33n

� By using the initial conditions� a0 = 2 = w1 + w2 + w3

� a1 = 5 = w1 + w2 x 2 + w3 x 3

� a2 = 15 = w1 + w2 x 4 + w3 x 9

� Therefore, w1 = 1, w2 = -1 and w3 = 2

� As a result, an = 1 - 2n + 2 x 3n

40Ch. 4.1, 4.2 & 4.5

Solving k-LiHoReCoCoswith same roots

� Let c1, c2, ..., ck be real numbers

� Suppose that the characteristic equation

rk – c1rk-1 – ··· – ck = 0

has t distinct roots r1, r2, ..., rt with multiplicities m1, m2, ..., mt

� i.e. ri appear mi times

� m1 + m2 + ·· · + m t = k

41Ch. 4.1, 4.2 & 4.5

Solving k-LiHoReCoCoswith same roots� A sequence {an} is a solution of the recurrence relation

� If and only if

for n = 0,1,2, ..., where wi,j

are constants for 1 ≤ i ≤ t and 0 ≤ j ≤ m

i-1

nm

mnrnwnwwa1

1

1,11,10,1)...( 1

1

−−+++=

nm

m rnwnww 2

1

1,21,20,2 )...( 2

2

−−++++

n

t

m

mttt rnwnww t

t)...(...

1

1,1,0,

−−+++++

∑ ∑=

=

=

t

i

n

i

m

j

j

ji rnwi

1

1

0

,

Special case for k=2, One distinct rootan = w1r0

n + w2nr0n

an = c1an-1 + c2an-2 + ... + ckan-k

No. of distinct roots

Multiplicities for ri

an = (w1 + w2n)r0n

42Ch. 4.1, 4.2 & 4.5

Solving k-LiHoReCoCos with same roots

Example� Find the solution to the recurrence relation

with the initial conditions

� Characteristic equation:

� Roots: −1, −1, −1, 2

� Therefore:

� By initial conditions:

4321253 −−−− +++−=

nnnnnHHHHH

210,1 3210 ==== ,HH,HH

0253234 =−−−+ xxxx

nn

ncncnccH 2)1)((

4

2

321+−++=

0 1 4

1 1 2 3 4

2 1 2 3 4

3 1 2 3 4

1

2 0

2 4 4 1

3 9 8 2

H c c

H c c c c

H c c c c

H c c c c

= + = = − − − + =

= + + + = = − − − + =

9

2,0,

3

1,

9

74321 ==−== cccc

nnn

n nH 29

2)1(

3

1)1(

9

7+−−−=

0)1)(2( 3 =+− xx

nm

mnrnwnwwa1

1

1,11,10,1)...( 1

1

−−+++=

nm

m rnwnww 2

1

1,21,20,2 )...( 2

2

−−++++

n

t

m

mtttrnwnww t

t

)...(...1

1,1,0,

−+++++

43Ch. 4.1, 4.2 & 4.5

Solving k-LiHoReCoCos

Summary

� Given : and ai = ci , where i = 1, 2, …, k

1.Characteristic equation:

2. Characteristic Root (r1, r2, …, rk)

1. is the solution of k-LiHoReCoCos

where m i is the multiplicity of ri

2. solve wi by ap = cp

where p = 1, 2, ..., k

01

=−∑=

−k

i

ik

i

krcr

∑=

−=k

i

inin aca1

∑ ∑=

=

=

t

i

n

i

m

j

j

jin rnwai

1

1

0

,

∑ ∑=

=

=

t

i

p

i

m

j

j

jirpw

i

1

1

0

,

44Ch. 4.1, 4.2 & 4.5

☺☺☺☺ Small Exercise ☺☺☺☺

� What is the solution of the recurrence relation a

n= a

n-1+ a

n-2- a

n-3with initial conditions a

0=

5, a1 = 5 and a2 = -6?

nm

mnrnwnwwa1

1

1,11,10,1)...( 1

1

−−+++=

nm

mrnwnww

2

1

1,21,20,2)...( 2

2

−−++++

n

t

m

mtttrnwnww t

t)...(... 1

1,1,0,

−−+++++

45Ch. 4.1, 4.2 & 4.5

☺☺☺☺ Small Exercise ☺☺☺☺

� the recurrence relation: an = an-1 + an-2 - an-3

� Initial conditions a0 = 5, a1 = 5 and a2 = -6

� Characteristic Equation:

� Characteristic Root:

� Therefore,

� Using the initial condition� a0 = 0 = c1 + c3

� a1 = 8 = c1 + c2 – c3

� a1 = 4 = c1 + 2c2 + c3

� c1 = 3, c2 = -3, c3 = 2

� Therefore,

(r – 1)(r – 1)(r + 1) = 0r3 – r2 – r + 1 = 0

r1 = 1, r2= 1, r3 = -1

an = (c1 + c2 n) (1)n + c3 (-1)n

an = 3 (1 – n) (1)n + 2 (-1)n

46Ch. 4.1, 4.2 & 4.5

Solving LiNoReCoCos

� Linear nonhomogeneous recurrence of degree k with constant coefficients(k-LiNoReCoCos) contain some terms F(n)

that depend only on n but not ai

� General form:

an = c1an−1 + … + cka

n−k + F(n)

Associated Homogeneo us Recurrence Relation

47Ch. 4.1, 4.2 & 4.5

Solving LiNoReCoCos

� If { } is a particular solution of the nonhomogeneous linear recurrence relation with constant coefficients

an = c1an-1 + c2an-2 + ... + ckan-k + F(n)

� Then every solution is of the form { }, where { } is a solution of the associated homogeneous recurrence relation

an = c1an-1 + c2an-2 + ... + ckan-k

)( p

na

)()( h

n

p

n aa +)(h

na

48Ch. 4.1, 4.2 & 4.5

Solving LiNoReCoCos

� Proof

� As { } is a particular solution for LiNoReCoCos

� Suppose that { } is an another solution

� { } is a solution of the associated homogeneous linear recurrence, named { }

� Consequently, for all n.

)(...)()(

22

)(

11

)(nFacacaca

p

knk

p

n

p

n

p

n ++++= −−−

)(...2211 nFbcbcbcb knknnn ++++= −−−

( ) ( ) ( ))()(

222

)(

111

)( ... p

knknk

p

nn

p

nn

p

nnabcabcabcab −−−−−− −++−+−=−

)( p

nn ab −)( h

na)()( h

n

p

nn aab +=

)( p

na

nb

)()(

22

)(

11

)(...

h

knk

h

n

h

n

h

n acacaca −−− +++=

49Ch. 4.1, 4.2 & 4.5

Solving LiNoReCoCos

Example 1

� Find all solutions to an = 3an−1+2n, which solution has a1 = 3?

� Notice this is a 1-LiNoReCoCo.

� Its associated 1-LiHoReCoCo

� an = 3an−1 and root is 3

� Solution is = c3n

� The solutions of LiNoReCoCo are in the form

)(h

na

)()( h

n

p

nn aaa +=

an = 3an−1+2n

a1= 3

Next step

50Ch. 4.1, 4.2 & 4.5

Solving LiNoReCoCos

Example

� If F(n) is a degree-u polynomial in n, a degree-upolynomial should be tried as the particular solution

� Now, F(n) = 2n

� Try = cn + d, c and d are constants

� Solution is: = -n – 3/2

an = 3an-1 + 2n

cn+d = 3(c(n−1)+d) + 2n

(2c+2)n + (3c−2d) = 0

c = −1 and d = −3/2

)( p

na

)( p

na

)( p

na

an = 3an−1+2n

a1= 3

51Ch. 4.1, 4.2 & 4.5

Solving LiNoReCoCos

Example

� Therefore, we have

� By using a1 = 3

� 3 = -1 - 3/2 + 3c

� c = 11/6

� As a result,

)()( h

n

p

nnaaa +=

nh

nca 3

)( =

( ) 3

2

p

na n= − −

33

2

nn c= − − +

6

311

2

3n

nna

⋅++−=

an = 3an−1+2n

a1= 3

52Ch. 4.1, 4.2 & 4.5

� Suppose {an} satisfies the LiNoReCoCo

where ci (i = 1,2,…k) are real numbers and

where b0, b

1, …, b

tand s are real numbers

� When s is not a root of the characteristic equation of the associated li near homogeneous RR, there is a particular solution( ) of the form

� When s is a root of the characteristic equation of the associated linear homogeneo us RR with multiplicity m, there is a particular solution ( ) of the form

)(1

nFacak

i

inin+

= ∑

=−

nt

t

t

t sbnbnbnbnF )...()( 01

1

1 ++++= −−

nt

t

t

tspnpnpnp )...(

01

1

1++++ −

nt

t

t

t

m spnpnpnpn )...(01

1

1++++ −

Solving LiNoReCoCos

Particular Solution

)( p

na

)( p

na

53Ch. 4.1, 4.2 & 4.5

� F(n) = 3n

� F(n) = n3n

� F(n) = n22n

� F(n) = (n2 + 1)3n

� Consider the associated ho mogeneous RR:

an

= 6an-1

- 9an-2

� Characteristic Equation

� Characteristic Root is 3, of multiplicity m=2

Solving LiNoReCoCos : Particular Solution

Example 1� What form does a particular solution of the linear

nonhomogeneous recurrence relation an = 6an-1 - 9a

n-2+F(n) have when ...

0)3(9622 =−=+− rrr

npn 3)(

0

2

npnpn 3)(

01

2 +

npnpnp 2)(

01

2

2++

npnpnpn 3)(

01

2

2

2 ++

nt

t

t

tspnpnpnp )...(

01

1

1++++ −

nt

t

t

t

m spnpnpnpn )...(01

1

1++++ −

s is not a root

s is a root

nt

t

t

tsbnbnbnbnF )...()(

01

1

1++++= −

54Ch. 4.1, 4.2 & 4.5

Solving LiNoReCoCos : Particular Solution

Example 2� Let an be the sum of the first n positive integers, so that

� an satisfies the linear nonhomogeneous RR

� Associated linear homogeneous RR is an = an-1

� Root is 1. The solution is , c is a constant

� Since F(n) = n = n x (1)n, and s = 1 is a root of degree one of the characteristic equation of the associated linear homogeneous RR

� So the particular solution has the form n(p1n+p0)

nh

n ca )1()( =

∑=

=n

k

n ka1

nt

t

t

t spnpnpnp )...( 01

1

1 ++++ −−

nt

t

t

t

mspnpnpnpn )...( 01

1

1 ++++ −−

s is not a root

s is a root

ntt

tt sbnbnbnbnF )...()( 01

11 ++++= −−

an

= an-1

+ n

55Ch. 4.1, 4.2 & 4.5

Solving LiNoReCoCos : Particular Solution

Example 2

� By solving p1n2 + p0n = p1 (n - 1)2 + p0(n - 1) + n

� We have p0 = p1 =1/2

� Recall,

� By using a1 = 1, so c = 0

� Therefore,

2

)1( +=

nna

n

)()( h

n

p

nnaaa +=

cnnan

++= 2/)1(ca h

n=)(

2/)1()( += nna

p

n

an = an-1 + n( )

1 0( )p

na n p n p= +

56Ch. 4.1, 4.2 & 4.5

Solving Linear Recurrence Relations

Summary� k-LiHoReCoCos with m same roots (without F(x))

� Find the root of characteristic equation

� Use initial terms to find alphas

� k-LiNoReCoCos with m same roots (with F(x))

� Find the solution of charac teristic equationof Associated linear homogeneo us RR

� Find the particular solution of LiNoReCoCo using

� Fina lly

� Use initial terms to find alphas

nm

mnrnna1

1

1,11,10,1)...( 1

1

−−+++= ααα

nm

mrnn2

1

1,21,20,2)...( 2

2

−−++++ ααα

n

t

m

mttt rnn t

t)...(...

1

1,1,0,

−−+++++ ααα

nt

t

t

t

mspnpnpnpn )...( 01

1

1 ++++ −−

)()( h

n

p

n aa +

=)( p

na

)(h

na

57Ch. 4.1, 4.2 & 4.5

☺☺☺☺ Small Exercise ☺☺☺☺

� Find all solutions to an = 7an−1+(2n2+2)3n, which solution has a1 = 10?

58Ch. 4.1, 4.2 & 4.5

☺☺☺☺ Small Exercise ☺☺☺☺

� Its associated 1-LiHoReCoCo� an = 7an−1 and root is 7

� Solution is = c7n

� The solutions of 1-LiNoReCoCo are in the form

� Need to do is find one

)(h

na

)()( h

n

p

nn aaa +=

)( p

na

an = 7an−1+(2n2+2)3n

a0 = 10

59Ch. 4.1, 4.2 & 4.5

☺☺☺☺ Small Exercise ☺☺☺☺

� Now, F(n) = (2n2+2)3n

� = (an2 + bn + c)3n

an = 7an-1 + (2n2+2)3n

)( p

na

(an2+bn+c)3n = 7(a(n-1)2+b(n-1)+c)3n-1 + (2n2+2)3n

3an2+3bn+3c = 7an2 - 14an + 7a + 7bn – 7b + 7c + 6n2 + 6

0 = n2(4a+6)+n(4b-14a) +(4c +7a-7b+6 )

4c +7a-7b+6=04b-14a=04a+6=0

a=-3/2 b=-21/4 c=-129/16

np

n nna 3)6/1294/212/3(2)( −−−=

an = 7an−1+(2n2+2)3n

a0 = 10

0 = 4an2 - 14an + 7a + 4bn – 7b + 4c + 6n2 + 6

60Ch. 4.1, 4.2 & 4.5

☺☺☺☺ Small Exercise ☺☺☺☺

� Therefore, we have

� By using a0 = 10

� a0 = 10 = -129/6 + c

� c = 189/6

� As a result,

)()( h

n

p

nn aaa +=nh

nca 7

)( =nn cnn 73)6/1294/212/3( 2 +−−−=

6/71893)6/1294/212/3(2 nn

nnna ⋅+−−−=

np

nnna 3)6/1294/212/3(

2)( −−−=

an = 7an−1+(2n2+2)3n

a0 = 10

61Ch. 4.1, 4.2 & 4.5

Generating Functions

� Generating functions ( G(x) ) are used to represent sequences efficiently by coding the terms of a sequence as coefficients of powers of a variable x in a formal power series

� Generating function for the sequence

a0, a1, a2, …, ak, … of real numbers is the infinite series

0 1

0

0 1( )k

k k

k kG x x x xa a a xa∞

=

= + + + + =∑⋯ ⋯

62Ch. 4.1, 4.2 & 4.5

Example

� What is the generating function for the

following sequence?

� {0, 2, …, 2k,…}

� {1, 1, 1, 1, 1}

∑∞

=0

2k

kkx

∑=

4

0k

kx1 + x + x2 + x3 + x4 =

0 + 2x + … + 2k · xk + … =

63Ch. 4.1, 4.2 & 4.5

Useful Facts About Power Series

is generating functionof the sequence 1,1,1,1, ...

is generating functionof the sequence 1, a, a2, a3, ...

� Recall, in Chapter 2.4,

( )x

xf−

=1

1 ( )ax

xf−

=1

1

∑∞

=0k

kx ∑

=0k

kkxa

x−=

1

1

ax−=

1

1

64Ch. 4.1, 4.2 & 4.5

Useful Facts About Power Series

� Given: ( ) ∑∞

=

=0k

k

k xaxf ( ) ∑∞

=

=0k

k

k xbxg

( ) ( )=+ xgxf

( ) ( )=xgxf

( )∑∞

=

+0k

k

kk xba

( )∑∑∞

= =−=

0 0k

k

j

k

jkj xba

∑∑∞

=

= 00 k

k

k

k

k

k xbxa

...)...)((1

1

0

0

1

1

0

0 ++++= xbxbxaxa

+++ )()( 0110

1

00

0babaxbax=

...)( 021120

2 +++ bababax00ba 0110 baba +

021120 bababa ++

65Ch. 4.1, 4.2 & 4.5

Useful Facts About Power Series

Example

� Let ,

� Find the coefficients a0, a1, a2, ... in the expansion

∑∞

==

0)(

k

k

kxaxh

2)1(

1)(

xxh

−=

( ) ∑∞

=

=−

=01

1

k

kx

xxf

( ) ∑∞

=

=0k

k

kxaxf ( ) ∑

=

=0k

k

kxbxg

( ) ( ) ( )∑∞

=

+=+0k

k

kkxbaxgxf

( ) ( ) ( )∑∑∞

= =−=

0 0k

k

j

k

jkjxbaxgxf

)(xh)1(

1

)1(

1

xx −−=

2)1(

1

x−=

0 0

kk

k j

x∞

= =

=∑∑

∑∞

=

+=0

)1(k

kxkak=k+1

0 0

k k

k k

x x∞ ∞

= =

= ∑ ∑

66Ch. 4.1, 4.2 & 4.5

Extended Binomial Coefficient

� Recall, the binomial coefficient,

where n is a nonnegative integer and r is an integer with 0 ≤ r ≤ n

� The extended binomial coefficients is defined by replacing nonngeative integer n by real number u

!

)1)...(1(

r

rnnn +−−=

)!(!

!

rnr

n

−=

r

n

67Ch. 4.1, 4.2 & 4.5

Extended Binomial Coefficient

Example

� Find the values of the extended binomial coefficients

3

2

3

2/1

!

)1)...(1(

r

rnnn

r

n +−−=

3

5 ( ) ( )123

25155

⋅⋅

−⋅−⋅= 10=

( ) ( )123

22122

⋅⋅

−−⋅−−⋅−= 4−=

( ) ( ) ( )123

22/112/12/1

⋅⋅

−−⋅−−⋅−=

16

1=

(Standard binomial coefficients)

68Ch. 4.1, 4.2 & 4.5

Extended Binomial Coefficient

� When the top parameter is a negative integer, the extended binomial coefficient can be expressed in terms of an ordinary binomial coefficient

r

n ( )( ) ( )!

11

r

rnnn +−−⋅⋅⋅−−−=

( ) ( )( ) ( )!

111

r

rnnnr −+⋅⋅⋅+−

=

( ) ( )( ) ( )!

211

r

nrnrnr ⋅⋅⋅−+−+−

=

( )

−+−=

r

rnr 11

69Ch. 4.1, 4.2 & 4.5

Extended Binomial Theorem

� Recall, the ordinary binomial theorem

� Extended binomial theorem

where x is a real number with |x|<1, u is a real number

k

k

u xk

ux ∑

=

=+

0

)1(

( )nyx+ jjn

n

j

yxj

n −

=∑

=

0

70Ch. 4.1, 4.2 & 4.5

Extended Binomial Theorem

Example

� Find the generating functions for (1+x)-n and (1-x)-n, where n is a positive integer, using the extended binomial theorem.

nx

−− )1(

nx

−+ )1(

( )kk

xk

n−

−=∑

=0

k

k

xk

n∑∞

=

−=

0

∑∞

=

−+=0

),1(k

kxkknC

∑∞

=

−+−=0

),1()1(k

kkxkknC

r

n ( )

−+−=

r

rnr 11∑

=

=0

)(k

k

k xaxG

ak

k

k

u xk

ux ∑

=

=+

0

)1(

71Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions� How can we solve the counting problems,

including the recurrence relation, by using the Generating Functions?

0 1

0

0 1( )k

k k

k kG x x x xa a a xa∞

=

= + + + + =∑⋯ ⋯

72Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 1� Find the number of solutions of e1 + e2 + e3 = n when n = 17,

where e1 ,e2, e3 are nonnegative integers with 2 ≤≤≤≤ e1 ≤≤≤≤ 5, 3 ≤≤≤≤ e2 ≤≤≤≤ 6, 4 ≤≤≤≤ e3 ≤≤≤≤ 7

� By considering this generating function for the sequence {an}, where an is the number of solution for n

� As n = 17, a17, which is the coefficient of x17, is the solution

� Answer is 3

=∑∞

=0k

k

kxa

⋅+++ )( 5432 xxxx

⋅+++ )(6543

xxxx

)(7654

xxxx +++

73Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 2

� In how many different ways can eight identical cookies be distributed among three distinct childrenif each child receives at least two cookies and no more than four cookies?

� By considering this generating function for the sequence {an}, where an is the number of solution for n

� The coefficient of x8 is 6

))()((432432432

xxxxxxxxx ++++++=∑∞

=0k

k

kxa

74Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 3

� Use generating functions to determine the number of ways to insert tokens worth $1, $2, and $5 into a vending machine to pay for an item that costs r dollars in both the cases when the order in which

� the order of inserting tokens does not matter

� the order does matter

� For example,

� Item that costs $3

� Order does not matter (2)

� Three $1 tokens

� $1 token and $2 token

� Order does matter (3)

� Three $1 tokens

� $1 token and a $2 token

� $2 token and a $1 token

75Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 3

� Order does not matter

� By considering:

� $1:

� $2:

� $5:

� The answer is the coefficient of xr in

...)(321 +++ xxx

...)(642 +++ xxx

...)( 15105 +++ xxx

1 2 3

2 4 6

5 10 15

( . ..)( . ..)( ...)

x x xx x xx x x

+ + + ⋅+ + + ⋅+ + +

=∑∞

=0k

k

kxa

76Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 3

� Order does matter

� The number of ways to insert n tokens to produce a total of r dollars is the coefficient of xr in

� Answer is the coefficient of xr in

nxxx )( 521 ++

xx

k

k

−=∑

= 1

1

0

1 2 5

0

( )n

n

x x x∞

=

= + +∑

)(1

152

xxx ++−=

521

1

xxx −−−=

1 2 5 1 2 5 21 ( ) ( ) ...x x x x x x+ + + + + + +

E.g. r = 5

1 2 5 2( )x x x+ +

1 2 5 3( )x x x+ +1 2 5 4

( )x x x+ +1 2 5 5

( )x x x+ +

11 2 5

( )x x x+ +

0

3

4

1

Coef. of x5

=∑∞

=0k

k

kxa

77Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 4� Use generating functions to find the number of ways

to select r objects of n different kinds if we must select at least one object of each kind.

� Each kind of objects contributes

to generating function G(x) for the sequence {xr}, where xr is the number of ways to select r objects of n different kinds

� Hence, there are n kinds:

At least one object of each kind

nxxx ...)( 321 +++=

...)(321 +++ xxx

)(xGnn xxx ...)1( 21 +++=

n

n

x

x

)1( −=

78Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 4

)(xGnn xx )1/( −=

(1 )n nx x −= −

r

r

nx

r

nx )(

0

−= ∑

=

rr

r

rnxrrnCx )()1(),1()1(

0

−−+−= ∑∞

=

rn

r

xrrnC+

=∑ −+= )(),1(

0

t

nt

xnttC )(),1(∑∞

=

−−=

r

nr

xnrrC )(),1(∑∞

=

−−=

There are C(r - 1, r - n) ways

to select r objects of n different kinds if we must

select at least one object of

each kind.

Extended binomial theore m

k

k

ux

k

ux ∑

=

=+

0

)1(

r

n( )

−+−=

r

rnr 11

79Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 5

� Solve the recurrence relation ak = 3ak-1 for k=1, 2, 3,

… and initial condition a0=2

� Let G(x) be the generating function for the sequence {ak}, that is

∑∞

=

=0

)(k

k

kxaxG

0

1

( ) k

k

k

G x a a x∞

=

= +∑

0 1

1

( ) 3 k

k

k

G x a a x∞

−=

= +∑1

0 1

1

( ) 3 k

k

k

G x a x a x∞

−−

=

= + ∑

0( ) 3 ( )G x a xG x= +

2( )

1 3G x

x=

0

( ) 2 3k k

k

G x x∞

=

= ⋅∑

∑∞

=0k

kk xaax−

=1

1

2 3k

ka = ⋅

80Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 6

� The sequence {an} satisfies the recurrence relation

an

= 8an-1 + 10n -1

and the initial condition a1 = 9

� Use generating functions to find an explicit formula for an

81Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 6

a0 = 1

a1

= 8a0

+ 101-1 = 90

( )n

n

n

G x a x∞

=

=∑

0

1

( ) n

n

n

G x a a x∞

=

= +∑1

0 1

1

( ) (8 10 )n n

n

n

G x a a x∞

−−

=

= + +∑1

0 1

1 1

( ) 8 10n n n

n

n n

G x a a x x∞ ∞

−−

= =

= + +∑ ∑ 0

1

1

k k

k

a xax

=

=−

1 1 1

0 1

1 0

( ) 8 10n n n

n

n n

G x a x a x x x∞ ∞

− − −−

= =

= + +∑ ∑

0( ) 8 ( )

1 10

xG x a xG x

x= + +

an = 8an-1 + 10n-1 a1 = 9

82Ch. 4.1, 4.2 & 4.5

Counting Problems and Generating Functions

Example 6

1 9( )

(1 8 )(1 10 )

xG x

x x

−=

− −

1 1 1

2 1 8 1 10x x

= + − −

0 0

18 10

2

n n n n

n n

x x∞ ∞

= =

= +

∑ ∑

( )0

18 10

2

n n n

n

x∞

=

= +∑ ( )18 10

2

n n

na = +

0( ) 8 ( )1 10

xG x a xG x

x= + +

−a0 = 1

0

1

1

k k

k

a xax

=

=−