0% found this document useful (0 votes)
143 views36 pages

Discrete Mathematics: Advanced Counting Techniques

The document discusses advanced counting techniques and recurrence relations. It begins by providing examples of recurrence relations, their applications, and ways to model problems using recurrence relations. It then discusses methods for solving linear homogeneous recurrence relations with constant coefficients, including finding the characteristic equation and its roots to determine the general solution. The document provides several examples of solving recurrence relations of different degrees. It concludes by stating a general theorem for solving recurrence relations where the characteristic equation has roots with multiplicities.

Uploaded by

anasuriraju
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
143 views36 pages

Discrete Mathematics: Advanced Counting Techniques

The document discusses advanced counting techniques and recurrence relations. It begins by providing examples of recurrence relations, their applications, and ways to model problems using recurrence relations. It then discusses methods for solving linear homogeneous recurrence relations with constant coefficients, including finding the characteristic equation and its roots to determine the general solution. The document provides several examples of solving recurrence relations of different degrees. It concludes by stating a general theorem for solving recurrence relations where the characteristic equation has roots with multiplicities.

Uploaded by

anasuriraju
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 36

Discrete

Mathematics

Chapter 7
Advanced Counting Techniques

大葉大學 資訊工程系 黃鈴玲


7.1 Recurrence Relations( 遞迴關
係)
Example 1. Let {an} be a sequence that satisfies
the recurrence relation an=an1an2 for n=2,3,…, and
suppose that a0=3,and a1=5.
Here a0=3 and a1=5 are the initial conditions.
By the recurrence relation,
a2 = a1a0 = 2
a3 = a2a1 = 3
a4 = a3a2 = 5
:
Q1: Applications ?
Q2: Are there better ways for computing the terms of
{an}? Ch7-2
※Modeling with Recurrence Relations
We can use recurrence relations to model (describe) a
wide variety of problems.
Example 3. Compound Interest ( 複利 )
Suppose that a person deposits( 存款 ) $10000 in
a saving account at a bank yielding 11% per year with
interest compounded annually.
How much will be in the account after 30 years ?
Sol : Let Pn denote the amount in the account
after n years.
Pn=Pn1 + 0.11Pn1=1.11  Pn1, P0=10000
∴ P30=1.11  P29=(1.11)2  P28=…=(1.11)30  P0
=228922.97 Ch7-3
Example 5. (The Tower of Hanoi)
The rules of the puzzle allow disks to be moved one at a time
from one peg to another as long as a disk is never placed on top
of a smaller disk. Let Hn denote the number of moves needed to
solve the Tower of Hanoi problem with n disks.
Set up a recurrence relation for the sequence {Hn}.
目標 : n 個 disk 都從 peg 1 移到
peg 2

H4 moves

peg 1 peg 2 peg 3


Sol : Hn=2Hn-1+1,
H1=1
( n1 個 disk 先從 peg 1→peg 3, 第 n 個 disk 從 peg
1→peg 2,
n1 個 disk 再從 peg 3→peg 2) Ch7-4
上例中 Hn=2Hn1+1, H1=1
∴Hn=2Hn1+1
=2(2Hn2+1)+1
=22Hn2+2+1
=22(2Hn3+1)+2+1
=23Hn3+(22+2+1)
:
=2n1H1+(2n2+2n3+…+1)
=2n1+2n2+…+1
2n  1
= 2  1 =2n1
Ch7-5
Example 6. Find a recurrence relation and give initial conditions for
the number of bit strings of length n that do not have two
consecutive 0s.
How many such bit strings are there of length 5 ?
Sol :

Let an be the number of bit strings of length n that


do not have two consecutive 0s.
1 2 … n-3 n-2 n-1 n

an-1 種 1 ∴ an = an1+an2, n  3
a1=2 (string : 0,1)
an-2 種 1 0 a2=3 (string : 01,10,11)

∴ a3=a2+a1=5, a4=8, a5=13


Ch7-6
Example 7. (Codeword enumeration)
A computer system considers a string of decimal digits
a valid codeword if it contains an even number of 0
digits. Let an be the number of valid n-digit codewords.
Find a recurrence relation for an.
Sol :

