Discrete Mathematics Chapter 7 Advanced Counting Techniques 大葉大學 資訊工程系 黃鈴玲.

Slides:



Advertisements
Similar presentations
Chapter 3 Determinants and Eigenvectors 大葉大學 資訊工程系 黃鈴玲 Linear Algebra.
Advertisements

1 生物計算期末作業 暨南大學資訊工程系 2003/05/13. 2 compare f1 f2  只比較兩個檔案 f1 與 f2 ,比完後將結果輸出。 compare directory  以兩兩比對的方式,比對一個目錄下所有檔案的相 似程度。  將相似度很高的檔案做成報表輸出,報表中至少要.
: Arrange the Numbers ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11481: Arrange the Numbers 解題者:李重儀 解題日期: 2008 年 9 月 13 日 題意: 將數列 {1,2,3, …,N}
布林代數的應用--- 全及項(最小項)和全或項(最大項)展開式
第七章 抽樣與抽樣分配 蒐集統計資料最常見的方式是抽查。這 牽涉到兩個問題: 抽出的樣本是否具有代表性?是否能反應出母體的特徵?
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
1.1 線性方程式系統簡介 1.2 高斯消去法與高斯-喬登消去法 1.3 線性方程式系統的應用(-Skip-)
Lecture 8 Median and Order Statistics. Median and Order Statistics2 Order Statistics 問題敘述 在 n 個元素中,找出其中第 i 小的元素。 i = 1 ,即為找最小值。 i = n ,即為找最大值。 i = 或 ,即為找中位數。
Review of Chapter 3 - 已學過的 rules( 回顧 )- 朝陽科技大學 資訊管理系 李麗華 教授.
: OPENING DOORS ? 題組: Problem Set Archive with Online Judge 題號: 10606: OPENING DOORS 解題者:侯沛彣 解題日期: 2006 年 6 月 11 日 題意: - 某間學校有 N 個學生,每個學生都有自己的衣物櫃.
: Problem E - Beverages ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11060: Problem E - Beverages 解題者:李重儀 解題日期: 2008 年 3 月 4 日 題意: Dilbert 大學剛畢業,他決定要和朋友出去。他有奇怪的嗜好,
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
1. 假設以下的敘述為一未提供 “ 捷徑計算 ” 能力的程式段,試用程 式設計的技巧,使此敘述經此改 寫的動作後,具有與 “ 捷徑計算 ” 之 處理方法相同之處理模式。 if and then E1 else E2 endif.
第一章 演算法:效率、分析與量級 1.1演算法 1.2發展有效率演算法的重要性 1.3演算法的分析 1.4量級(Order)
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
:Problem D: Bit-wise Sequence ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10232: Problem D: Bit-wise Sequence 解題者:李濟宇 解題日期: 2006 年 4 月 16.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
: Happy Number ★ ? 題組: Problem Set Archive with Online Judge 題號: 10591: Happy Number 解題者:陳瀅文 解題日期: 2006 年 6 月 6 日 題意:判斷一個正整數 N 是否為 Happy Number.
: Fast and Easy Data Compressor ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10043: Fast and Easy Data Compressor 解題者:葉貫中 解題日期: 2007 年 3.
3.1 矩陣的行列式 3.2 使用基本運算求行列式 3.3 行列式的性質 3.4 特徵值介紹 3.5 行列式的應用
CH 15- 元件可靠度之驗證  驗證方法  指數模式之可靠度驗證  韋式模式之可靠度驗證  對數常態模式之可靠度驗證  失效數為零時之可靠度估算  各種失效模式之應用.
: Problem A : MiniMice ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11411: Problem A : MiniMice 解題者:李重儀 解題日期: 2008 年 9 月 3 日 題意:簡單的說,題目中每一隻老鼠有一個編號.
Fugacity Coefficient and Fugacity
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
資料結構實習-一 參數傳遞.
第六章 陣列.
1 Finite Continued Fractions 田錦燕 94/11/03 95/8/9( 最後更新 )
Dynamic Multi-signatures for Secure Autonomous Agents Panayiotis Kotzanikolaou Mike Burmester.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
Section 4.2 Probability Models 機率模式. 由實驗看機率 實驗前先列出所有可能的實驗結果。 – 擲銅板:正面或反面。 – 擲骰子: 1~6 點。 – 擲骰子兩顆: (1,1),(1,2),(1,3),… 等 36 種。 決定每一個可能的實驗結果發生機率。 – 實驗後所有的實驗結果整理得到。
函式 Function Part.2 東海大學物理系‧資訊教育 施奇廷. 遞迴( Recursion ) 函式可以「呼叫自己」,這種動作稱為 「遞迴」 此程式的執行結果相當於陷入無窮迴圈, 無法停止(只能按 Ctrl-C ) 這給我們一個暗示:函式的遞迴呼叫可以 達到部分迴圈的效果.
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
: Expect the Expected ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11427: Expect the Expected 解題者:李重儀 解題日期: 2008 年 9 月 21 日 題意:玩一種遊戲 (a game.
-Antidifferentiation- Chapter 6 朝陽科技大學 資訊管理系 李麗華 教授.
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Chapter 2. Recurrence Relations (遞迴關係)
Chapter 10 m-way 搜尋樹與B-Tree
演算法課程 (Algorithms) 國立聯合大學 資訊管理學系 陳士杰老師 Course 7 貪婪法則 Greedy Approach.
計算機概論 第6章 數位邏輯設計.
2005/7 Linear system-1 The Linear Equation System and Eliminations.
: Mini Cube ★★★★★ 題組: Problem Set Archive with Online Judge 題號: 11007: Mini Cube 解題者:郭峻維 解題日期: 2007 年 3 月 27 日 題意:找出 2x2x2 的 Rubik‘s cube 的最佳解。
Visual C++重點複習.
資料結構實習-六.
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Problem E.Stone Game ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10165: Problem E.Stone Game 解題者:李濟宇 解題日期: 2006 年 3 月 26 日 題意: Jack 與 Jim.
結構學 ( 一 ) 第八次作業 97/05/22. 題目一 題目一 (a) 先決定放鬆哪個束制,成為靜定結構 以支承 C 之水平反力為贅力,則 C 點滾支 承變成自由端,即形成靜定基元結構 C 點滿足變位諧和  Δ CH =0.
: How many 0's? ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11038: How many 0’s? 解題者:楊鵬宇 解題日期: 2007 年 5 月 15 日 題意:寫下題目給的 m 與 n(m
Discrete Mathematics Chapter 4 Induction and Recursion 大葉大學 資訊工程系 黃鈴玲 (Lingling Huang)
7.4 Generating Functions Definition 1: The generation function for the sequence a 0, a 1,...,a k,... of real numbers is the infinite series G(x) = a 0.
Chapter 5 Laplace Transforms
Discrete Mathematics Chapter 4 Counting 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Discrete Mathematics Chapter 3 Mathematical Reasoning, Induction, and Recursion 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供.
Chapter 2 Combinatorial Analysis 主講人 : 虞台文. Content Unordered Samples without Replacement  Combinations Binomial Coefficients Some Useful Mathematic.
Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.
Discrete Mathematics Chapter 2 Basic Structures : Sets, Functions, Sequences, and Sums 大葉大學 資訊工程系 黃鈴玲 (Lingling Huang)
Chapter 3 Trees and Forests 大葉大學 資訊工程系 黃鈴玲
Discrete Mathematics Chapter 7 Relations 感謝 大葉大學 資訊工程系 黃鈴玲老師 提供.
Discrete Mathematics Section 3.7 Applications of Number Theory 大葉大學 資訊工程系 黃鈴玲.
Discrete Mathematics Chapter 5 Counting.
Discrete Mathematics Chapter 5 Counting 大葉大學 資訊工程系 黃鈴玲.
Discrete Mathematics Chapter 6 Advanced Counting Techniques.
Advanced Counting Techniques
Chapter 7 Advanced Counting Techniques
ICS 253: Discrete Structures I
Presentation transcript:

Discrete Mathematics Chapter 7 Advanced Counting Techniques 大葉大學 資訊工程系 黃鈴玲

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

Ch 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. 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 } ?

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   P n  1 =1.11  P n  1, ∴ P 30 =1.11  P 29 =(1.11) 2  P 28 =…=(1.11) 30  P 0 = P 0 =10000

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

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 (2H n  3 +1)+2+1 =2 3 H n  3 +( ) : =2 n  1 H 1 +(2 n  2 +2 n  3 +…+1) =2 n  1 +2 n  2 +…+1 = =2 n  1

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.

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

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

