Discrete Mathematics Chapter 6 Advanced Counting Techniques 7

  • Slides: 36
Download presentation
Discrete Mathematics Chapter 6 Advanced Counting Techniques

Discrete Mathematics Chapter 6 Advanced Counting Techniques

7. 1 Recurrence Relations(遞迴關係 ) Example 1. Let {an} be a sequence that satisfies

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 a 0=3, and a 1=5. Here a 0=3 and a 1=5 are the initial conditions. By the recurrence relation, a 2 = a 1 -a 0 = 2 a 3 = a 2 -a 1 = -3 a 4 = a 3 -a 2 = -5 : Q 1: Applications ? Q 2: Are there better ways for computing the terms of {an}? n

※Modeling with Recurrence Relations We can use recurrence relations to model (describe) a wide

※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. P 0=10000 Pn=Pn-1 + 0. 11 Pn-1=1. 11 Pn-1, ∴ P 30=1. 11 P 29=(1. 11)2 P 28=…=(1. 11)30 P 0 =228922. 97

Example 5. (The Tower of Hanoi) The rules of the puzzle allow disks to

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 H 4 moves peg 1 Sol : peg 2 peg 3 Hn=2 Hn-1+1, H 1=1 ( n-1個 disk 先從peg 1→peg 3, 第 n 個 disk 從 peg 1→peg 2, n-1個 disk 再從 peg 3→peg 2)

上例中 Hn=2 Hn-1+1, H 1=1 ∴Hn=2 Hn-1+1 =2(2 Hn-2+1)+1 =22 Hn-2+2+1 =22(2 Hn-3+1)+2+1 =23

上例中 Hn=2 Hn-1+1, H 1=1 ∴Hn=2 Hn-1+1 =2(2 Hn-2+1)+1 =22 Hn-2+2+1 =22(2 Hn-3+1)+2+1 =23 Hn-3+(22+2+1) : =2 n-1 H 1+(2 n-2+2 n-3+…+1) =2 n-1+2 n-2+…+1 = =2 n-1

Example 6. Find a recurrence relation and give initial conditions for the number of

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 0 s. How many such bit strings are there of length 5 ? Sol : 2 … n-3 n-2 n-1 1 n ∴ an = an-1+an-2, n 3 1 an-1 種 a 1=2 (string : 0, 1) an-2 種 a 2=3 (string : 01, 10, 11) 1 0 ∴ a 3=a 2+a 1=5, a 4=8, a 5=13

Example 7. (Codeword enumeration) A computer system considers a string of decimal digits a

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 an-1 種 10 n-1 - an-1 種 n 1~9 0 ∴ an = 9 an-1 + (10 n-1 -an-1) = 8 an-1 + 10 n-1 , n 2 a 1 = 9

求an通解 : Exercise : 3, 25, 27, 29, 41 (41推廣成n)

求an通解 : Exercise : 3, 25, 27, 29, 41 (41推廣成n)

7. 2 Solving Recurrence Relations Def 1. A linear homogeneous recurrence relation of degree

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 = c 1 an-1+c 2 an-2+…+ckan-k where ci R and ck≠ 0 Example 1 and 2. fn = fn-1 + fn-2 an = an-5 an = an-1 + an-22 an = nan-1 Hn = 2 Hn-1 + 1 (True, deg=2) (True, deg=5) (False, 不是linear) (False , 不是linear, not constant coeff. ) (False, 不是homogeneous)

Theorem 1. Let an = c 1 an-1+ c 2 an-2 be a recurrence

Theorem 1. Let an = c 1 an-1+ c 2 an-2 be a recurrence relation with c 1, c 2 R. If r 2 - c 1 r - c 2= 0 (稱為characteristic equation) has two distinct roots r 1 and r 2. Then the solution of an is an = a 1 r 1 n + a 2 r 2 n , for n=0, 1, 2, …, where a 1 , a 2 are constants. (a 1 , a 2可利用 a 0, a 1算出)

Example 3. What’s the solution of the recurrence relation an = an-1 + 2

Example 3. What’s the solution of the recurrence relation an = an-1 + 2 an-2 with a 0=2 and a 1=7 ? Sol : The characteristic equation is r 2 – r - 2=0. Its two roots are r 1= 2 and r 2 = -1. Hence an=a 1 2 n +a 2 (-1)n. ∵a 0 = a 1+a 2 = 2, a 1=2 a 1 -a 2=7 ∴a 1 = 3, a 2 = -1 驗算:a 2 = a 1 + 2 a 0 =11 a 2= 3 22 - 1 =11 an = 3 2 n - (-1)n.

