Transcript dmi11.ppt

 4.6.2 Exponential generating functions
 The number of r-combinations of multiset
S={n1·a1,n2·a2,…, nk·ak} : C(r+k-1,r),
 generating function:

 C (k  r
 1, r ) y r
r 0
1

(1  y ) k
The number of r-permutation of set S={a1,a2,…,
ak} :p(n,r),

generating function:
r
p
(
n
,
r
)
y

r 0

r
(
ax
)
ax
 C(n,r)=p(n,r)/r!
e 
r!
r 0
n
n
r
x
(1  x ) n   C (n, r ) x r   p(n, r )
r!
r 0
r 0
n
xr
 ar r!
r 0
Definition 2: The exponential generating
function for the sequence a0,a1,…,an,…of real
numbers is the infinite series

an n
ar r
a2 2
f ( x )   x  a0  a1 x  x   
x 
2!
n!
r  0 r!
 Theorem 4.17: Let S be the multiset
r! n ,n ,…,n are non{n
·a
,n
·a
,…,n
·a
}
where
k k
1 2
k
(21) 1 2 2
negative
integers. Let br
be m
the!number of rm1  m2 mk  r m1! m2 !
k
permutations
of S. Then the exponential generating
mi  0
function g(x) for the sequence b1, b2,…, bk,… is given
is the number of r - permutatio ns of S
by
 g(x)=gn1(x)·g n2(x)·…·gnk(x),where for i=1,2,…,k,
 gni(x)=1+x+x2/2!+…+xni/ni! .
 (1)The coefficient of xr/r! in gn1(x)·g n2(x)·…·gnk(x) is


m1  m2 mk
mi  0
r!
 r m1! m2 ! mk !
 Example: Let S={1·a1,1·a2,…,1·ak}.
Determine the number r-permutations of S.
 Solution: Let pr be the number rpermutations of S, and
g ( x )  (1  x ) k 
k
 C ( n, r ) x r
r 0
k
n!

xr
r  0 r! ( n  r )!
k
n! x r

r  0 ( n  r )! r!
 Example: Let S={·a1,·a2,…,·ak},
Determine the number r-permutations of S.
 Solution: Let pr be the number rpermutations of S,
 gri(x)=(1+x+x2/2!+…+xr/r!+…),then
 g(x)=(1+x+x2/2!+…+xr/r!+…)k=(ex)k=ekx


r
(kx) r
x

 k r
r!
r  0 r!
r 0
 Example:Let S={2·x1,3·x2},Determine the
number 4-permutations of S.
 Let pr be the number r-permutations of S,
 g(x)=(1+x+x2/2!)(1+x+x2/2!+x3/3!)
 Note: pr is coefficient of xr/r!.
 Example:Let S={2·x1,3·x2,4·x3}. Determine the
number of 4-permutations of S so that each of the 3
types of objects occurs even times.
 Solution: Let pr be the number r-permutations of S,
 g(x)=(1+x2/2!)(1+x2/2!)(1+x2/2!+x4/4!)
 Example: Let S={·a1,·a2, ·a3},
Determine the number of r-permutations of S
so that a3 occurs even times and a2 occurs at
least one time.
 Let pr be the number r-permutations of S,
 g(x)=(1+x+x2/2!+…+xr/r!+…)(x+x2/2!+…+xr/r!
+…) (1+x2/2!+x4/4!+…)=ex(ex-1)(ex+e-x)/2
 =(e3x-e2x+ex-1)/2
n
1  n
x
  (3  2n  1)
2 n1
n!
 Example: Let S={·a1,·a2, ·a3},
Determine the number of r-permutations of S
so that a3 occurs odd times and a2 occurs at
least one time.
 Let pr be the number r-permutations of S,
 g(x)=(1+x+x2/2!+…+xr/r!+…)(x+x2/2!+…+xr/r!
+…) (x+x3/3!+x5/5!+…)
 =ex(ex-1)(ex-e-x)/2
4.7 Recurrence Relations
 P13, P100
 Definition: A recurrence relation for the sequence{an}
is an equation that expresses an in terms of one or
more of the previous terms of the sequence, namely,
a0, a1, …, an-1, for all integers n with nn0, where n0
is a nonnegative integer.
 A sequence is called a solution of a recurrence
relation if its terms satisfy the recurrence relation.
 Initial condition: the information about the
beginning of the sequence.
 Example(Fibonacci sequence):
 13 世纪初意大利数学家 Fibonacci 研究过著名的兔
子繁殖数目问题
 A young pair rabbits (one of each sex) is placed in
enclosure. A pair rabbits dose not breed until they
are 2 months old, each pair of rabbits produces
another pair each month. Find a recurrence relation
for the number of pairs of rabbits in the enclosure
after n months, assuming that no rabbits ever die.
 Solution: Let Fn be the number of pairs of rabbits
after n months,
 (1)Born during month n
 (2)Present in month n-1
 Fn=Fn-2+Fn-1,F1=F2=1
 Example (The Tower of Hanoi): There are three pegs
