38810861-Chapter-2-Advance-Counting-Technique

March 28, 2018 | Author: Dilip Dubey | Category: Recurrence Relation, Mathematical Concepts, Discrete Mathematics, Logic, Elementary Mathematics


Comments



Description

BCT 2083 DISCRETE STRUCTURE ANDBCT 2083 DISCRETE STRUCTURE AND APPLICATIONS APPLICATIONS CHAPTER 2 CHAPTER 2 ADVANCE COUNTING ADVANCE COUNTING TECHNIQUE TECHNIQUE SITI ZANARIAH SATARI SITI ZANARIAH SATARI FSTI/FSKKP UMP I1011 FSTI/FSKKP UMP I1011 C H A P T E R 2 A D V A N C E C O U N T I N G T E C H N I Q U E CONTENT CONTENT 2.1 Recurrence Relations 2.2 Solving Recurrence Relations 2.3 Divide-and-Conquer Relations 2.4 Generating Functions 2.5 Inclusion-Exclusion 2.6 Application of Inclusion-Exclusion C H A P T E R 2 A D V A N C E C O U N T I N G T E C H N I Q U E – Product rule – Sum rule – The Inclusion-Exclusion Principle – Tree Diagrams – The Pigeonhole Principle – Permutations – Combinations 1 2 1 2 1 2 A A A A A A ∪ · + − ∩ RECALL – Counting technique RECALL – Counting technique Number of ways = n1n2 ··· nm Number of ways = n1 + n2 +…+ nm If N objects are placed into k boxes, then there is at least one box containing at least objects. N k ] ] ( ) ( ) ( ) ( ) ( ) ! , 1 2 1 ! n P n r n n n n r n r · − − − + · − L ( ) ( ) ! , ! ! n n Cnr r r n r |` ·· − ., 2.1 RECURRENCE RELATIONS 2.1 RECURRENCE RELATIONS • Define and develop a recurrence relation • Model a problem using recurrence relation • Find the solution of recurrence relations with the given initial conditions C H A P T E R 2 A D V A N C E C O U N T I N G T E C H N I Q U E 2 . 1 R E C U R R E N C E R E L A T I O N The number of bacteria in a colony doubles every hour. If the colony begins with 5 bacteria, how many will be present in n hours? Let an : the number of bacteria at the end of n hours Then; an = 2an-1, a0=5 What we are doing actually? We find a formula/model for an (the relationship between an and a0) – this is called recurrence relations between the term of sequence. Motivation Motivation Solution: Since bacteria double every hour Initial condition By using recursive definition 2 . 1 R E C U R R E N C E R E L A T I O N • Recursion – a process to define an object explicitly • The object can be a sequence, function or set (for BCT2078 purposes) • The ideas – construct new elements from known elements. • Process – specify some initial elements in a basis step and provide a rule for constructing new elements from those we already have in the recursive step. • Mathematical Induction can be used to prove the result. Recursive (Inductive) Recursive (Inductive) Definitions Definitions The given complex problem This simple version can be solved This simple version can be solved Can be solved if Can be solved if Can be solved if an = 2an-1 an-1 = 2an-2, a1 = 2a0, a0=5 2 . 1 R E C U R R E N C E R E L A T I O N • A recursive algorithm provides the solution of a problem of size n in term of the solutions of one or more instances of the same problem in smaller size. • The initial condition specify the terms that precede the first term where the recurrence elation takes effect. Recurrence Relation Recurrence Relation A recurrence relation for the sequence {an} is an equation that expresses an in terms of one or more of the previous terms of the sequence, namely, a0, a1,…, an-1, for all integers n with n ≥ n0, where n0 is a nonnegative integer. A sequence is call solution of a recurrence relation if its term satisfy the recurrence relation. an = 2an-1 a0 = 5 Initial condition Recurrence relation Recursive definition 2 . 1 R E C U R R E N C E R E L A T I O N Let {an} be a sequence that satisfies the recurrence relation an = an-1 – an-2 for n = 2, 3,4, and suppose that a0 =3 and a1 = 5. List the first four term. a0 = 3 a1 = 5 a2 = a1 – a0 = ___________________ a3 = __________________________ What is a5? a5 = __________________________ Example 2.1.1 Example 2.1.1 2 . 1 R E C U R R E N C E R E L A T I O N Determine whether {an} where an = 3n for every nonnegative integer n, is a solution of recurrence relation an = 2an-1 – an-2 for n = 2, 3, 4, … Suppose that an = 3n for every nonnegative integer n, Then for n ≥ 2; 2an-1 – an-2 = ___________________ Therefore, Determine whether {an} where an = 5 for every nonnegative integer n, is a solution of recurrence relation an = 2an-1 – an-2 for n = 2, 3, 4, … 2an-1 – an-2 = ___________________ Example 2.1.2 Example 2.1.2 2 . 1 R E C U R R E N C E R E L A T I O N 1. Let an denotes the nth term of a sequence satisfying the given initial condition (s) and the recurrence relation. Compute the first four terms of the sequence. EXERCISE 2.1 EXERCISE 2.1 0 1 1 128, for 1 4 n n a a a n − · · ≥ A B C D E 1 1 5, 7 2 for 2 n n b b b n − · · − ≥ ( ) 2 1 1 1 2, 3 2 for 2 n n n a a a a n − − · − · − − ≥ 1 2 3 1 2 3 1, 2, 3, for 4 n n n n d d d d d d d n − − − · · · · + + ≥ 1 2 1 2 1, 2, 3 for 3 n n n a a a a a n − − · · · + ≥ 2 . 1 R E C U R R E N C E R E L A T I O N 2. Is the sequence {an} a solution of the if 3. Is the sequence {an} a solution of the if 4. Show that the sequence {an} is a solution of the recurrence relation if EXERCISE 2.1 EXERCISE 2.1 2 1 n a n · − 1 2 3 2 n n n a a a − − · − − 1 2 2 2 n n n a a a − − · − + 2 3 n a n · − ( ) 3 n n a · − 1 2 3 6 n n n a a a − − · − + 2 . 1 R E C U R R E N C E R E L A T I O N • We can use recurrence relation to model a wide variety of problems such as – Finding a compound interest – Counting a population of rabbits – Determining the number of moves in the Tower of Hanoi puzzle – Counting bit strings Modeling with Recurrence Modeling with Recurrence Relation Relation 2 . 1 R E C U R R E N C E R E L A T I O N Suppose that a person deposits RM10,000 in a savings account at a bank yielding 11% per year with interest compounded annually. Define recursively the compound amount in the account at the end of n years. Let an : the amount in the account after n years Then; an = (compound amount at the end of (n -1)th years) + (interest for the nth years) an = an-1 + 0.11an-1 = 1.11 an-1 With initial condition; a0 = 10,000 Example 2.1.3: Compound Example 2.1.3: Compound interest interest Solution: 2 . 1 R E C U R R E N C E R E L A T I O N A young pair of rabbits (one of each sex) is placed on an island. A pair of rabbits does not breed until they are 2 months old. After they are 2 months old, each pair of rabbits produces another pair each month. Find a recurrence relation for the numbers of pairs of rabbits on the island after n months if all the rabbits alive. Let fn : the numbers of pairs of rabbits on the island after n months Then; fn = (number of pairs of rabbits in (n -1)th months) + (number of newborn pairs of rabbits) fn = fn-1 + fn-2 With initial condition; f1 = 1 and f2 = 1 ; n ≥ 3 Example 2.1.4: Population of Example 2.1.4: Population of rabbits rabbits Solution: WHY??? [Problem develop by Leonardo Pisano (Liber abaci, 13 th century) – lead to Fibonacci number] 2 . 1 R E C U R R E N C E R E L A T I O N Example 2.1.4: Population of Example 2.1.4: Population of rabbits rabbits 2 . 1 R E C U R R E N C E R E L A T I O N • Popular Puzzle invented by Edouard Lucas (French Mathematician, late 19 th century) RULES OF PUZZLE: – Suppose we have 3 pegs labeled A, B, C and a set of disks of different sizes. – These disks are arranged from the largest disk at the bottom to the smallest disk at the top (1 to n disks) on peg A. – The goal: to have all disks on peg C in order of size, with the largest on the bottom. – Only one disk is allow to move at a time from a peg to another. – Each peg must always be arranged from the largest at the bottom to the smallest at the top Example 2.1.5: Tower of Hanoi Example 2.1.5: Tower of Hanoi 2 . 1 R E C U R R E N C E R E L A T I O N ILLUSTRATION: SOLUTION Example 2.1.5: Tower of Hanoi Example 2.1.5: Tower of Hanoi A B C A B C Initial Position in the Tower of Hanoi Intermediate Position in the Tower of Hanoi n disks n-1 disks Hn-1 moves Let Hn : the numbers of moves with n disks transfer the top of n-1 disks to peg B 2 . 1 R E C U R R E N C E R E L A T I O N ILLUSTRATION: SOLUTION Example 2.1.5: Tower of Hanoi Example 2.1.5: Tower of Hanoi A B C A B C Intermediate Position in the Tower of Hanoi Last Position in the Tower of Hanoi 1 disks n disks Hn-1 moves Moves the largest disk to peg C transfer the top of n-1 disks to peg B 1 move 2 . 1 R E C U R R E N C E R E L A T I O N Thus the number of moves is given by: Where: Example 2.1.5: Tower of Hanoi Example 2.1.5: Tower of Hanoi Solution (continue): 1 1 2 1 ; 1 n n H H H − · + · Hn-1 moves Moves the largest disk to peg C transfer the top of n-1 disks to peg B 1 move Hn-1 moves transfer the top of n-1 disks to peg B + + 2 . 1 R E C U R R E N C E R E L A T I O N 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 bit strings are there of six length? Let an : number of bit strings of length n that do not have two consecutive 0s Then; an = (number of bit strings of length n-1 that do not have two consecutive 0s) + (number of bit strings of length n-2 that do not have two consecutive 0s) an = an-1 + an-2 ; n ≥ 3 With initial condition; a1 = 2, both strings of length 1 do not have consecutive 0s ( 0 and 1) a2 = 3, the valid strings only 01, 10 and 11 Example 2.1.6: Bit Strings Example 2.1.6: Bit Strings Solution: Solve yourself 2 . 1 R E C U R R E N C E R E L A T I O N A computer system considers a string of decimal digits a valid codeword if it contains an even number of 0 digits. For instance, 1230407869 is valid, whereas 120987045608 is not valid. Let an be the number of valid n-digit codewords. Find a recurrence relation for an. Let an : the number of valid n-digit codewords Then; an = (number of valid n-digit codewords obtained by adding a digit other than 0 at the end of a valid string of length n – 1) + (number of valid n-digit codewords obtained by adding a digit 0 at the end of an invalid string of length n – 1) With initial condition; a1 = 9, there are 10 one-digit strings and only one the string 0 not valid Example 2.1.7: Example 2.1.7: Codeword Codeword enumeration enumeration Solution: ( ) 1 1 1 1 1 9 10 8 10 n n n n n n a a a a − − − − − · + − · + 2 . 1 R E C U R R E N C E R E L A T I O N A valid codeword of length n can be formed by: A) Adding a digit other than 0 at the end of a valid string of length n – 1 - This can be done in nine ways. Hence, a valid string with n digits can be formed in this manner in ways. B) Adding a digit 0 at the end of an invalid string of length n – 1 - This produces a string with an even number of 0 digits because the invalid string of length n – 1 has an odd number of 0 digits. The number of ways that this can be done equals the number of invalid (n – 1)-digit strings. Because there are strings of length n – 1, and are valid, then there are invalid (n – 1)-digit strings. Thus; Example 2.1.7: Example 2.1.7: Codeword Codeword enumeration enumeration ( ) 1 1 1 1 1 1 9 10 8 10 , 9, 2 n n n n n n a A B a a a a n − − − − − · + · + − · + · ≥ 1 9 n a − 1 10 n− 1 n a − 1 1 10 n n a − − − 2 . 1 R E C U R R E N C E R E L A T I O N 6. Define recursively : 1, 4, 7, 10, 13, … 7. Judy deposits RM1500 in a local savings bank at an annual interest rate of 8% compounded annually. Define recursively the compound amount an she will have in her account at the end of n years. How much will be in her account after 3 years? 8. There are n students at a class. Each person shakes hands with everybody else exactly one. Define recursively the number of handshakes that occur. EXERCISE 2.1 EXERCISE 2.1 2 . 1 R E C U R R E N C E R E L A T I O N 9. Find a recurrence relation and initial condition for the number of ways to climb n stairs if the person climbing the stairs can take one, two or three stairs at a time. How many ways can this person climb a building with eight stairs? 10. Find a recurrence relation and initial condition for the number of bit strings of length n that contain three consecutive 0s. How many bit strings of length seven contain three consecutive 0s? 11. Find a recurrence relation for the number of bit sequences of length n with an even number of 0s? EXERCISE 2.1 EXERCISE 2.1 2 . 1 R E C U R R E N C E R E L A T I O N EXERCISE 2.1 : EXTRA EXERCISE 2.1 : EXTRA PAGE : 456, 457, 458, 459 and 460 Rosen K.H., Discrete Mathematics & Its Applications, (Seventh Edition), McGraw-Hill, 2007. 2.2 2.2 SOLVING RECURRENCE RELATION SOLVING RECURRENCE RELATION • Solve a recurrence relation using iterative method • Solve a linear homogeneous recurrence relation with constant coefficients • Solve a linear nonhomogeneous recurrence relation with constant coefficients C H A P T E R 2 A D V A N C E C O U N T I N G T E C H N I Q U E 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N • Solving the recurrence relation for a function f means finding an explicit formula for f (n). The iterative method of solving it involves two steps: – Apply the recurrence formula iteratively and look for the pattern to predict an explicit formula  Forward: start from a0 to an  Backward : start from an to a0 – Use Induction to prove that the formula does indeed hold for every possible value of the integer n. Iterative Method Iterative Method 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Using the iterative method, predict a solution for the following recurrence relation with the given initial condition. Example 2.2.1 (a): Iterative Example 2.2.1 (a): Iterative Method Method ( ) ( ) ( ) 0 1 0 2 2 1 0 0 2 3 3 2 0 0 1 1 0 0 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ; 1 n n n n n S S S S S S S S S S S S S S S n − − · · · · · · · · · · · · ≥ M Solution: (FORWARD) 1 0 2 ; 1 n n S S S − · · Solution: (BACKWARD) 1 2 2 3 3 0 2 2 2 2 2 n n n n n n S S S S S − − − · · · · · M 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Objective: To proof that the statement P(n) is true for each integer n ≥ n0 Steps: 1. Prove that the statement is true for n = n0. 2. Assume that the statement is true for n = k. 3. Prove that the statement is true for n = k + 1. 4. Conclusion: Therefore, the statement is true for each integer n ≥ n0 Recall: Mathematical Induction Recall: Mathematical Induction 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Using induction, verify the solution for the recurrence relation is given by . 1. Prove that the statement is true for n = n0. 2. Assume that the statement is true for n = k . 3. Prove that the statement is true for n = k + 1. 4. Conclusion: Therefore, the statement is true for each integer n ≥ n0 Example 2.2.1 (b): Induction Example 2.2.1 (b): Induction 2 ; 1 n n S n · ≥ Solution: 1 0 2 ; 1 n n S S S − · · Assume 2 ; 1 is true k k S k · ≥ 1 1 2 2 S · · ( ) 1 1 2 2 2 2 k k k k S S + + · · · 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Suppose that a person deposits RM10,000 in a savings account at a bank yielding 11% per year with interest compounded annually. How much will be in the account after 30 years? Let an : the amount in the account after n years Then; an = (compound amount at the end of (n -1)th years) + (interest for the nth years) an = an-1 + 0.11an-1 = 1.11 an-1 , n ≥ 1 With initial condition; a0 = 10,000 Example 2.2.2: Compound Example 2.2.2: Compound interest interest Solution: 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N By iterative approach: Thus, after 30 years the amount in the account will be: ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) 0 1 0 2 2 1 0 3 3 2 0 1 0 10000 1.11 1.11 1.11 1.11 1.11 1.11 1.11 1.11 10000 n n n n a a a a a a a a a a a a − · · · · · · · · · M Example 2.2.2: Compound Example 2.2.2: Compound interest interest Solution (continue): ( ) ( ) 30 30 1.11 10000 ___________ a · · PROVE BY INDUCTION ! 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N The number of moves is given by: By iterative approach: ( ) ( ) 1 2 2 2 2 3 2 3 3 1 2 3 1 1 2 3 2 1 2 2 1 1 2 2 1 2 2 1 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 2 1 n n n n n n n n n n n n n H H H H H H H − − − − − − − − − − − · + · + + · + + · + + + · + + + · + + + + + · + + + + + · − M K K Example 2.2.3: Tower of Hanoi Example 2.2.3: Tower of Hanoi 1 1 2 1 ; 1 n n H H H − · + · PROVE BY INDUCTION ! 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N 1. Using iterative method, predict a solution to each of the following recurrence relation. Verify the solutions using induction • • 1. There are n students at a class. Each person shakes hands with everybody else exactly one. Define recursively the number of handshakes that occur. Solve this recurrence relation using iterative method and prove it using induction. 2. If a deposit of RM100 is made on the first day of each month into an account that pays 6% interest per year compounded monthly, show that the amount in the account after 18 years is RM 38929. 1 0 4 ; 0 ; 1 n n a a n a n − · + · ≥ EXERCISE 2.2.1 EXERCISE 2.2.1 2 1 1 ; 1 ; 2 n n b b n a n − · + · ≥ 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N A linear homogeneous recurrence relation of degree k with constant coefficients is a recurrence relation of the form an = c1an-1 + c2an-2 + … + ckan-k Where c1, c2,…, ck are real numbers and ck ≠ 0 Linear Homogeneous Recurrence Relations with constant coefficients Linear : The RHS is the sum of previous terms of the sequence each multiplied by a function of n. Homogeneous : No terms occur that are not multiplies of the aj s. Degree k : an is expressed in terms of the previous k terms of the sequence Constant coefficients : c1, c2,…, ck Recurrence relation : with k initial condition a0 = C0, a1 = C1, … ak-1= Ck-1 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Linear Homogeneous Recurrence Relation Pn = (1.11) Pn-1 degree one fn = fn-1 + fn-2 degree two an = an-5 degree five Not Linear Homogeneous Recurrence Relation Hn = 2Hn-1 + 1 Bn = nBn-1 an = an-1 + a²n-2 Example 2.2.4: Example 2.2.4: Linear Linear Homogeneous RR Homogeneous RR 1. Often occur in modeling of problems 2. Can be systematically solved 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N • OUR AIM – look for the solutions of the form , where r is constant. • Note that, is a solution of the recurrence relation an = c1an-1 + c2an-2 + … + ckan-k iff . • When both sides of this equation are divided by and the RHS is subtracted from the left, we obtain a characteristic equation: • The solution of this equation are called the characteristics roots. Solving Linear Homogeneous Recurrence Relations with constant coefficients n n a r · n n a r · 1 2 1 2 n n n n k k r c r c r c r − − − · + + + K 1 2 1 2 1 0 k k k k k r c r c r c r c − − − − − − − − · K n k r − 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Let c1, c2, …, ck be real numbers. Suppose that the characteristics equation has k distinct roots r1, r2, …, rk. Then a sequence {an} is a solution of the recurrence relation an = c1an-1 + c2an-2 + … + ckan-k iff for n ≥ 0 and α1, α2, …, αk constant. If the characteristic equation has several (m) repeated roots, then the solution of the recurrence relation is given by: Solving Linear Homogeneous Recurrence Relations with constant coefficients 1 1 2 2 n n n n k k a r r r α α α · + + + K 1 2 1 2 1 0 k k k k k r c r c r c r c − − − − − − − − · K 1 1 2 1 1 n n m n n n m k k a r nr n r r α α α α · + + + + + K K 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Solve the recurrence relation an = 5an-1 - 6an-2 where a0 = 4 and a1 = 7. 1) Find the general solution of the recurrence relation • the characteristic equation is given by • the characteristic roots are 2 and 3 • thus, the general solution is 1) Find the constant values, A and B using the initial conditions • Solving the linear system: : A = 5, B = -1 1) Thus the solution to the recurrence relation and initial conditions is . Example 2.2.5: Example 2.2.5: Second-Order Second-Order LHRRWCCs LHRRWCCs Solution: 5 2 3 , 0 n n n a n · ⋅ − ≥ 2 3 n n n a A B · ⋅ + ⋅ 2 5 6 0 r r − + · 0 1 4 2 3 7 a A B a A B · + · · + · 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Solve the recurrence relation an = 6an-1 - 11an-2 + 6an-3 where a0 = 2, a1 =5, and a2 = 15. 1) Find the general solution of the recurrence relation • the characteristic equation is given by • the characteristic roots are 1, 2 and 3 • thus, the general solution is 1) Find the constant values, A and B using the initial conditions • Solving the linear system: (A = 1, B = -1, C = 2) 1) Thus the unique solution to the recurrence relation and initial conditions is . Example 2.2.6: Example 2.2.6: Higher-Order Higher-Order LHRRWCCs LHRRWCCs Solution: 1 2 2 3 , 0 n n n a n · − + ⋅ ≥ 1 2 3 n n n n a A B C · ⋅ + ⋅ + ⋅ 3 2 6 11 6 0 r r r − + − · 0 1 2 2, 2 3 5, 4 9 15 a A B C a A B C a A B C · + + · · + + · · + + · 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Suppose that the roots of the characteristic equation of a linear homogenous recurrence relation are 2, 2, 2, 5, 5, and 9. What is the form of general solution? Thus the general solution to the recurrence relation is Example 2.2.7: Example 2.2.7: LHRRWCCs with LHRRWCCs with multiple roots multiple roots Solution: ( ) ( ) 2 2 2 2 2 5 5 9 2 5 9 n n n n n n n n n n a A Bn Cn D En F A Bn Cn D En F · + + + + + ⋅ · + + + + + ⋅ 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N 1. What is the solution of the following recurrence relation • • • 1. Find an explicit formula for Fibonacci numbers. EXERCISE 2.2.2 EXERCISE 2.2.2 1 2 0 1 2 ; 2, 7 n n n a a a a a − − · + · · 1 2 0 1 6 9 ; 1, 3 n n n a a a a a − − · − · · 1 2 3 0 1 2 3 3 ; 1, 2, 1 n n n n a a a a a a a − − − · − − − · · − · − 1 2 1 2 ; 1, 1 n n n F F F F F − − · + · · 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N • A Linear Nonhomogenous recurrence relation with constant coefficients (LNHRRWCCs), that is a recurrence relation of the form an = c1an-1 + c2an-2 + … + ckan-k + F (n) . • Where – c1, c2, …, ck are real numbers – F (n) is a function not identically zero depending only n – c1an-1 + c2an-2 + … + ckan-k is called the associated homogenous recurrence relation • Example: Linear NonHomogenous Recurrence Relations with constant coefficients 2 1 2 1 n n n a a a n n − − · + + − + 1 2 3 n n n a a n − · + 1 3 2 n n a a n − · + 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Let be the general solution of c1an-1 + c2an-2 + … + ckan-k And be the particular solution of LNHRRWCCs, an = c1an-1 + c2an-2 + … + ckan-k + F (n) Then the general solution of LNHRRWCCs is given by There is no general method to find the particular solution. Solving Linear NonHomogenous Recurrence Relations with constant coefficients ( ) p n a ( ) h n a ( ) ( ) h p n n n a a a · + 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Suppose that {a n } satisfy the linear nonhomogenous recurrence relation And (i)When s is not a root of the characteristic equation, there is a particular solution of the form (ii) When s is a root of the characteristic equation , there is a particular solution of the form THEOREM 6 THEOREM 6 1 1 1 2,..., ... ( ) where , n n k n k k a c a c a F n c c c − − · + + + ∈ℜ 1 1 1 0 0 1 ( ) ( ... ) where , ,..., , t t n t t t F n b n b n b n b s b b b s − − · + + + ∈ℜ 1 1 1 0 ( ... ) t t n t t p n p n p n p s − − + + + 1 1 1 0 ( ... ) m t t n t t n p n p n p n p s − − + + + 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N Find all the solutions of recurrence relation an = 3an-1 + 2n 1) Find the general solution of the associated linear homogenous (ALH) equation. • the ALH equation is given by an = 3an-1 • thus, the general solution is 1) Find the particular solution • Since F(n) = 2n is polynomial with degree 1, then the trial solution linear function: pn = cn + d (c and d are constant) • The equation an = 3an-1 + 2n then become • Solve for c and d will gives c = -1 and d = -3/2 • Thus, the particular solution is 1) Thus the unique solution to the recurrence relation is Example 2.2.8: Example 2.2.8: LNHRRWCCs LNHRRWCCs Solution: ( ) 3 h n n a A · ⋅ 3 3 2 n n a A n · ⋅ − − ( ) ( ) 3 1 2 0 cn d c n d n + · − + + · ( ) 3 2 p n a n · − − 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N 1. What is the solution of the following recurrence relation • • 1. What form does a particular solution of linear nonhomogeneous recurrence relation when EXERCISE 2.2.3 EXERCISE 2.2.3 2 1 2 0 1 5 6 8 ; 4, 7 n n n a a a n a a − − · − + · · 1 2 0 1 5 6 7 ; 4, 7 n n n n a a a a a − − · − + · · ( ) 1 2 6 9 n n n a a a F n − − · − + ( ) ( ) ( ) ( ) ( ) ( ) ( ) 2 2 3 , 3 , 2 4 1 3 , 1 3 n n n n n F n F n n F n n F n n F n n · · · · + · + 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N EXERCISE 2.2 : EXTRA EXERCISE 2.2 : EXTRA PAGE : 456, 457, 458, 459 and 460 471, 472, and 473 Rosen K.H., Discrete Mathematics & Its Applications, (Seventh Edition), McGraw-Hill, 2007. 2.3 2.3 DIVIDE-AND-CONQUER RELATIONS DIVIDE-AND-CONQUER RELATIONS • Describe a divide-and-conquer algorithm • Analyze the computational complexity of divide-and-conquer algorithm using recurrence relation • Estimate the number of operations used by divide-and-conquer algorithm C H A P T E R 2 A D V A N C E C O U N T I N G T E C H N I Q U E 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • A procedure is called divide-and-conquer algorithm because – They DIVIDE a problem into one or more instances of the same problem of smaller size – & – They CONQUER the problem by using the solutions of the smaller problems to find a solution of the original problem • Example: – Binary search – Multiplying integers Divide-and-Conquer Algorithm Divide-and-Conquer Algorithm 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • Suppose that – A recursive algorithm divides a problem of size n into a subproblems, where each subproblem is of size n/b. – A total of g (n) extra operations are required in the conquer step of the algorithm to combine the solutions of the subproblems into a solution of the original problem. • Then, if f (n) represents the number of operations required to solve the problem of size n, it follows that f satisfies the recurrence relation – f (n) = a f (n/b) + g (n) • This is called a divide-and conquer recurrence relation Divide-and-Conquer Recurrence Divide-and-Conquer Recurrence Relations Relations 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • What happen in Binary search: – A subproblem is used: The algorithm reduces the search for an element in a search sequence of size n to the binary search for an element in a search sequence of size n/2, n even. – g (n) : two comparisons are needed to implement this reduction 1. to determine which half of the list to use 2. to determine whether any terms of the list remain • If f (n) represents the number of comparisons required to search for an element in a search sequence of size n, then – f (n) = a f (n/b) + g (n) = f (n/2) + 2 , n even Example 2.3.1: Binary Search Example 2.3.1: Binary Search 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • Locating the maximum and minimum elements of a sequence a1, a2, …, an: – 2 subproblems are used: • If n = 1, then a1 is the maximum and minimum • If n > 1, then the sequence split into 2 sequences ( either where both have the same number of elements or where one of the sequences has one ore element than the other), let say n/2 • The problem is reduced to find the maximum and minimum of each of the two smaller sequences • The solution for original problem is the comparison result from these two smaller sequences – g (n) : two comparisons are needed to implement this reduction 1. to compare the maxima of two sequences 2. to compare the minima of two sequences • If f (n) represents the total number of comparisons needed to find then maximum and minimum elements of the sequence with n elements, then – f (n) = a f (n/b) + g (n) = 2f (n/2) + 2 , n even Example 2.3.2: Maximum and Example 2.3.2: Maximum and Minimum Minimum 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • What happen in Merge Sort: – Splits a list to be sorted with n items, where n even, into two lists with size n/2 elements each – g (n) : uses fewer than n comparisons to merge the sorted lists of n/2 items each into one sorted list • Consequently, the number of comparisons used by the merge sort to sort a list of n element is less than M (n) where, – M (n) = a f (n/b) + g (n) = 2 M (n/2) + n Example 2.3.3: Merge Sort Example 2.3.3: Merge Sort 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • Let a, b є N and c, d є R⁺ with b > 1. Let f be an increasing function that satisfies the recurrence relation f (n) = a f (n/b) + c and f (1) = d. Then • Furthermore, when , where k is a positive integer and a > 1; where Theorem 1 Theorem 1 ( ) log 1 2 1 2 b a k f n C n C C a C · + · + k n b · ( ) ( ) ( ) log if 1 log if 1 b a O n a f n O n a ¹ > ¹ · ' · ¹ ¹ ( ) ( ) ( ) 1 2 1 1 and 1 C f c a C c a · + − · − − 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • Let f (n) = 5 f (n/2) + 3 and f (1) = 7. Find where k is a positive integer. Also estimate f (n) if f is increasing function Solution: a = 5, b = 2, c = 3, then If f is increasing function, Example 2.3.4 Example 2.3.4 ( ) ( ) ( ) ( ) ( ) ( ) 1 1 1 5 7 3 4 3 4 5 31 4 3 4 k k k f n a f c a c a · + − + − − ] ] ] ] · + − ] ] · − ( ) 2 k f ( ) ( ) ( ) 2 log log 5 b a f n O n O n · · 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • Estimate the number of comparisons used by binary search Solution: When n is even, Where f is the number of comparisons required to perform a binary search on a sequence of size n. Hence, Example 2.3.5: Binary search Example 2.3.5: Binary search ( ) ( ) / 2 2 f n f n · + ( ) ( ) log f n O n · 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • Estimate the number of comparisons used to locate the maximum and minimum elements. Solution: When n is even, Where f is the number of comparisons needed. Hence, Example 2.3.6: maximum and Example 2.3.6: maximum and minimum minimum ( ) ( ) 2 / 2 2 f n f n · + ( ) ( ) ( ) log2 f n O n O n · · 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • Let a, b є N and c, d є R⁺ with b > 1. Let f be an increasing function that satisfies the recurrence relation Then whenever , where k is a positive integer Master Theorem Master Theorem ( ) ( ) d f n af n b cn · + k n b · ( ) ( ) ( ) ( ) log if log if if b d d d d a d O n a b f n O n n a b O n a b ¹ < ¹ ¹ · · ' ¹ > ¹ ¹ 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S • Estimate the number of comparisons used by the merge sort to sort a list of n elements. Solution: The number of comparisons is less than M (n) where Hence, Example 2.3.7: Complexity of Example 2.3.7: Complexity of merge sort merge sort ( ) ( ) 2 / 2 M n M n n · + ( ) ( ) log M n O n n · 2 . 2 S O L V I N G R E C U R R E N C E R E L A T I O N 1. Find f (n) when where f satisfies the recurrence relation f (n) = 2 f (n/3) + 1 with f (1) = 1. Estimate the solution f (n) if f is an increasing function. 2. Suppose that there are teams in an elimination tournament, where there are n/2 games in the first round, with the winners playing in the second round, and so on. a. How many rounds are in the elimination tournament when there are 32 teams? b. Use Divide-and-Conquer algorithm to develop a recurrence relation for the number of rounds in the tournament. c. Solve the recurrence relation. EXERCISE 2.3 EXERCISE 2.3 3 k n · 1 / 2 2 k n − · 2 k n · 2 . 3 D I V I D E - A N D - C O N Q U E R R E L A T I O N S EXERCISE 2.3 : EXTRA EXERCISE 2.3 : EXTRA PAGE : 482, 483 and 484 Rosen K.H., Discrete Mathematics & Its Applications, (Seventh Edition), McGraw-Hill, 2007. 2.4 GENERATING FUNCTIONS 2.4 GENERATING FUNCTIONS • Represent a sequence as generating function • Solve counting problems using generating function • Solve recurrence relation using generating function C H A P T E R 2 A D V A N C E C O U N T I N G T E C H N I Q U E 2 . 4 G E N E R A T I N G F U N C T I O N S The generating function for the sequence a0, a1,…,ak,… of real numbers is the infinite series REMARKS: sometimes, this generating function for {ak} is called the ordinary generating function of ak USEFUL GENERATING FUNCTIONS refer hand-out or text book page 489 and 157 Generating Function of infinite Generating Function of infinite Sequence Sequence ( ) 0 1 0 k k k k k G x a a x a x a x ∞ · · + + + + · ∑ L L formal power series 2 . 4 G E N E R A T I N G F U N C T I O N S The generating function for the following sequences {ak} are given by: Example 2.4.1 Example 2.4.1 ( ) ( ) ( ) ( ) 0 0 0 3, 3 1, 1 2 , 2 k k k k k k k k k k k a G x x a k G x k x a G x x ∞ · ∞ · ∞ · · · · · + · + · · · · ∑ ∑ ∑ TIPS: refer handout 2 . 4 G E N E R A T I N G F U N C T I O N S The generating function for the finite sequence a0, a1,…,an of real numbers is define by REMARKS: the finite sequence is extend into an infinite sequence by setting an+1 = 0, an+2 = 0, and so on. Generating Function of finite Generating Function of finite Sequence Sequence ( ) 0 1 n n G x a a x a x · + + + L 2 . 4 G E N E R A T I N G F U N C T I O N S The generating function for sequences 1,1,1,1,1,1 given by: The generating function for sequences 1,1,1,1,1,1,… given by: Example 2.4.2 Example 2.4.2 2 3 4 5 1 1 , 1 1 x x x x x x x + + + + + + · < − K 6 2 3 4 5 1 1 , 1 1 x x x x x x x x − + + + + + · ≠ − WHY? WHY? 2 . 4 G E N E R A T I N G F U N C T I O N S 1. ak is given. Find G(x). • Let m be a positive integer and ak = C(m,k), for k = 0, 1, …,m. What is the generating function for the sequence a0, a1,…, am? 1. A sequence of integers is given. Find G(x). • Find the generating function for the finite sequence 1, 4, 16, 64, 256. 1. G(x) is given. Find the sequence of integers. • A generating function of a sequence is given by (x²+1)³. Find the sequence. TIPS: Types of questions TIPS: Types of questions 2 . 4 G E N E R A T I N G F U N C T I O N S 1. Find the generating function of the sequence 1, a, a², a³,… 2. Find a closed form of generating function of infinite sequence 0, 1, -2, 4, -8, 16, -32, 64, … 5. Find a closed form of generating function of infinite sequence 6. Find a closed form for generating function for the sequence {an} where an = -1 and an = for all n = 0, 1, 2,… 7. A generating function of a sequence is given by x² /(1 - x) ². Find the sequence. EXERCISE 2.4.1 EXERCISE 2.4.1 2 7 7 7 7 7 , 2 , 2 , , 2 , 0, 0, 0 1 2 7 | ` | ` | ` | ` . , . , . , . , K K 8 n | ` . , 2 . 4 G E N E R A T I N G F U N C T I O N S OBJECTIVE: Solve counting problem 1. to count the number of combinations of various types 2. to count the r-combinations from a set with n elements when repetition is allowed and additional constraints may exist 3. to count the solutions to equation of the form e1 + e2 + . . . + en = C where C is a constant ei is a nonnegative integer that may subject to specified constraint Counting Problems & Generating Counting Problems & Generating Functions Functions 2 . 4 G E N E R A T I N G F U N C T I O N S Find the number of solutions of e1 + e2 + e3 = 17, where e1, e2, and e3 are nonnegative integers with 2 ≤ e1 ≤ 5, 3 ≤ e2 ≤ 6, 4 ≤ e3 ≤ 7 . Solution From e1 + e2 + e3 = 17, we know that So, the number of solutions with the indicated constraints is the coefficient of in the expansion of Since the coefficient is 3, so there are ______ solutions. HOW? ( ) ( ) ( ) 2 3 4 5 3 4 5 6 4 5 6 7 x x x x x x x x x x x x + + + + + + + + + Example 2.4.4 Example 2.4.4 ( ) ( ) ( ) 3 1 2 17 e e e x x x x · 17 x 2 . 4 G E N E R A T I N G F U N C T I O N S In how many different ways can eight identical cookies be distributed among three distinct children if each child receive at least two cookies and no more than four cookies? Solution Let e1 : child 1’s cookies, e2: child 2’s cookies, e3: child 3’s cookies Each child receive at least two cookies and no more than four cookies, so 2 ≤ e1 ≤ 4, 2 ≤ e2 ≤ 4, and 2 ≤ e3 ≤ 4. 8 cookies is distributed among 3 children, so e1 + e2 + e3 = 8 where . Thus the generating function is . Since the coefficient of is ____, so there are ___ ways. ( ) 3 2 3 4 x x x + + Example 2.4.5 Example 2.4.5 ( ) ( ) ( ) 3 1 2 8 e e e x x x x · 8 x 2 . 4 G E N E R A T I N G F U N C T I O N S 1. Use generating functions to determine the number of ways to insert tokens worth RM1, RM5, and RM10 into a vending machine to pay for an item that cost RM r in both the cases when the order in which the tokens are inserted does not matter and when the order does matter. 2. Use generating functions to find the number of ways to make change for RM100 using RM1, RM5, RM10 and RM50. 3. Use generating functions to find the number of ways to select 14 balls from a jar containing 100 red balls, 100 blue balls, and 100 green balls so that no fewer than 3 and no more than 10 balls are selected from each color. Assume that the order in which the balls are drawn does not matter. EXERCISE 2.4.2 EXERCISE 2.4.2 2 . 4 G E N E R A T I N G F U N C T I O N S OBJECTIVE: find a solution to a recurrence relation and its initial conditions by finding an explicit formula for the associated generating function. TIPS: 1. Let G (x) be the generating function for the sequence {ak}, which 2. Change the sequence ak in the recurrence relation with G (x). 3. Solve for G (x). Recurrence Relations & Recurrence Relations & Generating Functions Generating Functions ( ) 1 1 0 0 1 k k k k k k k k k xG x x a x a x a x ∞ ∞ ∞ + − · · · · · · ∑ ∑ ∑ ( ) 0 k k k G x a x ∞ · · ∑ and ( ) 2 2 2 2 0 0 2 k k k k k k k k k x G x x a x a x a x ∞ ∞ ∞ + − · · · · · · ∑ ∑ ∑ 2 . 4 G E N E R A T I N G F U N C T I O N S Use generating functions to solve the recurrence relation ak = 3ak-1 for k = 1, 2, 3,… and initial condition a0 = 2. Solution By generating function, the recurrence relation ak = 3ak-1 become: Solving for G (x): Since . Consequently; ( ) 0 0 2 2 3 2 3 1 3 k k k k k k G x x x x ∞ ∞ · · · · · ⋅ − ∑ ∑ Example 2.4.6 Example 2.4.6 0 1 1 k k k a x ax ∞ · · − ∑ 2 3 k k a · ⋅ ( ) ( ) ( ) ( ) 1 0 1 0 1 1 1 3 3 3 2 3 2 k k k k k k k k k k k k k k G x xG x a x a x a a a x a a x ∞ ∞ ∞ ∞ − − · · · · − · − · + − · + − · ∑ ∑ ∑ ∑ 2 . 4 G E N E R A T I N G F U N C T I O N S 1. Use generating functions to solve the recurrence relation ak = 7ak-1 + 2 and initial condition a0 = 5. 2. Use generating functions to solve the recurrence relation and initial condition a0 = 4 and a1 = 12. 3. Suppose that a valid codeword is an n-digit number in decimal notation containing an even number of 0s. Let an denote the number of valid codewords of length n. The sequence {an} satisfies the recurrence relation and the initial condition a1 = 9. Use generating functions to find an explicit formula for an. 1 2 2 2 k k k k a a a − − · + + EXERCISE 2.4.2 EXERCISE 2.4.2 1 1 8 10 n n n a a − − · + 2 . 4 G E N E R A T I N G F U N C T I O N S EXERCISE 2.4 : EXTRA EXERCISE 2.4 : EXTRA PAGE : 496, 497, 498 and 499 Rosen K.H., Discrete Mathematics & Its Applications, (Seventh Edition), McGraw-Hill, 2007. 2.5 2.5 INCLUSION-EXCLUSION INCLUSION-EXCLUSION • Count the number of elements in the union of more than two sets. C H A P T E R 2 A D V A N C E C O U N T I N G T E C H N I Q U E Let A1, A2, … An be finite sets. Then: The number of elements in the union of the two sets A and B is: The number of elements in the union of the three sets A, B and C is: 2 . 5 I N C L U S I O N - E X C L U S I O N ( ) 1 2 1 1 1 1 1 2 1 n i i j i n i j n i j k i j k n n n A A A A A A A A A A A A ≤ ≤ ≤ < ≤ ≤ < < ≤ + ∪ ∪ ∪ · − ∩ + ∩ ∩ − + − ∩ ∩ ∩ ∑ ∑ ∑ L L L A B A B A B ∪ · + − ∩ The Principle of Inclusion- The Principle of Inclusion- Exclusion Exclusion A B C A B C A B B C A C A B C ∪ ∪ · + + − ∩ − ∩ − ∩ + ∩ ∩ 2 . 5 I N C L U S I O N - E X C L U S I O N Suppose that there are 1807 freshmen at your school. Of these, 453 are taking a course in computer science, 567 are taking a course in mathematics and 299 are taking course in both computer science and mathematics. How many not taking a course either in computer science or in mathematics? Solution Let A: The set of all freshmen taking a course in computer science B: The set of all freshmen taking a course in mathematics Then; The number of freshmen taking a course either in computer science or in mathematics is Thus, freshmen not taking a course either in computer science or in mathematics. 1807 721 1086 − · Example 2.5.1 Example 2.5.1 453, 567, 299 A B A B · · ∩ · 453 567 299 721 A B A B A B ∪ · + − ∩ · + − · 2 . 5 I N C L U S I O N - E X C L U S I O N A total of 1232 have taken a course in Spanish, 879 have taken a course in French and 114 have taken a course in Russian. Further, 103 have taken courses in both Spanish and French, 23 have taken courses in both Spanish and Russian, and 14 have taken courses in both French and Russian. If 2092 students have taken at least one of French, Spanish and Russian, how many students have taken a course in all three languages? Solution Let S: The set of students who taken a course in Spanish F: The set of students who taken a course in French R: The set of students who taken a course in Russian Then; The number of students have taken at least one of the languages is given by: Thus, the number of students have taken a course in all three languages is: 2092 1232 879 114 103 23 14 S F R · + + − − − + ∩ ∩ Example 2.5.2 Example 2.5.2 1232, 879, 114, 103, 23, 14, 2092 S F R S F S R F R S F R · · · ∩ · ∩ · ∩ · ∪ ∪ · 7 S F R ∩ ∩ · 2 . 5 I N C L U S I O N - E X C L U S I O N 1. How many positive integers not exceeding 1000 are divisible by 7 or 11? 2. To help plan the number of meals to be prepared in a college cafeteria, a survey was conducted and the following data were obtained. 130 students takes breakfast, 180 students takes lunch, 275 students takes dinner, 65 students takes breakfast and lunch, 112 students takes breakfast and dinner, 98 students ate lunch and dinner, and 58 students takes all three meals. How many of the students Ate at least one meal in the cafeteria? 3. How many elements are in the union of four sets if each of the sets has 100 elements, each pair of the sets shares 50 elements, each three of the sets share 25 elements, and there are 5 elements in all four sets? EXERCISE 2.5 EXERCISE 2.5 2 . 5 I N C L U S I O N - E X C L U S I O N EXERCISE 2.5 : EXTRA EXERCISE 2.5 : EXTRA PAGE : 504 and 505 Rosen K.H., Discrete Mathematics & Its Applications, (Seventh Edition), McGraw-Hill, 2007. 2.6 2.6 APPLICATION OF INCLUSION-EXCLUSION APPLICATION OF INCLUSION-EXCLUSION • Apply the inclusion-exclusion principle to solve various counting problem C H A P T E R 2 A D V A N C E C O U N T I N G T E C H N I Q U E 2 . 6 A P P L I C A T I O N O F I N C L U S I O N - E X C L U S I O N AIM: Solve problem that ask for the number of elements in a set that have none of n properties P1, P2, …, Pn. • Let Ai: the subset containing the elements that have property Pi - The number of elements with all the properties Pi1, Pi2, …, Pik will be denoted by N(Pi1, Pi2, …, Pik). In term of set, we have; • Let N(P1’, Pi’, …, Pi’): the number of elements in a set that have none of n properties P1, P2, …, Pn and N: number of elements in the set - Thus; • From the inclusion-exclusion principle, we see that: An Alternative Form of Inclusion- An Alternative Form of Inclusion- Exclusion Exclusion ( ) ( ) ( ) ( ) ( ) ( ) 1 1 2 1 2 1 1 1 ' ' ' 1 n n i i j i j k n i n i j n i j k n N P P P N N P N PP N PP P N PP P + ≤ ≤ ≤ < ≤ ≤ < < ≤ · − + − + + − ∑ ∑ ∑ K L L ( ) 1 2 1 2 i i ik i i ik A A A N P P P ∩ ∩ ∩ · K K ( ) 1 2 1 2 ' ' ' n n N P P P N A A A · − ∪ ∪ ∪ K K 2 . 6 A P P L I C A T I O N O F I N C L U S I O N - E X C L U S I O N How many solutions does x1 + x2 + x3 = 11 have where x1, x2, x3 are nonnegatives integers with x1 ≤ 3, x2 ≤ 4, and x3 ≤ 6? Solution Let a solution have property P1 if x1 > 3 P2 if x2 > 4 P3 if x3 > 6 The number of solutions satisfying the inequalities x1 ≤ 3, x2 ≤ 4, and x3 ≤ 6 is ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) 1 2 3 1 2 3 1 2 1 3 2 3 1 2 3 ' ' ' N P P P N N P N P N P N PP N PP N P P N PP P · − − − + + + − Example 2.6.1 Example 2.6.1 2 . 6 A P P L I C A T I O N O F I N C L U S I O N - E X C L U S I O N By combinations, it follows that: • N = total number of solutions = C (3+11-1, 11) = 78 • N(P1) = (number of solutions with x1 ≥ 4) = C (3+7-1, 7) = 36 • N(P2) = (number of solutions with x2 ≥ 5) = C (3+6-1, 6) = 28 • N(P3) = (number of solutions with x3 ≥ 7) = C (3+4-1, 4) = 15 • N(P1P2) = (number of solutions with x1 ≥ 4 and x2 ≥ 5) = C (3+2-1, 2) = 6 • N(P1P3) = (number of solutions with x1 ≥ 4 and x3 ≥ 7) = C (3+0-1, 0) = 1 • N(P2P3) = (number of solutions with x2 ≥ 5 and x3 ≥ 7) = 0 • N(P1P2P3) = (number of solutions with x1 ≥ 4, x2 ≥ 5 and x3 ≥ 7) = 0 Thus number of solutions satisfying the inequalities x1 ≤ 3, x2 ≤ 4, and x3 ≤ 6 is ( ) 1 2 3 ' ' ' 78 36 28 15 6 1 0 0 6 N P P P · − − − + + + − · Example 2.6.1 : cont… Example 2.6.1 : cont… C(n+r-1, r) 2 . 6 A P P L I C A T I O N O F I N C L U S I O N - E X C L U S I O N Find the number of prime not exceeding a specified positive integers (ex: 100) Solution CLUE: Composite integers not exceeding 100 must have a prime factor not exceeding 10 (WHY?); 2, 3, 5 and 7. Let a solution have property P1 if an integer is divisible by 2 P2 if an integer is divisible by 3 P3 if an integer is divisible by 5 P4 if an integer is divisible by 7 The number of prime not exceeding 100 is Example 2.6.2: The Sieve of Example 2.6.2: The Sieve of Eratosthenes Eratosthenes ( ) 1 2 3 4 4 ' ' ' ' N P P P P + 2 . 6 A P P L I C A T I O N O F I N C L U S I O N - E X C L U S I O N Because there are 99 positive integers greater than 1 and not exceeding 100, the principle of inclusion- exclusion shows that: Thus, the number of prime not exceeding 100 is Example 2.6.2: Cont… Example 2.6.2: Cont… ( ) 1 2 3 4 4 ' ' ' ' 4 21 25 N P P P P + · + · ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) 1 2 3 4 1 2 3 4 1 2 1 3 1 4 2 3 2 4 3 4 1 2 3 1 2 4 1 3 4 2 3 4 1 2 3 4 ' ' ' ' 99 50 33 20 14 16 10 7 6 4 2 3 2 1 0 21 N P P P P N N P N P N P N P N PP N PP N PP N P P N P P N PP N PP P N PP P N PPP N P PP N PP PP · − − − − + + + + + + − − − − + · · − − − − + + + + + + − − − + · 2 . 6 A P P L I C A T I O N O F I N C L U S I O N - E X C L U S I O N Let m and n be positive integers with m ≥ n. Then there are onto functions from a set with m elements to a set with n elements How many onto functions are there from the set with 6 elements to a set with 3 elements? Solution Suppose that the elements in the codomain are b1, b2, and b3. Let P1, P2 and P3 be the properties that b1, b2, and b3 are not in the range of the function, respectively. Thus, the number of onto functions is Example 2.6.3: Example 2.6.3: The Number of Onto The Number of Onto Functions Functions ( ) ( ) ( ) ( ) ( ) ( ) 1 ,1 1 , 2 2 1 , 1 1 m m n m m n C n n C n n C n n − − − + − − + − − L 8 x ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) 1 2 3 1 2 3 1 2 1 3 2 3 1 2 3 6 6 6 ' ' ' 3 3,1 2 3, 2 1 729 192 3 540 N P P P N N P N P N P N PP N PP N P P N PP P C C · − − − + + + − · − + · − + · 2 . 6 A P P L I C A T I O N O F I N C L U S I O N - E X C L U S I O N ! n D n Example 2.6.4: Derangements Example 2.6.4: Derangements ( ) 1 1 1 1 ! 1 1 1! 2! 3! ! n n D n n ] · − + − + + − ] ] L A derangement is a permutation of objects that leaves no object in its original position. • The permutation 21453 is a derangement of 12345 because no number left in its original position. • 21543 is not a derangement of 12345 because this permutation leaves 4 in fixed position. The number of derangements of a sets with n elements is The probability of a derangement is 2 . 6 A P P L I C A T I O N O F I N C L U S I O N - E X C L U S I O N 1. Find the number of solutions does the equation x1 + x2 + x3 + x4 = 17 have where x1, x2, x3 , x4 are nonnegatives integers with x1 ≤ 3, x2 ≤ 4, and x3 ≤ 5 and x4 ≤ 8 ? 2. How many ways are there to assign five different jobs to four different employees if every employee is assigned at least one job? 3. A new employees checks the hats of n people at a restaurant, forgetting to put claim check numbers on the hats. When customers return for their hats, the checker gives them back hats chosen at random from the remaining hats. What is the probability that no one receive the correct hats? EXERCISE 2.6 : EXERCISE 2.6 : 2 . 6 A P P L I C A T I O N O F I N C L U S I O N - E X C L U S I O N EXERCISE 2.6 : EXTRA EXERCISE 2.6 : EXTRA PAGE : 512 and 513 Rosen K.H., Discrete Mathematics & Its Applications, (Seventh Edition), McGraw-Hill, 2007. C H A P T E R 2 A D V A N C E C O U N T I N G T E C H N I Q U E SUMMARY SUMMARY THAT’S ALL ; THANK YOU • A recurrence relation express terms of a sequence as a function of one or more previous terms of the sequence • Recurrence relation can be solved using iterative approach and generating functions • Divide and Conquer algorithm solve a problem recursively by splitting it into a fix number of smaller problems of the same type. • The inclusion-exclusion principle count the number of elements in the union of more than two sets. What NEXT? Chapter 3: Graph CONTENT 2.1 Recurrence Relations 2.2 Solving Recurrence Relations 2.3 Divide-and-Conquer Relations 2.4 Generating Functions 2.5 Inclusion-Exclusion 2.6 Application of Inclusion-Exclusion CHAPTER 2 ADVANCE COUNTING TECHNIQUE RECALL – Counting technique – Product rule – Sum rule CHAPTER 2 ADVANCE COUNTING TECHNIQUE Number of ways = n1n2 ··· nm Number of ways = n1 + n2 +…+ nm A1 ∪ A2 = A1 + A2 − A1 ∩ A2 – The Inclusion-Exclusion Principle – Tree Diagrams – The Pigeonhole Principle – Permutations – Combinations If N objects are placed into k boxes, then there is at N k  least one box containing at   least objects. n! ( n − r) ! P ( n, r ) = n ( n − 1) ( n − 2) L ( n − r + 1) = C nr, ( = ) = n  r  n! r !n r ! ( − ) 2.1 RECURRENCE RELATIONS • • • Define and develop a recurrence relation Model a problem using recurrence relation Find the solution of recurrence relations with the given initial conditions CHAPTER 2 ADVANCE COUNTING TECHNIQUE . If the colony begins with 5 bacteria.Motivation The number of bacteria in a colony doubles every hour. a0=5 Since bacteria double every hour Initial condition recursive definition What we are doing actually? We find a formula/model for an (the relationship between an and a0) – this is called recurrence relations between the term of sequence.1 RECURRENCE RELATION Let an : the number of bacteria at the end of n hours Then. how many will be present in n hours? Solution: 2. By using an = 2an-1. . a1 = 2a0. a0=5 .Recursive (Inductive) Definitions • Recursion – a process to define an object explicitly • The object can be a sequence. The given complex problem Can be solved if 2.1 RECURRENCE RELATION This simple version can be solved Can be solved if Can be solved if This simple version can be solved an = 2an-1 an-1 = 2an-2. function or set (for BCT2078 purposes) • The ideas – construct new elements from known elements. • Process – specify some initial elements in a basis step and provide a rule for constructing new elements from those we already have in the recursive step. • Mathematical Induction can be used to prove the result. Recurrence Relation A recurrence relation for the sequence {an} is an equation that expresses an in terms of one or more of the previous terms of the sequence. a1. . • The initial condition specify the terms that precede the first term where the recurrence elation takes effect. an-1.…. a0. namely. where n0 is a nonnegative integer. for all integers n with n ≥ n0. A sequence is call solution of a recurrence relation if its term satisfy the recurrence relation. Recursive definition 2.1 RECURRENCE RELATION an = 2an-1 a0 = 5 Recurrence relation Initial condition • A recursive algorithm provides the solution of a problem of size n in term of the solutions of one or more instances of the same problem in smaller size. 3. and suppose that a0 =3 and a1 = 5. a0 a1 a2 a3 = = = = 3 5 a1 – a0 = ___________________ __________________________ 2.1 Let {an} be a sequence that satisfies the recurrence relation an = an-1 – an-2 for n = 2.1 RECURRENCE RELATION What is a5? a5 = __________________________ .1.Example 2.4. List the first four term. 4. is a solution of recurrence relation an = 2an-1 – an-2 for n = 2.Example 2. 2an-1 – an-2 = ___________________ Therefore.2 Determine whether {an} where an = 3n for every nonnegative integer n. … Suppose that an = 3n for every nonnegative integer n.1. … 2an-1 – an-2 = ___________________ 2.1 RECURRENCE RELATION . 4. is a solution of recurrence relation an = 2an-1 – an-2 for n = 2. Then for n ≥ 2. Determine whether {an} where an = 5 for every nonnegative integer n. 3. 3. a2 = 2. an = 3 − ( an−1 ) − 2a n−1 for n ≥ 2 1 a0 = 128. an = an −13 + a n − 2 for n ≥ 3 d1 = 1. d 2 = 2.1 1. bn = 7 − 2bn−1 for n ≥ 2 a1 = 1. 2 A B C D E 2. d 3 = 3.EXERCISE 2. Compute the first four terms of the sequence. d n = d n− 1 + d n− 2 + d n− 3 for n ≥ 4 . an = an −1 4 for n ≥ 1 b1 = 5.1 RECURRENCE RELATION a1 = −2. Let an denotes the nth term of a sequence satisfying the given initial condition (s) and the recurrence relation. 1 RECURRENCE RELATION = 3 − 2an−1 − an− 2 an = 2n − 1 3. Show that the sequence {an} is a solution 2 −the recurrence an = n of 3 an = 2an−1 − an− 2 + 2 relation if . Is the sequence {an} a solution of the if = −3 n a n an = −3an−1 + 6an− 2 ( ) 4.EXERCISE 2. Is the sequence {an} a solution of the n a if 2.1 2. 1 RECURRENCE RELATION .Modeling with Recurrence Relation recurrence relation to model a • We can use wide variety of problems such as – Finding a compound interest – Counting a population of rabbits – Determining the number of moves in the Tower of Hanoi puzzle – Counting bit strings 2. 000 .1 RECURRENCE RELATION account at a bank yielding 11% per year with interest compounded annually.11 an-1 With initial condition. a0 = 10.3: Compound interest Suppose that a person deposits RM10.000 in a savings Solution: 2. Define recursively the compound amount in the account at the end of n years. an = (compound amount at the end of (n -1)th years) + (interest for the nth years) an = an-1 + 0.Example 2.11an-1 = 1.1. Let an : the amount in the account after n years Then. 4: Population of rabbits A young pair of rabbits (one of each sex) is placed on an island. each pair of rabbits produces another pair each month.1. After they are 2 months old. fn = (number of pairs of rabbits in (n -1)th months) + (number of newborn pairs of rabbits) fn = fn-1 + fn-2 WHY??? With initial condition. Find a recurrence relation for the numbers of pairs of rabbits on the island after n months if all the rabbits alive.Example 2. f1 = 1 and f2 = 1 . 13th century) – lead to Fibonacci number] . Solution: 2. A pair of rabbits does not breed until they are 2 months old.1 RECURRENCE RELATION Let fn : the numbers of pairs of rabbits on the island after n months Then. n ≥ 3 [Problem develop by Leonardo Pisano (Liber abaci. 4: Population of rabbits 2.1 RECURRENCE RELATION .Example 2.1. late 19th century) 2. – The goal: to have all disks on peg C in order of size. B.1. – Each peg must always be arranged from the largest at the bottom to the smallest at the top .Example 2. with the largest on the bottom.5: Tower of Hanoi • Popular Puzzle invented by Edouard Lucas (French Mathematician.1 RECURRENCE RELATION RULES OF PUZZLE: – Suppose we have 3 pegs labeled A. – These disks are arranged from the largest disk at the bottom to the smallest disk at the top (1 to n disks) on peg A. – Only one disk is allow to move at a time from a peg to another. C and a set of disks of different sizes. 1 RECURRENCE RELATION n disks Let Hn : the numbers of moves with n disks A B Initial Position in the Tower of Hanoi C n-1 disks transfer the top of n-1 disks to peg B A B C Hn-1 moves Intermediate Position in the Tower of Hanoi .Example 2.1.5: Tower of Hanoi ILLUSTRATION: SOLUTION 2. 1 RECURRENCE RELATION 1 disks Moves the largest disk to peg C 1 move A B C Intermediate Position in the Tower of Hanoi n disks transfer the top of n-1 disks to peg B A B Last Position in the Tower of Hanoi C Hn-1 moves .5: Tower of Hanoi ILLUSTRATION: SOLUTION 2.Example 2.1. 5: Tower of Hanoi Solution (continue): 2.1. H1 = 1 Where: transfer the top of n-1 disks to peg B Hn-1 moves Moves the largest transfer the top of n-1 disks to peg B disk to peg C + 1 move + Hn-1 moves .1 RECURRENCE RELATION Thus the number of moves is given by: H n = 2H n −1 + 1 .Example 2. a1 = 2. 10 and 11 .1 RECURRENCE RELATION Solution: Solve yourself Let an : number of bit strings of length n that do not have two consecutive 0s Then.Example 2. How many bit strings are there of six length? 2. both strings of length 1 do not have consecutive 0s ( 0 and 1) a2 = 3.6: Bit Strings Find a recurrence relation and give initial conditions for the number of bit strings of length n that do not have two consecutive 0s.1. the valid strings only 01. an = (number of bit strings of length n-1 that do not have two consecutive 0s) + (number of bit strings of length n-2 that do not have two consecutive 0s) an = an-1 + an-2 . n≥3 With initial condition. 1 RECURRENCE RELATION A computer system considers a string of decimal digits a valid codeword if it contains an even number of 0 digits. Find a recurrence relation for an. there are 10 one-digit strings and only one the string 0 not valid an = 9an −1 + ( 10n −1 − an −1 ) = 8an −1 +10n −1 .Example 2. a1 = 9. : the number of valid n-digit codewords Then. For instance. whereas 120987045608 is not valid.7: Codeword enumeration Let a Solution: n 2.1. Let an be the number of valid n-digit codewords. an = (number of valid n-digit codewords obtained by adding a digit other than 0 at the end of a valid string of length n – 1) + (number of valid n-digit codewords obtained by adding a digit 0 at the end of an invalid string of length n – 1) With initial condition. 1230407869 is valid. − are valid.This produces a string with an even number of 0 digits because the invalid string of length n – 1 has an odd number of 0 digits. Because there are 10 andan −1 strings of length n – 1. then there are invalid (n – 1)-digit strings. a valid string with n 9an −1 digits can be formed in this manner in ways.Example 2. a1 = 9. B) Adding a digit 0 at the end of an invalid string of length n – 1 . Thus. The number of ways n−1 this can be done equals the an −1 10 that number of invalid (n – n −1 1)-digit strings.7: Codeword enumeration n can be formed by: A valid codeword of length A) Adding a digit other than 0 at the end of a valid string of length n–1 . 2. Hence. n ≥ 2 .This can be done in nine ways.1.1 RECURRENCE RELATION an = A + B = 9a n−1 + ( 10n −1 − a n−1 ) = 8a n−1 +10 n −1. Define recursively : 1.EXERCISE 2. Define recursively the compound amount an she will have in her account at the end of n years. Define recursively the number of handshakes that occur. Each person shakes hands with everybody else exactly one.1 6. 4. 13.1 RECURRENCE RELATION . 7. Judy deposits RM1500 in a local savings bank at an annual interest rate of 8% compounded annually. 10. How much will be in her account after 3 years? 8. There are n students at a class. … 7. 2. How many bit strings of length seven contain three consecutive 0s? 11. Find a recurrence relation and initial condition for the number of bit strings of length n that contain three consecutive 0s.EXERCISE 2.1 RECURRENCE RELATION . How many ways can this person climb a building with eight stairs? 10. Find a recurrence relation for the number of bit sequences of length n with an even number of 0s? 2. Find a recurrence relation and initial condition for the number of ways to climb n stairs if the person climbing the stairs can take one. two or three stairs at a time.1 9. 459 and 460 Rosen K. McGraw-Hill.EXERCISE 2. 2007.1 RECURRENCE RELATION . Discrete Mathematics & Its Applications. (Seventh Edition). 458. 2.1 : EXTRA PAGE : 456.H. 457.. 2.2 SOLVING RECURRENCE RELATION CHAPTER 2 ADVANCE COUNTING TECHNIQUE • • • Solve a recurrence relation using iterative method Solve a linear homogeneous recurrence relation with constant coefficients Solve a linear nonhomogeneous recurrence relation with constant coefficients . Iterative Method • Solving the recurrence relation for a function f means finding an explicit formula for f (n).2 SOLVING RECURRENCE RELATION . 2. The iterative method of solving it involves two steps: – Apply the recurrence formula iteratively and look for the pattern to predict an explicit formula  Forward: start from a0 to an  Backward : start from an to a0 – Use Induction to prove that the formula does indeed hold for every possible value of the integer n. 1 (a): Iterative Method method.2 SOLVING RECURRENCE RELATION S n = 2Sn −1 . S 0 = 1 Solution: (FORWARD) Solution: (BACKWARD) S0 = 1 S1 = 2 S0 S 2 = 2 S1 = 2 ( 2 S0 ) = 22 S0 M S n = 2 S n −1 = 2 ( 2n −1 S0 ) = 2n S0 = 2n . n ≥1 S 3 = 2 S 2 = 2 ( 2 2 S 0 ) = 23 S 0 S n = 2Sn −1 = 22 S n − 2 = 23 S n − 3 M = 2 n S 0 = 2n . 2. predict a solution for Using the iterative the following recurrence relation with the given initial condition.Example 2.2. 2. 4. Assume that the statement is true for n = k. Prove that the statement is true for n = n0. 3.Recall: Mathematical Induction Objective: To proof that the statement P(n) is true for each integer n ≥ n0 Steps: 1.2 SOLVING RECURRENCE RELATION . Prove that the statement is true for n = k + 1. Conclusion: Therefore. the statement is true for each integer n ≥ n0 2. 2 SOLVING RECURRENCE RELATION S1 = 21 = 2 2.1 (b): Induction Using induction. k ≥ 1 is true 3. Assume S k = 2k . S 0 = 1 = 2Sn − Sn = 2n .Example 2. the statement is true for each integer n ≥ n0 . Prove that the statement is true for n = k + 1. S k +1 = 2S k = 2 ( 2k ) = 2k +1 4.2. Assume that the statement is true for n = k . Prove that the statement is true for n = n0. 2. n ≥ 1 n is given by . Solution: 1. verify the solution for the recurrence Srelation 1 . Conclusion: Therefore. 11 an-1 .000 . a0 = 10.11an-1 = 1. How much will be in the account after 30 years? Solution: 2.2.2: Compound interest Suppose that a person deposits RM10. an = (compound amount at the end of (n -1)th years) + (interest for the nth years) an = an-1 + 0.Example 2.2 SOLVING RECURRENCE RELATION Let an : the amount in the account after n years Then. n ≥ 1 With initial condition.000 in a savings account at a bank yielding 11% per year with interest compounded annually. 11) a0 2 2.2 SOLVING RECURRENCE RELATION PROVE BY INDUCTION ! a3 = ( 1.11) a0 = ( 1.11) an −1 = ( 1.11) a0 a2 = ( 1.11) 30 ( 10000 ) = ___________ .2.Example 2. after 30 years the amount in the account will be: n n a30 = ( 1.11) a1 = ( 1.11) a2 = ( 1.11) ( 10000 ) Thus.11) a0 3 M an = ( 1.2: Compound interest Solution (continue): By iterative approach: a0 = 10000 a1 = ( 1. 2.2 SOLVING RECURRENCE RELATION H n = 2 H n −1 + 1 .Example 2. H1 = 1 By iterative approach: H n = 2 H n −1 + 1 = 2 ( 2 H n − 2 + 1) + 1 = 22 H n − 2 + 2 + 1 = 22 ( 2 H n −3 + 1) + 2 + 1 = 23 H n −3 + 22 + 2 + 1 M = 2n −1 H1 + 2n − 2 + 2n −3 + K + 2 + 1 = 2n −1 + 2n − 2 + 2n −3 + K + 2 + 1 = 2n − 1 PROVE BY INDUCTION ! .3: Tower of Hanoi The number of moves is given by: 2. Each person shakes hands with everybody else exactly one.2 SOLVING RECURRENCE RELATION an = an −1 + 4 n . . Solve this recurrence relation using iterative method and prove it using induction.2.EXERCISE 2. 2. Define recursively the number of handshakes that occur. a0 = 0 . Verify the solutions using induction • • 2. n ≥ 1 bn = bn −1 + n 2 . There are n students at a class. n ≥ 2 1. show that the amount in the account after 18 years is RM 38929. Using iterative method. predict a solution to each of the following recurrence relation. a1 = 1 . If a deposit of RM100 is made on the first day of each month into an account that pays 6% interest per year compounded monthly.1 1. c2.…. ck Recurrence relation : with k initial condition a0 = C0. … ak-1= Ck-1 2. Degree k : an is expressed in terms of the previous k terms of the sequence Constant coefficients : c1. ck are real numbers and ck ≠ 0 Linear : The RHS is the sum of previous terms of the sequence each multiplied by a function of n.…. c2.Linear Homogeneous Recurrence Relations with constant coefficients A linear homogeneous recurrence relation of degree k with constant coefficients is a recurrence relation of the form an = c1an-1 + c2an-2 + … + ckan-k Where c1. Homogeneous : No terms occur that are not multiplies of the aj s.2 SOLVING RECURRENCE RELATION . a1 = C1. 4: Linear Homogeneous RR Pn = (1.2 SOLVING RECURRENCE RELATION degree two degree five 2. Often occur in degree one modeling of problems 2.Example 2. Can be systematically solved Not Linear Homogeneous Recurrence Relation Hn = 2Hn-1 + 1 Bn = nBn-1 an = an-1 + a²n-2 .2.11) Pn-1 fn = fn-1 + fn-2 an = an-5 Linear Homogeneous Recurrence Relation 1. we obtain a characteristic c1r k −1 − c2 r k − 2 − K − c k −1r − c k = 0 r k − equation: • The solution of this equation are called the characteristics roots. . • and the RHS is subtracted from the left. is a solution of the recurrence an = c1an-1 + c2an-2 + … + r n = c1r n−1 + c2 r n− 2 + K + ck r n− k . n = r n a relation ckan-k iff 2.Solving Linear Homogeneous Recurrence Relations with constant coefficients • Note that.2 SOLVING RECURRENCE RELATION • OUR AIM – look for the solutions of the form r n an = where r is constant. r n−k When both sides of this equation are divided by . 2 SOLVING RECURRENCE RELATION Let c1. r2. rk.Solving Linear Homogeneous Recurrence Relations with constant coefficients has k distinct roots r1. then the solution of the recurrence relation is given by: n n m n n an = α1r1 + α 2 nr1 + K + α m n r1 + K + α k rk . c2. …. αk constant. α2. …. If the characteristic equation has several (m) repeated roots. 2. Suppose that the characteristics equationk − c r k −1 − c r k − 2 − K − c r − c = 0 r 1 2 k −1 k Then a sequence {an} is a solution of the recurrence n an = αcr1an-k α 2 r2 n + K + α k rk n relation an = c1an-1 + c2an-2 + … + 1 k + iff for n ≥ 0 and α1. ck be real numbers. …. 2. B = -1 a = 2 A + 3B = 7 1 an = A ⋅ 2 + B ⋅ 3 1) Thus the solution n the recurrence relation and initial to n conditions isan = 5 ⋅ 2 − 3 . A and B using the initial conditions a0 :A= • Solving the linear system: = A + B = 4 5. n ≥ 0 .6an-2 where a0 = 4 and a1 = 7.Example 2.5: Second-Order Solve the recurrence relation an = 5an-1 .2 SOLVING RECURRENCE RELATION LHRRWCCs 1) Find the general solution of the recurrence relation • the characteristic equation is given by r 2 − 5r + 6 = 0 • the characteristic roots are 2 and 3 • thus. Solution: 2. the general solution is n n 1) Find the constant values. . a1 = A + 2 B + 3C = 5.2 SOLVING RECURRENCE RELATION LHRRWCCs 1) Find the constant values. the general solution is 2.Example 2. a1 =5. C = 2) an = A ⋅1n + B ⋅ 2n + C ⋅ 3n 1) Thus the unique solution to the recurrence relation and initial conditions is . and a2 = 15. A and B using the initial conditions • Solving the linear system: (A = 1.2. B = -1. Solution: 1) Find the general solution of the recurrence relation • the characteristic equation is given by 3 r − 6r 2 + 11r − 6 = 0 • the characteristic roots are 1. 2 and 3 • thus. n ≥ 0 . a0 = A + B + C = 2.6: Higher-Order Solve the recurrence relation an = 6an-1 .11an-2 + 6an-3 where a0 = 2. a2 = A + 4 B + 9C = 15 an = 1 − 2n + 2 ⋅ 3n . What is the form of general solution? 2.Example 2.7: LHRRWCCs with multiple roots Suppose that the roots of the characteristic equation of a linear homogenous recurrence relation are 2. 2.2 SOLVING RECURRENCE RELATION Solution: Thus the general solution to the recurrence anis A2n + Bn 2n + Cn 2 2n + D5n + En5n + F ⋅ 9n relation = = ( A + Bn + Cn 2 ) 2n + ( D + En ) 5n + F ⋅ 9n . 2. 5. and 9. 5.2. a1 = 7 an = 6an −1 − 9an − 2 .2 1. Fn = Fn −1 + Fn − 2 . a0 = 1. an = an −1 + 2an − 2 . a0 = 1. F1 = 1. a1 = 3 an = −3an −1 − 3an − 2 − an −3 . F2 = 1 .2.2 SOLVING RECURRENCE RELATION • • • 1. What is the solution of the following recurrence relation 2.EXERCISE 2. a2 = −1 Find an explicit formula for Fibonacci numbers. a1 = −2. a0 = 2. …. c2. ck are real numbers – F (n) is a function not identically zero depending only n – c1an-1 + c2an-2 + … + ckan-k is called the associated homogenous recurrence relation • Example: 2.Linear NonHomogenous Recurrence Relations with constant coefficients • A Linear Nonhomogenous recurrence relation with constant coefficients (LNHRRWCCs). • Where – c1. that is a recurrence relation of the form an = c1an-1 + c2an-2 + … + ckan-k + F (n) .2 SOLVING RECURRENCE RELATION an = 3an−1 + 2n an = an −1 + an− 2 + n2 − n + 1 an = 2an −1 + n3n . 2 SOLVING RECURRENCE RELATION be the particular solution of LNHRRWCCs. p) ( h) an = an + an . ( p) a ann = c1an-1 + c2an-2 + … + ckan-k + F (n) Then the general solution of LNHRRWCCs is given by There is no general method to ( find the particular solution.Solving Linear NonHomogenous Recurrence Relations with constant coefficients Let And h an ( ) be the general solution of c1an-1 + c2an-2 + … + ckan-k 2. bt ....b1n + b0 ) s n where b0 .... c2..THEOREM 6 And Suppose that {an} satisfy the linear nonhomogenous recurrence relation 2... p1n + p0 ) s n n m ( pt nt + pt −1nt −1 + .2 SOLVING RECURRENCE RELATION an = c1an −1 + ck an− k + . + F ( n) where c1 ..... there is a particular solution of the form (ii) When s is a root of the characteristic equation . s ∈ ℜ (i)When s is not a root of the characteristic equation. there is a particular solution of the form ( pt nt + pt −1nt −1 + ..ck ∈ℜ F (n) = (bt nt + bt −1nt −1 + ... p1n + p0 ) s n . b1 . the particular solution is an = A ⋅ 3n − n − 3 2 1) Thus the unique solution to the recurrence relation is 2.2.8: LNHRRWCCs Find all the solutions of recurrence relation an = 3an-1 + 2n Solution: 1) Find the general solution of the associated linear homogenous (ALH) equation. the general solution is 1) Find the particular solution • Since F(n) = 2n is polynomial with degree 1.2 SOLVING RECURRENCE RELATION . • the ALH equation is given by an = 3an-1 an ( h ) = A ⋅ 3n • thus.Example 2. then the trial solution linear function: pn = cn + d (c and d are cn + d = 3 ( c ( n − 1) + d ) + 2n = 0 constant) • The equation an = 3an-1 + 2n then become an ) − − • Solve for c and d will gives( pc==n-13 and d = -3/2 2 • Thus. What form does a particular solution 9an−linear nonhomogeneous recurrence relation when F n = 3n . What is the solution of the following recurrence relation an = 5an −1 − 6an − 2 + 8n 2 . a 0 = 4. F ( n ) = ( n 2 + 1) 3 n ( ) . a0 = 4. a1 = 7 an = 6an −1 − of 2 + F ( n ) 1.3 1. F n = n 2 2 n ( ) ( ) F ( n ) = 4 ( n + 1) 3n .2 SOLVING RECURRENCE RELATION • • an = 5an −1 − 6an − 2 + 7 n .2. a1 = 7 2.EXERCISE 2. F n = n3 n . (Seventh Edition). McGraw-Hill.2 SOLVING RECURRENCE RELATION .H. 2007.2 : EXTRA PAGE : 456. and 473 Rosen K..EXERCISE 2. 459 and 460 471. 2. 457. 472. Discrete Mathematics & Its Applications. 458. 2.3 DIVIDE-AND-CONQUER RELATIONS CHAPTER 2 ADVANCE COUNTING TECHNIQUE • • Describe a divide-and-conquer algorithm Analyze the computational complexity of divide-and-conquer algorithm using recurrence relation • Estimate the number of operations used by divide-and-conquer algorithm . 3 DIVIDE-AND-CONQUER RELATIONS .Divide-and-Conquer Algorithm • A procedure is called divide-and-conquer algorithm because – They DIVIDE a problem into one or more instances of the same problem of smaller size – & – They CONQUER the problem by using the solutions of the smaller problems to find a solution of the original problem • Example: – Binary search – Multiplying integers 2. if f (n) represents the number of operations required to solve the problem of size n. it follows that f satisfies the recurrence relation – f (n) = a f (n/b) + g (n) • This is called a divide-and conquer recurrence relation 2.3 DIVIDE-AND-CONQUER RELATIONS . where each subproblem is of size n/b. • Then.Divide-and-Conquer Recurrence Relations • Suppose that – A recursive algorithm divides a problem of size n into a subproblems. – A total of g (n) extra operations are required in the conquer step of the algorithm to combine the solutions of the subproblems into a solution of the original problem. n 2. to determine which half of the list to use 2. – g (n) : two comparisons are needed to implement this reduction 1.3.3 DIVIDE-AND-CONQUER RELATIONS .Example 2.1: Binary Search • What happen in Binary search: – A subproblem is used: The algorithm reduces the search for an element in a search sequence of size n to the binary search for an element in a search sequence of size n/2. then – f (n) = a f (n/b) + g (n) = f (n/2) + 2 even . to determine whether any terms of the list remain • If f (n) represents the number of comparisons required to search for an element in a search sequence of size n. n even. to compare the maxima of two sequences 2. 2. a2. to compare the minima of two sequences • If f (n) represents the total number of comparisons needed to find then maximum and minimum elements of the sequence with n elements. then . …. n even – f (n) = a f (n/b) + g (n) = 2f (n/2) + 2 .2: Maximum and Minimum • Locating the maximum and minimum elements of a sequence a1.3 DIVIDE-AND-CONQUER RELATIONS an: – 2 subproblems are used: • If n = 1. then the sequence split into 2 sequences ( either where both have the same number of elements or where one of the sequences has one ore element than the other). then a1 is the maximum and minimum • If n > 1.3. let say n/2 • The problem is reduced to find the maximum and minimum of each of the two smaller sequences • The solution for original problem is the comparison result from these two smaller sequences – g (n) : two comparisons are needed to implement this reduction 1.Example 2. 3 DIVIDE-AND-CONQUER RELATIONS . into two lists with size n/2 elements each – g (n) : uses fewer than n comparisons to merge the sorted lists of n/2 items each into one sorted list • Consequently. where n even.3. the number of comparisons used by the merge sort to sort a list of n element is less than M (n) where. – M (n) = a f (n/b) + g (n) = 2 M (n/2) + n 2.3: Merge Sort • What happen in Merge Sort: – Splits a list to be sorted with n items.Example 2. Let f be an increasing function that satisfies the recurrence relation f (n) = a f (n/b) + c and f (1) = d. logb a f ( n ) = C1n + C2 = C1a k + C2 where ( ) C1 = f ( 1) + c ( a − 1) and C 2 = − c ( a − 1) . when integer and a > 1. where k is a positive • Furthermore.3 DIVIDE-AND-CONQUER RELATIONS O n logb a if a > 1  f ( n) =  O ( log n ) if a = 1  n = bk . Then 2. d є R⁺ with b > 1.Theorem 1 • Let a. b є N and c. then f ( n ) = a k  f ( 1) + c ( a − 1)  +  − c ( a − 1)      = 5k  7 + ( 3 4 )  − 3 4   = 5k ( 31 4 ) − 3 4 If f is increasing function.3 DIVIDE-AND-CONQUER RELATIONS Solution: a = 5. f ( n ) = O nlogb a = O nlog2 5 ( ) ( ) . Also estimate f (n) if f is increasing function k 2. c = 3. b = 2.Example 2. ) Find where k is a positive integer.3.4 (2 • Let f (n) = 5 f (n/2) + 3 and f (1) =f 7. Example 2.5: Binary search • Estimate the number of comparisons used by binary search Solution: When n is even. O ( log n ) f ( n) = .3.3 DIVIDE-AND-CONQUER RELATIONS Where f is the number of comparisons required to perform a binary search on a sequence of size n. f ( n ) = f ( n / 2) + 2 2. Hence. 6: maximum and minimum number of comparisons used to • Estimate the locate the maximum and minimum elements.3. f ( n ) = 2 f ( n / 2) + 2 2. Solution: When n is even. f ( n ) = O ( nlog 2 ) = O ( n ) .Example 2.3 DIVIDE-AND-CONQUER RELATIONS Where f is the number of comparisons needed. Hence. Let f be an increasing function that satisfies the recurrence relation f ( n ) = af ( n b ) + cn d Then 2. where k is a positive integer . b є N and c. d є R⁺ with b > 1.3 DIVIDE-AND-CONQUER RELATIONS O ( n d ) if a < bd   f ( n ) = O ( n d log n ) if a = bd  O nlogb a if a > b d   ( ) n = bk whenever .Master Theorem • Let a. Solution: The number of comparisons is less than M (n) where M ( n ) = 2M ( n / 2 ) + n Hence.7: Complexity of merge sortnumber of comparisons used by • Estimate the the merge sort to sort a list of n elements.3 DIVIDE-AND-CONQUER RELATIONS .Example 2. M ( n ) = O ( n log n ) 2.3. c. Suppose that there are = 2k teams in an elimination n tournament. second round. Estimate the solution f (n) if f is an increasing function.2 SOLVING RECURRENCE RELATION 2.3 1. Solve the recurrence relation. How many rounds are in the elimination tournament when there are 32 teams? b.EXERCISE 2. k 2. where there are n/2 games in the first round. with the k −1 winners playing in the n / 2 = and so on. Use Divide-and-Conquer algorithm to develop a recurrence relation for the number of rounds in the tournament. . 2 a. Find f (n) when n = 3 where f satisfies the recurrence relation f (n) = 2 f (n/3) + 1 with f (1) = 1. 3 : EXTRA PAGE : 482. (Seventh Edition). 483 and 484 Rosen K.EXERCISE 2. 2. McGraw-Hill.H..3 DIVIDE-AND-CONQUER RELATIONS . 2007. Discrete Mathematics & Its Applications. 2.4 GENERATING FUNCTIONS • • • Represent a sequence as generating function Solve counting problems using generating function Solve recurrence relation using generating function CHAPTER 2 ADVANCE COUNTING TECHNIQUE Generating Function of infinite Sequence ∞ 2.4 GENERATING FUNCTIONS The generating function for the sequence a0, a1,…,ak,… of real numbers is the infinite series G ( x ) = a0 + a1 x + L + a k x k + L = ∑ ak x k k =0 REMARKS: sometimes, this generating function for {ak} is called the ordinary generating function of ak USEFUL GENERATING FUNCTIONS refer hand-out or text book page 489 and 157 formal power series Example 2.4.1 The generating function for the following sequences {ak} are given by: 2.4 GENERATING FUNCTIONS ak = 3, ak = k + 1, ak = 2k , G ( x ) = ∑ 3xk = k =0 ∞ ∞ G ( x ) = ∑ ( k + 1) x k = k =0 ∞ G ( x ) = ∑ 2k xk = k =0 TIPS: refer handout and so on.an of real numbers is define by 2.Generating Function of finite Sequence The generating function for the finite sequence a0. a1.…. an+2 = 0. .4 GENERATING FUNCTIONS G ( x ) = a0 + a1 x + L + an x REMARKS: n the finite sequence is extend into an infinite sequence by setting an+1 = 0. Example 2.1.1.4.1.1.4 GENERATING FUNCTIONS 1− x 1+ x + x + x + x + x = .2 The generating function for sequences 1.1.1.1.1 given by: 2.1.… given by: WHY? 1 1+ x + x + x + x + x +K = . x <1 1− x 2 3 4 5 WHY? .1. x ≠1 1− x 2 3 4 5 6 The generating function for sequences 1. ak is given. Find the sequence of integers.4 GENERATING FUNCTIONS .k). a1. • Let m be a positive integer and ak = C(m. A sequence of integers is given. 2. Find G(x). Find the sequence. 16. …. What is the generating function for the sequence a0.…. • A generating function of a sequence is given by (x²+1)³. 1. G(x) is given. • Find the generating function for the finite sequence 1. 256.TIPS: Types of questions 1. for k = 0. 64. Find G(x). 1.m. am? 1. 4. 1. Find a closed 0  for generating function for the sequence {an}  and  1   2for all n = 0. a².4. a. 0.1 1.…  an =  7  where an = -1 7. Find a closed form of generating function of infinite sequence 0. a³. 64. -8. 0.x) ².   n . Find the generating function of the sequence 1. -2.4 GENERATING FUNCTIONS  7 7  2 7  7 7  . 16. A generating function of a sequence is given by x² /(1 .… 2. Find 8 the sequence. … 5. -32. 2.2  form  . 2   . Find a closed form of generating function of infinite sequence 2. 1. 4. 2   .K 6.K .EXERCISE 2. . + en = C where C is a constant ei is a nonnegative integer that may subject to specified constraint 2. to count the r-combinations from a set with n elements when repetition is allowed and additional constraints may exist 3. .4 GENERATING FUNCTIONS .Counting Problems & Generating Functions counting problem OBJECTIVE: Solve 1. to count the number of combinations of various types 2. to count the solutions to equation of the form e1 + e2 + . so there are ______ solutions. we know that e1 e2 e3 17 x 2 + x3 + x 4 + x5 ) ( x3 + x 4 + x 5 + x 6 ) ( x 4 + x 5 + x 6 + x 7 ) ( Since the coefficient is 3. HOW? . where e1.Example 2. the number of solutions with the indicated constraints x17 is the coefficient of in the expansion of 2. Solution From e1 + e2 + e3 So. and e3 are nonnegative integers with 2 ≤ e1 ≤ 5. 4 ≤ e3 ≤ 7 .4 Find the number of solutions of e1 + e2 + e3 = 17.4 GENERATING FUNCTIONS (x )(x )(x ) = x = 17. 3 ≤ e2 ≤ 6.4. e2. 8 cookies is distributed among 3 children. e2: child 2’s cookies.Example 2. and 2 ≤ e3 ≤ 4. Since the e1 x e2 x e3 of x 8 x coefficient = 2. 2 ≤ e2 ≤ 4. so there are ___ ways.5 In how many different ways can eight identical cookies be distributed among three distinct children if each child receive at least two cookies and no more than four cookies? Solution Let e1 : child 1’s cookies. so 2 ≤ e1 ≤ 4.4. e3: child 3’s cookies Each child receive at least two cookies and no more than four cookies.4 GENERATING FUNCTIONS ( )( )( ) is ____. Thus the generating function is . so e1 + e2 + e3 = 8 where . ( x 2 + x3 + x 4 ) x8 3 . and RM10 into a vending machine to pay for an item that cost RM r in both the cases when the order in which the tokens are inserted does not matter and when the order does matter.2 1.4 GENERATING FUNCTIONS . RM10 and RM50.4. Assume that the order in which the balls are drawn does not matter. 3. 100 blue balls. Use generating functions to determine the number of ways to insert tokens worth RM1. RM5. RM5.EXERCISE 2. and 100 green balls so that no fewer than 3 and no more than 10 balls are selected from each color. 2. 2. Use generating functions to find the number of ways to select 14 balls from a jar containing 100 red balls. Use generating functions to find the number of ways to make change for RM100 using RM1. 4 GENERATING FUNCTIONS G ( x ) = ∑ ak x k =0 ∞ k xG ( x ) = x∑ ak x = ∑ ak x k k =0 k =0 ∞ 2 ∞ ∞ k +1 = ∑ ak −1 xk k =1 ∞ and x G ( x) = x 2 ∑a x = ∑a x k k =0 k k =0 k ∞ ∞ k +2 = ∑ ak − 2 xk k =2 2. Change the sequence ak in the recurrence relation with G (x). TIPS: 1.Recurrence Relations & Generating Functions OBJECTIVE: find a solution to a recurrence relation and its initial conditions by finding an explicit formula for the associated generating function. which 2. . Let G (x) be the generating function for the sequence {ak}. Solve for G (x). 3. 4.… and initial condition a0 = 2. ak = 2 ⋅ 3k Consequently. 2. Solution By generating function. .6 Use generating functions to solve the recurrence relation ak = 3ak-1 for k = 1. 3.4 GENERATING FUNCTIONS G ( x ) − 3xG ( x ) = ∑ a k x − 3∑ a k −1x = a 0 + ∑ ( a k − 3a k −1 ) x = 2 + ∑ ( a k − 3a k ) x = 2 ∞ ∞ 2 k k G ( x) = = 2∑ 3 x = ∑ 2 ⋅ 3k xk 1 − 3x Solving for G (x): k =0 k =0 ∞ 1 = ∑ ak xk Since 1 − ax k =0 . the recurrence relation ak = 3ak-1 ∞ ∞ ∞ ∞ become: k k k k k =0 k =1 k =1 k =1 2.Example 2. 3. Use generating functions to solve the recurrence relation ak = ak −1 + 2a k − 2 + 2k and initial condition a0 = 4 and a1 = 12.4 GENERATING FUNCTIONS . Use generating functions to find an explicit formula for an. 2. 2. Suppose that a valid codeword is an n-digit number in decimal notation containing an even number of 0s.4.2 1. Let an denote the number of valid codewords = 8an −1 + 10n −1 an of length n.EXERCISE 2. The sequence {an} satisfies the recurrence relation and the initial condition a1 = 9. Use generating functions to solve the recurrence relation ak = 7ak-1 + 2 and initial condition a0 = 5. Discrete Mathematics & Its Applications. McGraw-Hill. 2. 497.4 : EXTRA PAGE : 496. 2007. 498 and 499 Rosen K. (Seventh Edition).4 GENERATING FUNCTIONS ..H.EXERCISE 2. .5 INCLUSION-EXCLUSION CHAPTER 2 ADVANCE COUNTING TECHNIQUE • Count the number of elements in the union of more than two sets.2. … A 1 2 n 2.The Principle of InclusionExclusion be finite sets. Then: Let A .5 INCLUSION-EXCLUSION A1 ∪ A2 ∪ L ∪ An = 1≤i ≤ n ∑ + Ai − 1≤ i < j ≤ n ∑ Ai ∩ Aj 1≤i < j < k ≤ n ∑ Ai ∩ Aj ∩ Ak n +1 − L + ( −1) A1 ∩ A2 ∩ L ∩ An The number of elements in the union of the two sets A and B is: A ∪ B = A + B − A ∩ B The number of elements in the union of the three sets ∪ BB C = A +is: + C − A ∩ B − B ∩ C − A ∩ C + A ∩ B ∩ C A A. A . ∪ and C B . B = 567. 453 are taking a course in computer science.5. 567 are taking a course in mathematics and 299 are taking course in both computer science and mathematics. How many not taking a course either in computer science or in mathematics? Solution Let A: The set of all freshmen taking a course in computer science B: The set of all freshmen taking a course in mathematics Then. 1807 − 721 = 1086 . Of these.1 Suppose that there are 1807 freshmen at your school.taking a course either in computer A = of freshmen A ∩ B = 299 science or in mathematics is 2. either in computer science or in mathematics. The number453.5 INCLUSION-EXCLUSION A ∪ B = A freshmen not taking a − 299 = 721 + B − A ∩ B = 453 + 567 course Thus.Example 2. Example 2. If 2092 students have taken at least one of French. 23 have taken courses in both Spanish and Russian. F ∩R =14. S ∩one 23. the number of students have taken a course in all three languages is: 2. 103 have taken courses in both Spanish and French. students = 114. and 14 have taken courses in both French and Russian. S ∩ F at least R = of the languages ∪ The number of F = 879. how many students have taken a course in all three languages? Solution Let S: The set of students who taken a course in Spanish F: The set of students who taken a course in French R: The set of students who taken a course in Russian Then.5 INCLUSION-EXCLUSION 2092 = 1232 + 879 + 114 − 103 − 23 − 14 + S ∩ F ∩ R S∩F ∩R =7 .5. 879 have taken a course in French and 114 have taken a course in Russian. S ∪F is R =2092 given by: Thus.2 A total of 1232 have taken a course in Spanish. Further. Spanish and Russian. R have taken =103. S = 1232. a survey was conducted and the following data were obtained. 65 students takes breakfast and lunch. 112 students takes breakfast and dinner. 130 students takes breakfast. To help plan the number of meals to be prepared in a college cafeteria. and there are 5 elements in all four sets? 2.5 INCLUSION-EXCLUSION . How many of the students Ate at least one meal in the cafeteria? 3. How many elements are in the union of four sets if each of the sets has 100 elements. How many positive integers not exceeding 1000 are divisible by 7 or 11? 2. and 58 students takes all three meals. 98 students ate lunch and dinner.5 1. each three of the sets share 25 elements. 275 students takes dinner. each pair of the sets shares 50 elements.EXERCISE 2. 180 students takes lunch. 2007. 2.EXERCISE 2. Discrete Mathematics & Its Applications.5 : EXTRA PAGE : 504 and 505 Rosen K.H. (Seventh Edition)..5 INCLUSION-EXCLUSION . McGraw-Hill. 2.6 APPLICATION OF INCLUSION-EXCLUSION CHAPTER 2 ADVANCE COUNTING TECHNIQUE • Apply the inclusion-exclusion principle to solve various counting problem . An Alternative Form of InclusionExclusion that ask for the number of elements in a set that AIM: Solve problem have none of n properties P1. • From the inclusion-exclusion principle. Pi2.The number of elements with all the properties Pi1. Pn. …. Pik). Pi2. we see that: 2. • Let Ai: the subset containing the elements that have property Pi . Pi’. …. …. P2. Pi’): the number of elements in a set that have Ai1 ∩ Ai 2 ∩noneAik = N ( Pi1Pi 2 K Pik )1.6 APPLICATION OF INCLUSIONEXCLUSION N ( P ' P2 'K Pn ' ) = N − A1 ∪ A2 ∪ K ∪ An 1 N ( P ' P2 'K Pn ' ) = N − 1 1≤i ≤ n ∑ N ( Pi ) + 1≤ i < j ≤ n ∑ N ( PPj ) − i 1≤i < j < k ≤ n ∑ N ( PP jPk ) + L + ( −1 ) i n +1 N ( P1P2L Pn ) . we have. Pn K ∩ of n properties P and N: number of elements in the set . Pik will be denoted by N(Pi1. …. P2. In term of set. …. • Let N(P1’.Thus. Example 2.6.1 How many solutions does x1 + x2 + x3 = 11 have where x1, x2, x3 are nonnegatives integers with x1 ≤ 3, x2 ≤ 4, and x3 ≤ 6? Solution Let a solution have property P1 if x1 > 3 P2 if x2 > 4 P3 if x3 > 6 The number of solutions satisfying the inequalities x1 ≤ 3, x2 '≤ '4, 'and x3N≤P − N P − N P 6 is N P P P =N− 2.6 APPLICATION OF INCLUSIONEXCLUSION ( 1 2 3 ) ( 1) ( 2 ) ( 3) + N ( P P2 ) + N ( P P ) + N ( P P ) − N ( P P P ) 1 1 3 2 3 1 2 3 Example 2.6.1 : cont… By combinations, it follows that: • N = total number of solutions = C (3+11-1, 11) = 78 • • • • • • • N(P1) = (number of solutions with x1 ≥ 4) = C (3+7-1, 7) = 36 N(P2) = (number of solutions with x2 ≥ 5) = C (3+6-1, 6) = 28 N(P3) = (number of solutions with x3 ≥ 7) = C (3+4-1, 4) = 15 N(P1P2) = (number of solutions with x1 ≥ 4 and x2 ≥ 5) = C (3+2-1, 2) = 6 N(P1P3) = (number of solutions with x1 ≥ 4 and x3 ≥ 7) = C (3+0-1, 0) = 1 N(P2P3) = (number of solutions with x2 ≥ 5 and x3 ≥ 7) = 0 N(P1P2P3) = (number of solutions with x1 ≥ 4, x2 ≥ 5 and x3 ≥ 7) = 0 2.6 APPLICATION OF INCLUSIONEXCLUSION C(n+r-1, r) Thus number of solutions satisfying the inequalities x1 ≤ 3, x2 ≤ 4, and x3 ≤ 6 is N ( P ' P2 ' P3 ') = 78 − 36 − 28 − 15 + 6 + 1 + 0 − 0 = 6 1 Example 2.6.2: The Sieve of Eratosthenesprime not exceeding a specified Find the number of positive integers (ex: 100) Solution CLUE: Composite integers not exceeding 100 must have a prime factor not exceeding 10 (WHY?); 2, 3, 5 and 7. Let a solution have property P1 if an integer is divisible by 2 P2 if an integer is divisible by 3 P3 if an integer is divisible by 5 P4 if an integer is divisible by 7 4 + N ( P ' P2 ' P3 ' P4 ') 1 The number of prime not exceeding 100 is 2.6 APPLICATION OF INCLUSIONEXCLUSION 2: Cont… Because there are 99 positive integers greater than 1 and not exceeding 100.6 APPLICATION OF INCLUSIONEXCLUSION = 99 − 50 − 33 − 20 − 14 + 16 + 10 + 7 + 6 + 4 + 2 − 3 − 2 − 1 + 0 = 21 Thus. the number of prime not exceeding 100 is 4 + N ( P ' P2 ' P3 ' P4 ' ) = 4 + 21 = 25 1 .6. the principle of inclusionexclusionP4shows that: ( P2 ) − N ( P3 ) − N ( P4 ) N ( P ' P2 ' P3 ' ' ) = N − N ( P ) − N 1 1 + N ( P P2 ) + N ( P P3 ) + N ( P P4 ) + N ( P2 P3 ) + N ( P2 P4 ) + N ( P3 P4 ) 1 1 1 − N ( PP2 P3 ) − N ( P P2 P4 ) − N ( P P3 P4 ) − N ( P2 P3 P4 ) + N ( P P2 P3 P4 ) 1 1 1 1 = 2.Example 2. 6. and b3 are N ( P ' P2 ' P3 ') = N − N ( P ) − N ( P2 ) − N ( P ) 1 1 3 not in the range of the function. b2.6 APPLICATION OF INCLUSIONEXCLUSION .1) 26 + C ( 3. 2) ( n − 2) −L +( −1) C( n. Let P1. P2 and P3 be the properties that b1. 2) 16 = 729 − 192 + 3 = 540 2. b2.3: The Number of Onto Functions n − C ( n. Thus.1) ( n −1) + C ( n. respectively. and b3.Example 2. Then there are m m n−1 m m onto functions from a set with m elements to a set with n elements How many onto functions are there from the set with 6 elements to a set with 3 elements? Solution Suppose that the elements in the codomain are b1. the + N ( P P2 8 + 1 x 1 1 number of onto functions) is N ( P P3 ) + N ( P2 P3 ) − N ( P P2 P3 ) = 36 − C ( 3. n −1 1 ) Let m and n be positive integers with m ≥ n. 4: Derangements A derangement is a permutation of objects that leaves no object in its original position. The number of derangements of a sets with n elements is 2.Example 2.6. • 21543 is not a derangement of 12345 because this permutation leaves 4 in fixed position.6 APPLICATION OF INCLUSIONEXCLUSION Dn The probability of a derangement is n! n 1   1 1 1 Dn = n ! 1 − + − +L + ( −1) n!   1! 2! 3!  . • The permutation 21453 is a derangement of 12345 because no number left in its original position. Find the number of solutions does the equation x1 2.6 APPLICATION OF INCLUSIONEXCLUSION + x2 + x3 + x4 = 17 have where x1. x4 are nonnegatives integers with x1 ≤ 3. When customers return for their hats.EXERCISE 2. What is the probability that no one receive the correct hats? . x3 . and x3 ≤ 5 and x4 ≤ 8 ? 2. A new employees checks the hats of n people at a restaurant.6 : 1. forgetting to put claim check numbers on the hats. x2. How many ways are there to assign five different jobs to four different employees if every employee is assigned at least one job? 3. the checker gives them back hats chosen at random from the remaining hats. x2 ≤ 4. H.6 : EXTRA PAGE : 512 and 513 Rosen K.EXERCISE 2. 2007.. (Seventh Edition). McGraw-Hill. 2.6 APPLICATION OF INCLUSIONEXCLUSION . Discrete Mathematics & Its Applications. CHAPTER 2 ADVANCE COUNTING TECHNIQUE • A recurrence relation express terms of a sequence as a function of one or more previous terms of the sequence • Recurrence relation can be solved using iterative approach and generating functions • Divide and Conquer algorithm solve a problem recursively by splitting it into a fix number of smaller problems of the same type. • The inclusion-exclusion principle count the number of elements in the union of more than two sets. THANK YOU . SUMMARY What NEXT? Chapter 3: Graph THAT’S ALL .
Copyright © 2024 DOKUMEN.SITE Inc.