Download presentation
Presentation is loading. Please wait.
Published byMartin Johns Modified over 9 years ago
1
Discrete Mathematics Chapter 7 Advanced Counting Techniques 大葉大學 資訊工程系 黃鈴玲
2
Outline 7.1 Recurrence Relations 7.2 Solving Linear Recurrence Relations 7.4 Generating Functions 7.5 Inclusion-Exclusion 7.6 Applications of Inclusion-Exclusion Ch9-2
3
Ch7-3 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 } ?
4
Ch7-4 ※ 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
5
Ch7-5 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
6
Ch7-6 上例中 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
7
Ch7-7 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 … Let a n be the number of bit strings of length n that do not have two consecutive 0 s.
8
Ch7-8 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 an1 種an1 種 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 …
9
Ch7-9 求 a n 通解 : Exercise : 3,23,25,27,29,41 (41 推廣成 n )
10
Ch7-10 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, not linear) (False, not homogeneous)
11
Ch7-11 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 算出 ) Solving Linear Homogeneous Recurrence Relations with Constant Coefficients
12
Ch7-12 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 r 1 與 r 2 順序可交換, 結果會一樣
13
Ch7-13 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
14
Ch7-14 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.
15
Ch7-15 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 only 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
16
Ch7-16 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.
17
Ch7-17 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
18
Ch7-18 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 where i,j are constants for 1 i t and 0 j m i 1.
19
Ch7-19 補充說明: 若特徵方程式的 root 為: 1 ( 2 重根 ), 2 ( 3 重根 ), 3 ( 無重根 ) 則上述定理給出的通解為: a n = ( 1,1 + 1,2 n) 1 n + ( 2,1 + 2,2 n + 2,3 n 2 ) ( 2) n + 3,1 3 n ( 其實變數 的下標可從 開始排起,只要不重複就好 a n = ( 1 + 2 n) 1 n + ( 3 + 4 n + 5 n 2 ) ( 2) n + 6 3 n
20
Ch7-20 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 2 +4 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
21
Ch7-21 Linear Nonhomogeneous Recurrence Relations with Constant Coefficients Example: a n = 3a n 1 + 2n A recurrence relation of the form a n = c 1 a n 1 + c 2 a n 2 + … + c k a n k + F(n), where c 1, c 2, …, c k are real numbers and F(n) is a function not identically zero depending only on n. The recurrence relation a n = c 1 a n 1 + c 2 a n 2 + … + c k a n k is called the associated homogeneous recurrence relation.
22
Ch7-22 Example 9: a n = a n 1 + 2 n, associated h.r.r a n = a n 1 a n = a n 1 + a n 2 + n 2 +1, associated h.r.r a n = a n 1 + a n 2 a n = 3a n 1 + n3 n, associated h.r.r a n = 3a n 1 a n = a n 1 + a n 3 + n!, associated h.r.r a n = a n 1 + a n 3
23
Ch7-23 Theorem 5. If {a n (p) } is a particular solution ( 特解 ) of a n = c 1 a n 1 + c 2 a n 2 + … + c k a n k + F(n), then every solution is of the form {a n (p) + a n (h) }, where {a n (h) } is a solution of a n = c 1 a n 1 + c 2 a n 2 + … + c k a n k Proof. If {a n (p) } and {b n } are both solutions of a n = c 1 a n 1 + c 2 a n 2 + … + c k a n k + F(n), then a n (p) = c 1 a n 1 (p) + c 2 a n 2 (p) + … + c k a n k (p) + F(n), and b n = c 1 b n 1 + c 2 b n 2 + … + c k b n k + F(n). a n (p) b n = c 1 (a n 1 b n 1 ) + c 2 (a n 2 b n 2 ) + … + c k (a n k b n k ) {a n (p) b n } is a solution of a n = c 1 a n 1 + c 2 a n 2 + … + c k a n k b n = a n (p) + a n (h)
24
Ch7-24 Example 10. Find all solutions of the recurrence relation a n = 3a n 1 + 2n. What is the solution with a 1 =3 ? Sol : {associated 的部分 a n = 3a n 1 先解 } Characteristic equation: r – 3 = 0 r = 3 a n (h) = 3 n. {particular solution} ∵ F(n) = 2n ∴ Let a n (p) =cn+d, where c, d R. If a n (p) = cn+d is a solution to a n = 3a n 1 + 2n, then cn+d = 3(c(n 1)+d)+2n =3cn 3c d +2n 2cn 3c d +2n = (2c+2)n + ( d 3c) = 0 ( 任何 n 代入都需為 0) ∴ 2c+2 = 0, and d 3c = c = 1, d = 3/2 a n (p) = n 3/2 a n = a n (h) a n (p) = 3 n n 3/2 If a 1 = 3 1 3/2 = 3 = 11/6 a n = (11/6) 3 n n 3/2
25
Ch7-25 Example 11. Find all solutions of the recurrence relation a n = 5a n 1 6a n 2 + 7 n. Sol : {associated 的部分 a n = 5a n 1 6a n 2 先解 } Characteristic equation: r 2 – 5r + 6 = 0 r 1 = 3, r 2 = 2 a n (h) = 1 3 n + 2 2 n. {particular solution} ∵ F(n) = 7 n ∴ Let a n (p) = c 7 n, where c R. If a n (p) = c 7 n is a solution to a n = 5a n 1 6a n 2 + 7 n, then c 7 n = 5c 7 n 1 6c 7 n 2 + 7 n 49c = 35c 6c + 49 c = 49/20 a n (p) = (49/20) 7 n a n = a n (h) a n (p) = 1 3 n + 2 2 n + (49/20) 7 n Exercise : 23
26
Ch7-26 Theorem 6. a n = c 1 a n 1 + c 2 a n 2 + … + c k a n k + F(n), where F(n) = (b t n t + b t 1 n t 1 +…+ b 1 n + b 0 )s n. When s is not a root of the characteristic equation of the associated linear homogeneous recurrence relation, there is a particular solution of the form (p t n t + p t 1 n t 1 +…+ p 1 n + p 0 )s n. When s is a root of the characteristic equation and its multiplicity is m, there is a particular solution of the form n m (p t n t + p t 1 n t 1 +…+ p 1 n + p 0 )s n.
27
Ch7-27 Example 12. What form does a particular solution of the linear nonhomogeneous recurrence relation a n = 6a n 1 9a n 2 + F(n) have when F(n) =3 n, F(n) =n3 n, F(n) =n 2 2 n, and F(n) = (n 2 +1)3 n. Sol : The associated linear homogeneous recurrence relation is a n = 6a n 1 9a n 2. characteristic equation: r 2 6r 9 = 0 r = 3 (2 重根 ) F(n) =3 n, and 3 is a root a n (p) = p 0 n 2 3 n F(n) =n3 n, and 3 is a root a n (p) = n 2 (p 1 n+p 0 ) 3 n F(n) =n 2 2 n, and 2 is not a root a n (p) = (p 2 n 2 +p 1 n+p 0 )2 n F(n) = (n 2 +1)3 n, and 3 is a root a n (p) = n 2 (p 2 n 2 +p 1 n+p 0 ) 3 n Exercise : 27
28
Ch7-28 Example 13. Find the solutions of the recurrence relation a n = a n 1 + n with a 1 =1. Sol : The associated linear homogeneous recurrence relation is a n = a n 1. F(n) = n = n(1) n, and 1 is a root a n (p) = n(p 1 n+p 0 )1 n = p 1 n 2 +p 0 n 將 a n (p) 代入 a n = a n 1 + n p 1 n 2 +p 0 n = p 1 (n 1) 2 +p 0 (n 1)+n (2p 1 1)n+p 0 p 1 =0 p 1 = ½, p 0 p 1 = ½ a n (p) = (n 2 +n)/2 a n = a n (p) + a n (h) = (n 2 +n)/2+c characteristic eq.: r 1 = 0 r = 1 a n (h) = c(1) n =c a 1 =1 c=0 a n = a n (p) + a n (h) = (n 2 +n)/2 Exercise : 29
29
Ch7-29 ex 40: Solve the simultaneous recurrence relations a n = 3a n 1 + 2b n 1 b n = a n 1 + 2b n 1 with a 0 = 1 and b 0 = 2. Sol : a n b n = 2a n 1 b n = a n 2a n 1 a n = 3a n 1 + 2b n 1 = 3a n 1 + 2a n 1 4a n 2 a n = 5a n 1 4a n 2 r 2 5r 4 = 0 r = 1, 4 a n = 1 + 2 4 n a 0 = 1 + 2 = 1 a 1 = 1 +4 2 = 3a 0 + 2b 0 = 7 1 = 1, 2 = a n = 4 n 1 b n = a n 2a n 1 = 4 n 1 4 n = 4 n
30
Ch7-30 7.4 Generating Functions. Def 1. The generating function for the sequence a 0, a 1, a 2,… of real numbers is the infinite series G(x) = a 0 + a 1 x +… + a n x n +… = ( 若數列 {a n } 是 finite ,可視為是 infinite ,但後面的項都 等於 0 )
31
Ch7-31 Example 1. Find the generating functions for the sequences {a k } with (1) a k = 3 (2) a k = k+1 (3) a k = 2 k (1) G(x) = Sol : (3) G(x) = (2) G(x) =
32
Ch7-32 Example 2. What is the generating function for the sequence 1,1,1,1,1,1 ? Sol : (expansion ,展開式 ) (closed form) a0a0 a1a1 a2a2 a3a3 a4a4 a5a5 a 6 及之後都 =0 G(x) = = a 0 + a 1 x + a 2 x 2 + a 3 x 3 +… Exercise : 2
33
Ch7-33 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 下面的二項式定理 )
34
Ch7-34 Example 4. The function f (x) = is the generating function of the sequence 1, 1, 1, …, because = 1 + x + x 2 + …= when |x| < 1. Useful Facts About Power Series Example 5. The function f (x) = is the generating function of the sequence 1, a, a 2, …, because = 1 + ax + a 2 x 2 + …= when |ax| < 1 for a≠0. Exercise : 5(a)(b), 11(a)
35
Ch7-35 Theorem 1. Let f(x) = and g(x) =. Then f(x) + g(x) =. f(x) g(x) = (a 0 +a 1 x+a 2 x 2 +…)(b 0 +b 1 x +b 2 x 2 +…) = (a 0 b 0 )+(a 0 b 1 +a 1 b 0 ) x+(a 0 b 2 +a 1 b 1 +a 2 b 0 ) x 2 +… =
36
Ch7-36 Example 6. Let f (x) =. Use Example 4 to find the coefficients a 0, a 1, a 2, … in the expansion f (x)=. Sol : = 1 + x + x 2 + … == a k = k+1
37
Example 7. Find and Sol : Ch7-37 Def 2. Let u R and k N. Then the extended binomial coefficient is defined by
38
Ch7-38 Example 8 When the top parameter is a negative integer, the extended binomial coefficient can be expressed in terms of an ordinary binomial coefficient.
39
Ch7-39 Thm 2. (The Extended Binomial Theorem) Let x R with |x|<1 and let u R, then
40
Ch7-40 Example 9. Find the generating functions for (1+x) n and (1 x) n where n Z + Sol : By the Extended Binomial Theorem, Replacing x by –x, we find that Exercise : 11(b)(d)
41
Ch7-41 Counting Problems and Generating Functions Generating functions can be used to count the number of combinations of various types. Example 10. Find the number of solutions of e 1 + e 2 + e 3 = 17, where e 1, e 2, e 3 are integers with 2 e 1 5, 3 e 2 6, and 4 e 3 7. Sol : The number of solutions with the indicated constraints is the coefficient of x 17 in the expansion of (x 2 + x 3 + x 4 + x 5 )(x 3 + x 4 + x 5 + x 6 )(x 4 + x 5 + x 6 + x 7 ) ( 即相當於找 e 1, e 2, e 3 使 x e 1 x e 2 x e 3 = x 17 ) (e 1, e 2, e 3 )=(4, 6, 7), (5, 5, 7), (5, 6, 6) 共 3 種
42
Ch7-42 Example 11. In how many different ways can eight identical cookies be distributed among three distinct children if each child receives at least two cookies and no more than four cookies? Sol : The number of solutions is the coefficient of x 8 in the expansion of (x 2 + x 3 + x 4 ) 3 (c 1, c 2, c 3 ) = (2, 2, 4), (2, 3, 3), (2, 4, 2), (3, 2, 3), (3, 3, 2), (4, 2, 2) 共 6 種 Exercise: 23
43
Ch7-43 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 節 Thm 1 公式 ) r – 3 = 0 r = 3 a n = 3 n ∵ a 0 = 2 = ∴ a n = 2 3 n
44
Ch7-44 Let be the generating function for {a k }. First note that a k = 3a k 1 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 從 k = 1 開始,以避免 a k 1 變成 a 1
45
Ch7-45 Example 17 Solving a k = 8a k 1 +10 k 1 for k =1,2,3,… and initial condition a 1 = 9. (Sec. 7.1 Example 7) Let be the generating function for {a k }. Sol : Let a 0 = 1 ( 為計算方便而假設 ).
46
Ch7-46 ∴ a k = (10 k + 8 k )/2 Exercise: 33
47
Ch7-47 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| 後
48
Ch7-48 Theorem 1. A 1, A 2, …, A n : sets Exercise : 10, 11, 17
49
Ch7-49 7.6 Applications of Inclusion and Exclusion Example 1. How many solutions does x 1 + x 2 + x 3 = 11 have, where x 1, x 2, x 3 are nonnegative integers with x 1 3, x 2 4, and x 3 6 ? Sol : Let a solution have property P 1 if x 1 4, property P 2 if x 2 5, and property P 3 if x 3 7. N(P 1 ’ P 2 ’ P 3 ’ ) = N N(P 1 ) N(P 2 ) N(P 3 ) + N(P 1 P 2 ) + N(P 2 P 3 ) + N(P 1 P 3 ) N(P 1 P 2 P 3 )
50
Ch7-50 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 都出現 ? The number of onto functions = ( 所有函數個數 ) ( a,b,c 中有一個沒被對應 ) + ( a,b,c 中二個沒被對應 ) ( a,b,c 都沒被對應 ) The Number of Onto Functions
51
Ch7-51 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 Exercise : 8
52
Ch7-52 Example 3. How many ways are there to assign five different jobs to four different employees if every employee is assigned at least one job? Sol : Consider the assignment of jobs as a function from the set of five jobs to the set of four employees. The number of onto functions Exercise : 9
53
Ch7-53 Def. A derangement is a permutation of objects that leaves no object in its original position. Derangements ( 亂序 ) Example 5. The permutation 21453 is a derangement of 12345. But 21543 is not a derangement of 12345.
54
Ch7-54 D 4 = ( 所有 4 個元素的 permutation 數 ) ( 4 個元素有一個在原位置的 permutation 數 ) + ( 4 元素中有二個在原位置的 permutation 個數 ) ( 4 個元素中有三個在原位置的 permutation 個數 ) + ( 4 元素都在原位置的 permutation 個數 ) = Def. Let D n be the number of derangements of n objects. D 3 = 2 because the derangements of 123 are 231 and 312. D 2 = 1 because the derangements of 12 are 21.
55
Ch7-55 Theorem 2. ( 亂序公式 ) Exercise : 13 Proof.
56
Ch7-56 Exercise 17. How many ways can the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 be arranged so that even digit is in its original position? Sol :
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.