and n circular disks of increasing size on one peg, with
the largest disk on the bottom. These disks are to be
transferred, one at a time, onto another of the pegs,
with the provision that at no time is one allowed to
place a larger disk on top of a smaller one. The
problem is to determine the number of moves
necessary for the transfer.
 Solution: Let h(n) denote the number of moves needed
to solve the Tower of Hanoi problem with n disks.
h(1)=1
 (1)We must first transfer the top n-1 disks to a peg
 (2)Then we transfer the largest disk to the vacant peg
 (3)Lastly, we transfer the n-1 disks to the peg which
contains the largest disk.
 h(n)=2h(n-1)+1, h(1)=1
 Using Characteristic roots to solve recurrence
relations
 Using Generating functions to solve
recurrence relations
4.7.1 Using Characteristic roots to solve
recurrence relations
 Definition: A linear homogeneous recurrence
relation of degree k with constant coefficients is a
recurrence relation of the form
 an=h1an-1+h2an-2+…+hkan-k, where hi are constants
for all i=1,2,…,k,n≥k, and hk≠0.
 Definition: A linear nonhomogeneous recurrence
relation of degree k with constant coefficients is a
recurrence relation of the form
 an=h1an-1+h2an-2+…+hkan-k+f(n), where hi are
constants for all i=1,2,…,k,n≥k, and hk≠0.
 Definition: The equation xk-h1xk-1-h2xk-2-…-hk=0 is
called the characteristic equation of the recurrence
relation an=h1an-1+h2an-2+…+hkan-k. The solutions
q1,q2,…,qk of this equation are called the
characteristic root of the recurrence relation, where
qi(i=1,2,…,k) is complex number.
 Theorem 4.18: Suppose that the characteristic
equation has k distinct roots q1,q2,…,qk. Then the
general solution of the recurrence relation is
 an=c1q1n+c2q2n+…+ckqkn, where c1,c2,…ck are
constants.












Example:
the
relation
5 3  Solve
1
5 recurrence
3 1
c1 
c2 
an=2an-1
6 +2a
3 n-2,(n≥2)
6 3
subject5to3the
 1 initial nvalues
5 3 a11=3 and na2=8.
an 
(1  3 ) 
(1  3 )
characteristic
equation
:
6 3
6 3
x2-2x-2=0,
roots:
q1=1+31/2,q2=1-31/2。
the general solution of the recurrence relation is
an=c1(1+31/2)n+c2(1-31/2)n,
We want to determine c1 and c2 so that the initial values
c1(1+31/2)+c2(1-31/2)=3,
c1(1+31/2)2+c2(1-31/2)2=8
 Theorem 4.19: Suppose that the characteristic
equation has t distinct roots q1,q2,…,qt with
multiplicities m1,m2,…,mt, respectively, so
that mi≥1 for i=1,2,…,t and m1+m2+…+mt=k.
Then the general solution of the recurrence
relation is
t
mi
a n   cij n j 1 qin
i 1 j 1
where cij are constants for 1≤j≤mi and 1≤i≤t.















Example: Solve the recurrence relation
an+an-1-3an-2-5an-3-2an-4=0,n≥4
subject to the initial values a0=1,a1=a2=0, and a3=2.
characteristic equation
x4+x3-3x2-5x-2=0,
roots:-1,-1,-1,2
By Theorem 4.19:the general solution of the recurrence
relation is
an=c11(-1)n+c12n(-1)n+c13n2(-1)n+c212n
We want to determine cij so that the initial values
c11+c21=1
-c11-c12-c13+2c21=0
c11+2c12+4c13+4c21=0
-c11-3c12-9c13+8c21=2
c11=7/9,c12=-13/16,c13=1/16,c21=1/8
an=7/9(-1)n-(13/16)n(-1)n+(1/16)n2(-1)n+(1/8)2n
 the general solution of the linear nonhomogeneous
recurrence relation of degree k with constant
coefficients is
 an=a'n+a n*
 a'n is the general solution of the linear homogeneous
recurrence relation of degree k with constant
coefficients an=h1an-1+h2an-2+…+hkan-k
 a n*is a particular solution of the nonhomogeneous
linear recurrence relation with constant coefficients
 an=h1an-1+h2an-2+…+hkan-k+f(n)
 Theorem 4.20: If {a n*} is a particular solution
