Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Mathematics Chapter 6 Advanced Counting Techniques.

Similar presentations


Presentation on theme: "Discrete Mathematics Chapter 6 Advanced Counting Techniques."— Presentation transcript:

1 Discrete Mathematics Chapter 6 Advanced Counting Techniques

2 7.1Recurrence Relations( 遞迴關係 ) Example 1. Let {a n } be a sequence that satisfies the recurrence relation a n = a n  1  a n  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 : Q1: Applications ? Q2: Are there better ways for computing the terms of {a n } ?

3 ※ 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 P n denote the amount in the account after n years. P n =P n  1 + 0.11  P n  1 =1.11  P n  1, ∴ P 30 =1.11  P 29 =(1.11) 2  P 28 =…=(1.11) 30  P 0 =228922.97 P 0 =10000

4 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 H n denote the number of moves needed to solve the Tower of Hanoi problem with n disks. Set up a recurrence relation for the sequence {H n }. Sol : H n =2H n-1 +1, ( n  1 個 disk 先從 peg 1 →peg 3, 第 n 個 disk 從 peg 1 →peg 2, n  1 個 disk 再從 peg 3 →peg 2 ) peg 1 peg 2peg 3 H 4 moves 目標 : n 個 disk 都從 peg 1 移到 peg 2 H 1 =1

5 上例中 H n =2H n  1 +1, H 1 =1 ∴ H n =2H n  1 +1 =2(2H n  2 +1)+1 =2 2 H n  2 +2+1 =2 2 (2H n  3 +1)+2+1 =2 3 H n  3 +(2 2 +2+1) : =2 n  1 H 1 +(2 n  2 +2 n  3 +…+1) =2 n  1 +2 n  2 +…+1 = =2 n  1

6 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 : ∴ a n = a n  1 +a n  2, n  3 a 1 =2 (string : 0,1) a 2 =3 (string : 01,10,11) ∴ a 3 =a 2 +a 1 =5, a 4 =8, a 5 =13 1 a n-1 種 a n-2 種 1 0 n-2n-1n 1 2 n-3 …

7 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 a n be the number of valid n -digit codewords. Find a recurrence relation for a n. Sol : 1~9 an1 種an1 種 10 n  1  a n  1 種 0 ∴ a n = 9a n  1 + (10 n  1  a n  1 ) = 8a n  1 + 10 n  1, n  2 a 1 = 9 n-1 n 1 2 3 …

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

9 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 where c i  R and c k ≠ 0 Example 1 and 2. f n = f n  1 + f n  2 a n = a n  5 a n = a n  1 + a n  2 2 a n = na n  1 H n = 2H n  1 + 1 a n = c 1 a n  1 +c 2 a n  2 +…+c k a n  k (True, deg=2) (True, deg=5) (False, 不是 linear) (False, 不是 linear, not constant coeff. ) (False, 不是 homogeneous)

10 Theorem 1. Let a n = c 1 a n  1 + c 2 a n  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 a n is a n =  1 r 1 n +  2 r 2 n, for n=0,1,2,…, where  1,  2 are constants. (  1,  2 可利用 a 0, a 1 算出 )

11 Example 3. What’s the solution of the recurrence relation a n = a n  1 + 2a n  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 a n =  1  2 n +  2  (  1) n. ∵ a 0 =  1  2 = 2, a 1 =2  1  2 =7 ∴  1 = 3,  2 =  1  a n = 3  2 n  (  1) n. 驗算: a 2 = a 1 + 2a 0 =11 a 2 = 3  2 2  1 =11

12 Example 4. Find an explicit formula for the Fibonacci numbers. Sol : f n = f n  1 + f n  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

13 Thm 2. Let a n = c 1 a n  1 +c 2 a n  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 a n is a n =  1  r 0 n +  2  n  r 0 n for n=0,1,2,…, where  1 and  2 are constants.

14 Example 5. What’s the solution of a n = 6a n  1  9a n  2 with a 0 =1 and a 1 =6 ? Sol : The root of r 2  6r + 9 = 0 is r 0 = 3. Hence a n =  1 . 3 n +  2 . n . 3 n. ∵ a 0 =  1 = 1 a 1 = 3  1 + 3  2 = 6 ∴  1 = 1 and  2 = 1  a n = 3 n + n . 3 n 驗算: a 2 = 6a 1  9a 0 =27 a 2 = 3 2 +2  3 2 =27

15 Thm 3. Let a n = c 1 a n  1 + c 2 a n  2 + … + c k a n  k be a recurrence relation with c 1, c 2, …, c k  R. If r k  c 1 r k-1  c 2 r k-2  …  c k = 0 has k distinct roots r 1, r 2,…, r k. Then the solution of a n is a n =  1 r 1 n +  2 r 2 n + …+  k r k n, for n = 0, 1, 2, … where  1,  2,…  k are constants.

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

17 Thm 4. Let a n = c 1 a n  1 + c 2 a n  2 + … + c k a n  k be a recurrence relation with c 1, c 2, …, c k  R. If r k  c 1 r k  1  c 2 r k  2  …  c k = 0 has t distinct roots r 1, r 2, …, r t with multiplicities m 1, m 2, …, m t respectively, where m i  1,  i, and m 1 + m 2 +…+ m t = k, then ( 接下一頁 )

18 where  i,j are constants. ( 1  i  t, 0  j  m i  1 )

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

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

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

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

23 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

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

25 Example 7. Find and Sol :

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

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

28 ※ Using Generating Functions to solve Recurrence Relations. Example 16. Solving the recurrence relation a k = 3a k  1 for k=1,2,3,… and initial condition a 0 = 2. Sol : 另法: (by 7.2 公式 ) r – 3 = 0  r = 3  a n =  3 n ∵ a 0 = 2 =  ∴ a n = 2  3 n

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

30 7.5 Inclusion-Exclusion 排容原理 A,B,C,D : sets 1 112 2 2 3 A B C |A|+|B|+|C| 時 各部分被計算的次數 1 1 1 1 20 +|A  B  C| 後 -|A  B|-|A  C|-|B  C| 後

31 Theorem 1. A 1, A 2, …, A n : sets Exercise : 17

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

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

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

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

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


Download ppt "Discrete Mathematics Chapter 6 Advanced Counting Techniques."

Similar presentations


Ads by Google