Example 4. Find an explicit formula for the Fibonacci numbers. Sol : fn =

Example 4. Find an explicit formula for the Fibonacci numbers. Sol : fn = fn-1 + fn-2 , n 2, f 0=0 , f 1=1. The characteristic equation is r 2 - r - 1=0. Its two roots are So we have , .

Thm 2. Let an = c 1 an-1+c 2 an-2 be a recurrence relation

Thm 2. Let an = c 1 an-1+c 2 an-2 be a recurrence relation with c 1, c 2 R. If r 2 - c 1 r - c 2= 0 has only one root r 0. Then the solution of an is an = a 1 r 0 n + a 2 n r 0 n for n=0, 1, 2, …, where a 1 and a 2 are constants.

Example 5. What’s the solution of an= 6 an-1 - 9 an-2 with a

Example 5. What’s the solution of an= 6 an-1 - 9 an-2 with a 0=1 and a 1=6 ? Sol : The root of r 2 - 6 r + 9 = 0 is r 0 = 3. Hence an = a 1.3 n +a 2.n.3 n. ∵a 0 = a 1 = 1 a 1 = 3 a 1 + 3 a 2 = 6 ∴ a 1 = 1 and a 2 = 1 驗算:a 2 = 6 a 1 - 9 a 0 =27 n n an = 3 + n.3 a 2= 32 +2 32 =27

Thm 3. Let an = c 1 an-1 + c 2 an-2 + …

Thm 3. Let an = c 1 an-1 + c 2 an-2 + … + ckan-k be a recurrence relation with c 1, c 2, …, ck R. If rk - c 1 rk-1 - c 2 rk-2 -…- ck = 0 has k distinct roots r 1, r 2, …, rk. Then the solution of an is an = a 1 r 1 n +a 2 r 2 n + …+akrkn, for n = 0, 1, 2, … where a 1, a 2, …ak are constants.

Example 6 (k = 3) Find the solution of an = 6 an-1 -

Example 6 (k = 3) Find the solution of an = 6 an-1 - 11 an-2 + 6 an-3 with initial conditions a 0=2, a 1=5 and a 2=15. Sol : The roots of r 3 - 6 r 2 + 11 r – 6 = 0 are r 1 = 1, r 2 = 2, and r 3 = 3 ∴an = a 1 1 n + a 2 2 n + a 3 3 n ∵a 0 = a 1 + a 2 + a 3 = 2 a 1 = 1, a 2 = -1, a 1 = a 1 + 2 a 2 + 3 a 3 = 5 a 3 = 2 a 2 = a 1 + 4 a 2 + 9 a 3 = 15 0 =47 ∴an = 1 - 2 n + 2 3 n 驗算:a 3 = 6 a 2 -311 a 1+ 6 a 3 a 3= 1 - 2 + 2 3 =47

Thm 4. Let an = c 1 an-1 + c 2 an-2 + …

Thm 4. Let an = c 1 an-1 + c 2 an-2 + … + ckan-k be a recurrence relation with c 1, c 2, …, ck R. If rk - c 1 rk-1 - c 2 rk-2 - … - ck = 0 has t distinct roots r 1, r 2, …, rt with multiplicities m 1, m 2, …, mt respectively, where mi 1, i, and m 1+ m 2 +…+ mt = k, then (接下一頁)

where ai, j are constants. (1 i t , 0 j mi-1)

where ai, j are constants. (1 i t , 0 j mi-1)

Example 8. Find the solution to the recurrence relation an = -3 an-1 -

Example 8. Find the solution to the recurrence relation an = -3 an-1 - 3 an-2 - an-3 with initial conditions a 0 = 1, a 1 = -2 and a 2 = -1. Sol : r 3 + 3 r 2 + 3 r + 1 = 0 has a single root r 0 = -1 of multiplicity three. ∴ an = (a 1+a 2 n+a 3 n 2) r 0 n = (a 1+a 2 n+a 3 n 2)(-1)n ∵ a 0 = a 1 = 1 a 1 = (a 1+a 2+a 3) (-1) = -2 a 2 = (a 1+a 2+a 3) = -1 驗算:a 3 = - 3 a 2 - 3 a 1 - a 0 =8 a 3= (1+3 3 -2 32) (-1)3 =8 ∴a 1 = 1, a 2 = 3, a 3 = -2 an = (1+3 n-2 n 2) (-1)n Exercise : 3, 15, 19