of the nonhomogeneous linear recurrence
relation with constant coefficients
 an=h1an-1+h2an-2+…+hkan-k+f(n),
 then every solution is of the form {a'n+a n*},
where {a n*} is a general solution of the
associated homogeneous recurrence relation
an=h1an-1+h2an-2+…+hkan-k.
 Key:a n*









(1)When f(n) is a polynomial in n of degree t,
a n*=P1nt+P2nt-1+…+Ptn+Pt+1
where P1,P2,…,Pt,Pt+1 are constant coefficients
(2)When f(n) is a power function with constant
coefficient n, if  is not a characteristic root of the
associated homogeneous recurrence relation,
a n*= Pn ,
where P is a constant coefficient.
if  is a characteristic root of the associated
homogeneous recurrence relation with multiplicities
m,
a n*= Pnmn ,where P is a constant coefficient.
Example: Find all solutions of the recurrence
relation an+2an-1=n+1,n1, a0=2
 Example: Find all solutions of the recurrence
relation h(n)=2h(n-1)+1, n2, h(1)=1
 Example: Find all solutions of the recurrence
relation
 an=an-1+7n,n1, a0=1
 If let an*=P1n+P2,
 P1n+P2-P1(n-1)-P2=7n
 P1=7n
 Contradiction
 let an*=P1n2+P2n
4.7.2 Using Generating functions to solve
recurrence relations
f ( x) 

n
a
x
 n
n 0
Example: Solve the recurrence relation
an=an-1+9an-2-9an-3,n≥3
subject to the initial values a0=0, a1=1, a2=2




Example: Solve the recurrence relation :
an=an-1+9an-2-9an-3,n≥3
subject to the initial values a0=0, a1=1, a2=2
Solution:
Let Generating
functions
of {an}
a0=0,a1=1, a2=2,and
when n≥3,an-a
n-1-9an-2+9an-3=0,
(an=an-1+9an-2-9an-3)
be:
thus: +a x+a x2+…+a xn+… , then:
 f(x)=a
2
n
2
(1-x-9x20+9x13)f(x)=x+x
2-a x3…-a xn+1-…
 -xf(x)
=-a
x-a
x
2
2
0
1 3) 2
n
f(x)=(x+x )/(1-x-9x
+9x
2f(x)
2)/((1-x)(1+3x)(1-3x))
 -9x
=
-9a0x2-9a1x3-9a2x4-…-9an-2xn-…
=(x+x
1 1
13+9a x41+…+9a
1
n+…
 9x3f(x)
=  1 9a0x
x
1
n-3

1  2x+9x312
1  +(a
3 x -a )x+(a
3 1  -a
3 x-9a )x2+
 ( 1 4
- x-9x
)f(x)=a
0
1 0
2 1
0
2
n
1
1
1 n
n
n
1/(1-x)=1+x+x
+…+x
+…;
3
n
 +9a
  n-3()x
1) +…
3  3
(a3-a2-9a1+9a0)x +…+(an-an-1-9aann-2
4 12
3
1/(1+3x)=1-3x+32x2-…+(-1)n3nxn+…
n 1
2
2
n
n
1
3
1/(1-3x)=1+3x+3 x +…+3 x +…;    ( 1) n
 3n 1
4
4

 Example:
Find an explicit
x
1 formula
1 5 n
1for
5 nthe


(( 2 )  ( 2 ) ) x n
5
( x Fibonacci
 1 5 )( x  1numbers,
)
n 0 5
2
2
 Fn=F
+F
,
n-2
n-1
1
1 5 n
1 5 n
1
1
F

((
)

(


1

1


1 F1=F2=1。
n
2
2 ) )
5
5 
5
  Solution:

Let Generating
functions of {Fn} be:
1

5
1

5


1n 5
1 5 n
2
x

x

2
|
|

1
,
hence
(
 f(x)=F20+F1x+F2x2 +…+F

2 ) 0
nx 2+…,then: lim
-…
 -xf(x)
=-F0x-F1x2-F2x3…-Fnxnn+1


n
1n 5
1
1 -x2f(x)1
1 x2-FFx3-Fx4-…-F

=-F
x
-…
(
)
0
1 n 2


5 n-2 2
2
3
5 2)f(x)=F
1 x+(F
5
 5(  11  -1 x-x
x
1

1 x  2-F1)x +(F3-F2-F1)x +(F4-F32
2
 n+…
Fn
1
5
F2)xF4+…+(F
-F
-F
)x
n2 n-1 n-2

n 1
Thus


0
.
618
 F1=1, F2=1,and when n≥3,F
Fn 
2
n-F
n-1-Fn-2=0,
1
Fn
1

5
 (Fn=Fn-1+Fn-2)
thus:
F n-1
0.618F
n。
2
 (1-x-x )f(x)=x
golden
section黄金分割
。
2)
 f(x)=x/(1-x-x
 Exercise P104 18,20,23.Note: By Characteristic roots,
solve recurrence relations 23; By Generating functions,
solve recurrence relations 18,20.
 1.Determine the number of n digit numbers with all
digits at least 4, such that 4 and 6 each occur an even
number of times, and 5 and 7 each occur at least once,
there being no restriction on the digits 8 and 9.
 2.a)Find a recurrence relation for the number of ways
to climb n stairs if the person climbing the stairs can
take one stair or two stairs at a time. b) What are the
initial conditions?
 3.a) Find a recurrence relation for the number of
ternary strings that do not contain two consecutive 0s.
b) What are the initial conditions?