1 2 3 … n-1 n ∴ an = 9an1 + (10n1an1)


= 8an1 + 10n1 , n2
an1 種 1~9
a1 = 9
10n1 an1 種 0
Exercise : 3,23,25,27,29,41
(41 推廣成 Ch7-7
7.2 Solving Recurrence Relations
Def 1. A linear homogeneous recurrence relation of
degree k (i.e., k terms) with constant coefficients
is a recurrence relation of the form
an = c1an1+c2an2+…+ckank
where ciR and ck≠0

Example 1 and 2.
fn = fn1 + fn2 (True, deg=2)
an = an5 (True, deg=5)
an = an1 + an22 (False, not linear)
(False , not linear)
an = nan1
(False, not homogeneous)
H = 2H + 1 Ch7-8
Theorem 1.
Let an = c1an1+ c2an2 be a recurrence relation
with c1,c2R.
If r2 c1r c2= 0 ( 稱為 characteristic equation)
has two distinct roots r1 and r2.
Then the solution of an is an = 1r1n + 2r2n ,
for n=0,1,2,…, where 1 , 2 are constants.
(1 , 2 可利用 a0, a1 算出 )

Ch7-9
Example 3.
What’s the solution of the recurrence relation
an = an1 + 2an2
with a0=2 and a1=7 ?
Sol :
The characteristic equation is r2 – r  2=0.
Its two roots are r1= 2 and r2 = 1.
Hence an=12n +2 (1)n .
∵a0 = 12 = 2, a1=212=7
∴1 = 3, 2 = 1 驗算: a2 = a1 + 2a0 =11
a = 32 1 =11
 an = 32n (1)n.
2
2
Ch7-10
Example 4. Find an explicit formula for the
Fibonacci numbers.
Sol :
fn = fn1 + fn2 , n  2, f0=0 , f1=1.
The characteristic equation is r2 r  1=0.
1 5 1 5
r1  r2 
Its two roots are 2 , 2 .
So we have f    (1  5 ) n   (1  5 ) n
n 1 2
2 2
1 5 1 5
 f 0  1   2  0, f1  1 ( )  2 ( ) 1
1 1 2 2
1  , 2 
5 5
1 1 5 n 1 1 5 n
 fn  ( )  ( )
5 2 5 2 Ch7-11
Thm 2.
Let an = c1an1+c2an2 be a recurrence relation
with c1,c2R.
If r2  c1r  c2= 0 has only one root r0 .
Then the solution of an is
an = 1  r0n + 2  n  r0n
for n=0,1,2,…, where 1 and 2 are constants.

Ch7-12
Example 5.
What’s the solution of an= 6an1 9an2
with a0=1 and a1=6 ?
Sol :
The root of r2  6r + 9 = 0 is r0 = 3.
Hence an = 1 . 3n +2 . n . 3n .
∵a0 = 1 = 1
a 1 = 3  1 + 3 2 = 6
∴ 1 = 1 and 2 = 1
驗算: a2 = 6a1  9a0 =27
 an = 3 + n . 3
n n
a2= 32 +2 32 =27
Ch7-13
Thm 3.
Let an = c1an1 + c2an2 + … + ckank be a
recurrence relation with c1, c2, …, ck  R.
If rk  c1rk-1  c2rk-2 … ck = 0 has k distinct roots
r1, r2,…, rk.
Then the solution of an is
an = 1r1n +2r2n + …+krkn, for n = 0, 1, 2, …
where 1, 2,…k are constants.

Ch7-14
Example 6 (k = 3)
Find the solution of an = 6an1  11an2 + 6an3
with initial conditions a0=2, a1=5 and a2=15 .
Sol :
The roots of r3  6r2 + 11r – 6 = 0 are
r1 = 1, r2 = 2, and r3 = 3
∴an = 1  1n + 2 2n + 3 3n
∵a0 = 1 + 2 + 3 = 2 1 = 1,
a1 = 1 + 22 + 33 = 5 2 = 1,
a2 = 1 + 42 + 93 = 15 3 = 2
驗算: a3 = 6a2  11a1+ 6a0 =47
∴an = 1  2 + 2  3
n n
a = 1  23 + 2  33 =47
3 Ch7-15
Thm 4.
Let an = c1an1 + c2an2 + … + ckank be a
recurrence relation with c1, c2, …, ck R.
If rk c1rk1 c2rk2 … ck = 0
has t distinct roots r1, r2, …, rt with
multiplicities m1, m2, …, mt respectively, where
mi  1,i, and m1+ m2 +…+ mt = k,
then
( 接下一頁 )

Ch7-16
m1 1 n
an  (α1,0  α1,1  n  ...  α1,m1 1  n )r1
 ...
mi 1 n
 (αi ,0  αi,1  n  ...  αi,mi 1  n )  ri
 ...
mt 1 n
 (αt,0  αt,1  n  ...  αt,mt 1  n )  rt
where i,j are constants.
(1  i  t , 0  j  mi1)
Ch7-17
補充說明:
若特徵方程式的 root 為: 1 (2 重根 ),
2 (3 重根 ),
3 ( 無重根 )

則通解為:
an= (1+2n )  1n+ (3+4n +5n2 )  (2) n+6  3n

( 變數的下標從開始排起只
, 要不重複就好

Ch7-18
Example 8. Find the solution to the recurrence
relation an = 3an1  3an2  an3 with initial conditions
a0 = 1, a1 = 2 and a2 = 1.
Sol :
r3 + 3r2 + 3r + 1 = 0 has a single root r0 = 1 of
multiplicity three.
∴ an = (1+2n+3n2) r0n = (1+2n+3n2)(1)n
∵ a0 = 1 = 1
a1 = (1+2+3)  (1) = 2
a2 = (1+2+3) = 1 驗算: a3 =  3a2  3a1 a0 =8
a3= (1+33232)(1)3 =8
∴1 = 1, 2 = 3, 3 = 2
Exercise : 3,13,15,19
 an = (1+3n2n2)  (1)n Ch7-19
7.4 Generating Functions.
Def 1. The generating function for the sequence {an}
is the infinite power series.
G(x) = a0 + a1x +… + anxn +…

= k
k
a x
k 0

( 若 {an} 是 finite ,可視為是 infinite ,但後面的 term


都等於 0)

Ch7-20
Example 2. What is the generating function
for the sequence 1,1,1,1,1,1 ?
Sol :
G ( x)  1  x  x  ...  x
2 5
(expansion ,展開式 )
x6 1
 (closed form)
x 1

Ch7-21
Example 3.
m
Let mZ+ and ak   k ,for k = 0, 1, …, m.
 
What is the generating function for the sequence
a0, a1,…, am ?
Sol :
G(x) = a0 + a1x + a2x2 + … + amxm
 m  m  m 2  m m
      x    x      x
0 1 2  m

= (1+x)m (by 二項式定理 )

Ch7-22
Example 5.
1
The function f (x) = is the generating
1  ax

function of the sequence 1, a, a2, …,


1 
since 1  ax = 1 + ax + a2x2 + …=  (
k 0
ax ) k

when |ax| < 1 for a≠0

Ch7-23
( 跳過 )

Def 2.
Let uR and kZ+∪{0}. Then the extended

u 
binomial coefficient  k  is defined by
 
1
 u   u (u  1)(u  2)...(u  k  1), if k  0
    k!
 k  1 if k  0

Ch7-24
( 跳過 )

Example 7.
  2  12 
Find   and  
 3   3
   
Sol :

  2 1
   (2)(3)(4)  4
 3  3!
 12  1  1   1   3  1
      
 3  3!  2  2  2  16
Ch7-25
( 跳過 )

Thm 2. (The Extended Binomial Theorem)


Let xR with |x|<1 and let uR, then
 x

1  x  u
 u
k
k

k 0

Ch7-26
Example 9. ( 跳過 )
Find the generating functions for (1+x)n and (1x)n
where nZ+
Sol : By the Extended Binomial Theorem,

  n  
1
(1  x)     x   ( n)(n  1) ... (n  k  1) x k
n k

k 0  k  k  0 k!

(1) k
 (n) (n  1) ... (n  k  1) x k
k 0 k!
 n k  n  k  1
k  n  k  1 k

 (1)   x Note :    (1)  
k 0  k   k   k 

By replacing x by –x we have

 n  k  1 k
(1  x)   
n
 x
k 0  k 
Ch7-27
※Using Generating Functions to solve
Recurrence Relations.
Example 16.
Solving the recurrence relation ak = 3ak1 for
k=1,2,3,… and initial condition a0 = 2.
Sol :
另法: (by 6.2 公式 )
r – 3 = 0  r = 3  an =  3n
∵ a0 = 2 = 
∴ an = 2  3n
Ch7-28

Let G ( x)  a0  a1 x  a2 x  ...   ak x be the
2 k

k 0
generating function for {ak}.
First note that ak xk = 3ak1 xk
   

 k  k 1  k 1  k
k 1
a x k
 3 a x k
 3 x a x  3 x a x k

k 1 k 1 k 1 k 0

 G(x)  a0 = 3x  G(x)
∵a0 = 2  G(x)  3x  G(x) = G(x)(13x) = 2
 
2
 G ( x)   2   (3x) k   2  3k  x k
1  3x k 0 k 0

∴ ak = 2  3 k Exercise : 5,7,11,33 Ch7-29


7.5 Inclusion-Exclusion 排容原理
A,B,C,D : sets
(1). A  B  A  B  A  B
(2). A  B C  A  B  C  A  B  A C  B C  A  B C
A
1 |A|+|B|+|C| 時
各部分被計算的次數
2
1 21
2
3
1
0
-|AB|-|AC|-|BC| 後
1 2 1 C
B 1
+|ABC| 後

(3). A  B C  D  ?
Ch7-30
Theorem 1.
A1, A2, …, An : sets
n
A1  A2 ...  An   Ai   A A i j
i 1 1i  j  n

  Ai  A j  Ak  ...  (1) n  A1  A2 ...  An


1 i , j , k  n

Exercise : 17 Ch7-31
7.6 Applications of Inclusion and
Exclusion
Example 2. How many onto functions are there
form set A={1, 2, 3, 4, 5, 6} to set B={a, b, c} ?
Sol : f : A → B
f (1)= {a, b, c} 不同的填法造出不同的函數
f (2)= 如何使 a,b,c 都出現 ?
︰ ︰
f (6)=

# of onto functions
= ( 所有函數個數 )  (a,b,c 中有一個沒被對應 )
+ (a,b,c 中二個沒被對應 )  (a,b,c 都沒被對應 )
= 6
3     2    1     0
3
1
6 3 6
2
3 6
3 Ch7-32
Thm 1. |A| = m , |B| = n
There are
n 
m
    n  1     (n  2)     (n  3)
n
1
m n
2
m n
3
m
 ...
 (1)    1
n 1 n
n 1
m

onto functions f : A → B.
pf :
A = {a1, a2, …, am}. B = {b1, b2, …, bn}
f (a1)=
f (a2)= b1, b2, …, bn
︰ ︰
f (am)= Ch7-33
( 跳過 )

※Derangements 亂序
Def.
A derangement is a permutation of
objects that leaves no object in its
original position.

Ch7-34
( 跳過 )
Example 5. 21453, 23451, 34512, …
are derangements of 12345 :

Def.
Let Dn be the number of derangements of n objects.

D4 = ( 所有 4 個元素的 permutation 數 )
 (4 個元素有一個在原位置的 permutation 數 )
+ (4 元素中有二個在原位置的個數 )
 (4 個元素中有三個在原位置的個數 )
+ (4 元素都在原位置的個數 )
 4  4  4  4
= 4!   3!   2!  1!   0!
1  2  3  4
Ch7-35
( 跳過 )

Theorem 2. ( 亂序公式 )
Dn  n!   n1   (n  1)!   n2   (n  2)!  ...  (1) n  nn   0!
n! (n  1)! n! (n  2)!
 n! (1      ...
1!(n  1)! n! 2!(n  2)! n!
n! 0!
 (1) 
n
 )
n!0! n!
1 1 n 1
 n! ( 1    ...  (1)  )
1! 2! n!

Exercise : 8, 13 Ch7-36

You might also like