7. 4 Generating Functions. Def 1. The generating function for the sequence {an} is

7. 4 Generating Functions. Def 1. The generating function for the sequence {an} is the infinite power series. G(x) = a 0 + a 1 x +… + anxn +… = (若 {an} 是finite,可視為是infinite,但後面的term 都等於 0)

Example 2. What is the generating function for the sequence 1, 1, 1, 1

Example 2. What is the generating function for the sequence 1, 1, 1, 1 ? Sol : (expansion,展開式) (closed form)

Example 3. Let m Z+ and , for k = 0, 1, …, m.

Example 3. Let m Z+ and , for k = 0, 1, …, m. What is the generating function for the sequence a 0, a 1, …, am ? Sol : G(x) = a 0 + a 1 x + a 2 x 2 + … + amxm = (1+x)m (by 二項式定理)

Example 5. The function f (x) = is the generating function of the sequence

Example 5. The function f (x) = is the generating function of the sequence 1, a, a 2, …, since = 1 + ax + a 2 x 2 + …= when |ax| < 1 for a≠ 0

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

Def 2. Let u R and k Z+∪{0}. Then the extended binomial coefficient is defined by

Example 7. Find Sol : and

Example 7. Find Sol : and

Thm 2. (The Extended Binomial Theorem) Let x R with |x|<1 and let u

Thm 2. (The Extended Binomial Theorem) Let x R with |x|<1 and let u R, then

Example 9. Find the generating functions for (1+x)-n and (1 -x)-n where n Z+

Example 9. Find the generating functions for (1+x)-n and (1 -x)-n where n Z+ Sol : By the Extended Binomial Theorem, Def 2. By replacing x by –x we have

※Using Generating Functions to solve Recurrence Relations. Example 16. Solving the recurrence relation ak

※Using Generating Functions to solve Recurrence Relations. Example 16. Solving the recurrence relation ak = 3 ak-1 for k=1, 2, 3, … and initial condition a 0 = 2. Sol : 另法: (by 7. 2公式 ) r – 3 = 0 r = 3 an = a 3 n ∵ a 0 = 2 = a ∴ an = 2 3 n

Let generating function for {ak}. First note that ak xk = 3 ak-1 xk

Let generating function for {ak}. First note that ak xk = 3 ak-1 xk be the - a 0 = 3 x G(x) ∵a 0 = 2 k G(x) - 3 x G(x) = G(x)(1 -3 x) = 2 ∴a =2 3 G(x) k Exercise : 5, 7, 11, 33

7. 5 Inclusion-Exclusion 排容原理 A, B, C, D : sets A |A|+|B|+|C| 時 各部分被計算的次數

7. 5 Inclusion-Exclusion 排容原理 A, B, C, D : sets A |A|+|B|+|C| 時 各部分被計算的次數 1 2 1 B 1 2 3 1 0 2 1 21 1 C -|A B|-|A C|-|B C|後 +|A B C|後

Theorem 1. A 1, A 2, …, An : sets Exercise : 17

Theorem 1. A 1, A 2, …, An : sets Exercise : 17

7. 6 Applications of Inclusion and Exclusion Example 2. How many onto functions are

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)= f (2)= ︰ ︰ f (6)= {a, b, c} 不同的填法造出不同的函數 如何使a, b, c都出現 ? # of onto functions = (所有函數個數) - (a, b, c中有一個沒被對應) + (a, b, c中二個沒被對應) - (a, b, c都沒被對應) =

Thm 1. |A| = m , |B| = n There are onto functions f

Thm 1. |A| = m , |B| = n There are onto functions f : A → B. pf : A = {a 1, a 2, …, am}. B = {b 1, b 2, …, bn} f (a 1)= b 1, b 2, …, bn f (a 2)= ︰ f (am)= ︰

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

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

Example 5. derangements of 12345 : 21453, 23451, 34512, … Def. Let Dn denote

Example 5. derangements of 12345 : 21453, 23451, 34512, … Def. Let Dn denote the number of derangements of n objects. D 4 = (所有4個元素的permutation數) - (4個元素有一個在原位置的permutation數) + (4元素中有二個在原位置的個數) - (4個元素中有三個在原位置的個數) + (4元素都在原位置的個數) =

Theorem 2. (亂序公式) Exercise : 8 參考: 12, 13

Theorem 2. (亂序公式) Exercise : 8 參考: 12, 13