380 likes | 472 Views
Discrete Mathematics. Chapter 6 Advanced Counting Techniques. 7.1 Recurrence 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 .
E N D
Discrete Mathematics Chapter 6 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}?
Example 3.Compound Interest (複利) Suppose that a person deposits(存款) $10000 ina saving account at a bank yielding 11% per year with interest compounded annually. How much will be in the account after 30 years ? ※Modeling with Recurrence Relations We can use recurrence relations to model (describe) a wide variety of problems. Sol : Let Pn denote the amount in the account after n years. Pn=Pn-1 + 0.11Pn-1=1.11 Pn-1, ∴ P30=1.11 P29=(1.11)2P28=…=(1.11)30P0=228922.97 P0=10000
H4moves peg 2 peg 3 peg 1 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}. Sol :Hn=2Hn-1+1, ( n-1個 disk 先從peg 1→peg 3, 第 n 個 disk 從 peg 1→peg 2, n-1個 disk 再從 peg 3→peg 2) 目標 : n 個disk都從 peg 1 移到 peg 2 H1=1
上例中 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 n-2 n-1 n n-3 1 an-1種 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 : ∴ an = an-1+an-2, n 3 a1=2 (string : 0,1) a2=3 (string : 01,10,11) 1 an-2種 0 1 ∴ a3=a2+a1=5, a4=8, a5=13
… 2 3 n-1 n 1 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 : ∴ an = 9an-1 + (10n-1-an-1) = 8an-1 + 10n-1 , n2 a1 = 9 an-1種 1~9 10n-1 - an-1種 0
求an通解 : Exercise : 3,23,25,27,29,41 (41推廣成n)
7.2 Solving Recurrence Relations Def 1. A linearhomogeneous recurrence relationof degree k (i.e., k terms) with constant coefficients is a recurrence relation of the form where ciR and ck≠0 an = c1an-1+c2an-2+…+ckan-k Example 1 and 2. fn = fn-1 + fn-2 an = an-5 an= an-1 + an-22 an= nan-1 Hn= 2Hn-1 + 1 (True, deg=2) (True, deg=5) (False, 不是linear) (False , 不是linear, not constant coeff. ) (False, 不是homogeneous)
Theorem 1. Let an = c1an-1+ c2an-2 be a recurrence relation with c1,c2R. If r2 - c1r - c2= 0 (稱為characteristic equation)has two distinct roots r1 and r2. Then the solution of an is an = a1r1n + a2r2n, for n=0,1,2,…, where a1 , a2 are constants. (a1, a2可利用 a0, a1算出)
Example 3. What’s the solution of the recurrence relation an = an-1 + 2an-2 with a0=2 anda1=7 ? Sol : The characteristic equation is r2 – r - 2=0. Its two roots are r1= 2 and r2 = -1. Hence an=a12n +a2 (-1)n . ∵a0 = a1+a2 = 2, a1=2a1-a2=7 ∴a1 = 3, a2 = -1 an = 32n - (-1)n. 驗算:a2 = a1 + 2a0 =11a2= 322 -1 =11
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. Its two roots are , . So we have
Thm 2. Let an = c1an-1+c2an-2 be a recurrence relation with c1,c2R. If r2 -c1r-c2= 0 has only one root r0. Then the solution of an is an = a1 r0n + a2 n r0n for n=0,1,2,…, where a1 and a2 are constants.
Example 5. What’s the solution of an= 6an-1 - 9an-2with a0=1 and a1=6 ? Sol : The root of r2 - 6r + 9 = 0 is r0 = 3. Hence an = a1.3n+a2.n.3n . ∵a0 = a1 = 1 a1 = 3a1 + 3a2 = 6 ∴ a1 = 1 and a2 = 1 an = 3n+ n.3n 驗算:a2 = 6a1 - 9a0 =27a2= 32 +2 32 =27
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 = a1r1n +a2r2n + …+akrkn, for n = 0, 1, 2, … where a1, a2,…ak are constants.
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 = a1 1n + a2 2n + a3 3n ∵a0 = a1 + a2 + a3 = 2 a1 = a1 + 2a2 + 3a3 = 5 a2 = a1 + 4a2 + 9a3 = 15 ∴an = 1 - 2n+ 2 3n a1 = 1, a2 = -1, a3 = 2 驗算:a3 = 6a2 - 11a1+6a0 =47a3= 1 - 23 + 2 33=47
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= 0has t distinct roots r1, r2, …, rt with multiplicities m1, m2, …, mt respectively, where mi 1,i, and m1+ m2 +…+ mt = k, then (接下一頁)
where ai,jare constants. (1 i t , 0 jmi-1)
Example 8.Find the solution to the recurrence relation an = -3an-1 - 3an-2 -an-3with initial conditionsa0 = 1, a1 = -2 and a2 = -1. Sol : r3 + 3r2 + 3r + 1 = 0 has a single root r0 = -1 of multiplicity three. ∴ an= (a1+a2n+a3n2) r0n= (a1+a2n+a3n2)(-1)n ∵ a0 = a1 = 1 a1 = (a1+a2+a3) (-1) = -2 a2 = (a1+a2+a3) = -1 ∴a1 = 1, a2 = 3, a3 = -2 an = (1+3n-2n2) (-1)n 驗算:a3 = - 3a2 - 3a1-a0 =8a3= (1+33-232)(-1)3=8 Exercise : 3,13,15,19
7.4 Generating Functions. Def 1. The generating function for the sequence {an}is the infinite power series. G(x) = a0 + a1x +… + anxn +… = (若 {an}是finite,可視為是infinite,但後面的term都等於0)
Example 2. What is the generating function for the sequence 1,1,1,1,1,1 ? Sol : (expansion,展開式) (closed form)
Example 3. Let mZ+ and ,for k = 0, 1, …, m. What is the generating function for the sequence a0, a1,…, am ? Sol : G(x) = a0 + a1x + a2x2 + … + amxm = (1+x)m(by 二項式定理)
Example 5. The function f (x) = is the generating function of the sequence 1, a, a2, …, since = 1 + ax + a2x2 + …= when |ax| < 1 for a≠0
Def 2. Let uR and kZ+∪{0}. Then the extended binomial coefficient is defined by
Example 7. Find and Sol :
Thm 2. (The Extended Binomial Theorem) Let xR with |x|<1 and let uR, then
Example 9. Find the generating functions for (1+x)-n and (1-x)-n where nZ+ 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 = 3ak-1 for k=1,2,3,… and initial condition a0 = 2. Sol : 另法: (by 7.2公式 ) r – 3 = 0 r = 3 an = a 3n ∵ a0 = 2 = a ∴ an = 2 3n
Let be the generating function for {ak}. First note that ak xk= 3ak-1 xk • G(x) -a0 = 3x G(x) • ∵a0 = 2 G(x) - 3x G(x) = G(x)(1-3x) = 2 ∴ ak = 2 3k Exercise : 5,7,11,33
A -|AB|-|AC|-|BC|後 +|ABC|後 |A|+|B|+|C| 時 各部分被計算的次數 C B 7.5 Inclusion-Exclusion 排容原理 A,B,C,D : sets 1 2 1 2 1 3 1 2 0 1 2 1 1
Theorem 1. A1, A2, …, An : sets Exercise : 17
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都沒被對應) =
Thm 1.|A| = m , |B| = n There are onto functions f : A → B. pf : A = {a1, a2, …, am}. B = {b1, b2, …, bn} f (a1)= f (a2)= ︰ ︰ f (am)= b1, b2, …, bn
※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 the number of derangements of n objects. D4 = (所有4個元素的permutation數) - (4個元素有一個在原位置的permutation數) + (4元素中有二個在原位置的個數) - (4個元素中有三個在原位置的個數) + (4元素都在原位置的個數) =
Theorem 2. (亂序公式) Exercise : 8 參考:12,13