Ch 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  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)

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

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 順序可交換, 結果會一樣

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

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.

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   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 =27

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.

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 r – 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 =    3 = 5 a 2 =    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   3 3 =47

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.

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

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

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.

Ch7-22 Example 9: a n = a n  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

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)

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

Ch7-25 Example 11. Find all solutions of the recurrence relation a n = 5a n  1  6a n  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  n, then c  7 n = 5c  7 n  1  6c  7 n  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

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.

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

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

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 

Ch 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 )

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) =

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

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 下面的二項式定理 )

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)

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 +… =

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

Example 7. Find and Sol : Ch7-37 Def 2. Let u  R and k  N. Then the extended binomial coefficient is defined by

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.

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

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)

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 種

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

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

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

Ch7-45 Example 17 Solving a k = 8a k  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 ( 為計算方便而假設 ).

Ch7-46 ∴ a k = (10 k + 8 k )/2 Exercise: 33

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

Ch7-48 Theorem 1. A 1, A 2, …, A n : sets Exercise : 10, 11, 17

Ch 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 )

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

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

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

Ch7-53 Def. A derangement is a permutation of objects that leaves no object in its original position. Derangements ( 亂序 ) Example 5. The permutation is a derangement of But is not a derangement of

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.

Ch7-55 Theorem 2. ( 亂序公式 ) Exercise : 13 Proof.

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 :