Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.

Slides:



Advertisements
Similar presentations
Advanced Counting Techniques
Advertisements

Chapter Recurrence Relations
Fall 2002CMSC Discrete Structures1 Now it’s Time for… RecurrenceRelations.
Chapter 6 Advanced Counting 6.1 Recurrence Relations.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
CS 2210 (22C:19) Discrete Structures Advanced Counting
Chapter Recurrence Relations
1 Copyright M.R.K. Krishna Rao Solving Recurrence Relations Steps for solving a linear homogeneous recurrence relation of degree 2 : Step #1.
CSE115/ENGR160 Discrete Mathematics 04/19/12 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 04/21/11 Ming-Hsuan Yang UC Merced 1.
Transparency No. 5-1 Discrete Mathematics Chapter 5 Advanced Counting Techniques.
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
6.Advanced Counting Techniques 1 Copyright M.R.K. Krishna Rao 2003 Ch 6. Recurrence Relations A recurrence relation for the sequence {a n } is an equation.
4.4.2 Combinations of multisets
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Applied Discrete Mathematics Week 9: Relations
Advanced Counting Techniques
7.4 Generating Functions Definition 1: The generation function for the sequence a 0, a 1,...,a k,... of real numbers is the infinite series G(x) = a 0.
Jessie Zhao Course page: 1.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Chap. 7 (c) , Michael P. Frank1 Chapter 7: Advanced Counting Techniques.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
4.6.2 Exponential generating functions
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
14.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo –Divide & conquer –Master’s method.
Recurrence Relation. Outline  What is a recurrence relation ?  Solving linear recurrence relations  Divide-and-conquer algorithms and recurrence relations.
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
Module #20 - Recurrences 1 Ch. 7 Recurrence Relations Rosen 6 th ed., §§7.1.
R. Johnsonbaugh Discrete Mathematics 7 th edition, 2009 Chapter 7 Recurrence Relations Instructor Tianping Shuai.
15.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo Reading: Sections Reading:
Module #17: Recurrence Relations Rosen 5 th ed., §
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
4.5.2 Applications of Inclusion-Exclusion principle
Sequences and Summations
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Recurrence.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
after UCI ICS/Math 6A, Summer AdvancedCounting -1 Recurrence Relations (RRs) A “Recurrence Relation”
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Discrete Structures1 One, two, three, we’re… Counting.
CHAPTER TWO RECURRENCE RELATION
7.2 Solving Linear Recurrence Relations Some of these recurrence relations can be solved using iteration or some other ad hoc technique. However, one important.
Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.
Discrete Mathematics Chapter 6 Advanced Counting Techniques.
Recurrence Relations. Outline Recurrence relationsSolving recurrence relationsRecurrence and Divide-and-conquer algorithmsGenerating functions
2/24/20161 One, two, three, we’re… Counting. 2/24/20162 Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter.
7.6 Applications of Inclusion-Exclusion An Alternative Form of Inclusion-Exclusion Example 1: How many solutions does x 1 + x 2 +x 3 =11 have,where x 1,
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Advanced Counting Techniques
Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO.
CMSC Discrete Structures
Advanced Counting Techniques
Modeling with Recurrence Relations
Applied Discrete Mathematics Week 11: Relations
A0=0 a1=2 an a2=6 an-1 a3=12 a4=20 a2 a1 a0.
Recurrence Relations.
CS100: Discrete structures
4.6.2 Exponential generating functions
CS 2210 Discrete Structures Advanced Counting
CMSC Discrete Structures
4.7 Recurrence Relations P13, P100
CMSC Discrete Structures
Recurrence Relations Discrete Structures.
Chapter 7 Advanced Counting Techniques
ICS 253: Discrete Structures I
Presentation transcript:

Chapter 7 Advance Counting Techniques

Content Recurrence relations Generating function The principle of inclusion-exclusion

Recurrence relations Definition: a recurrence relation for the sequence {a n } is an equation that express a n in terms of the sequence, namely a 1, a 2, …, a n-1, for all integers n with n>n 0. where n 0 is a nonnegative integer. A sequence is called a solution of a recurrence relation if its term satisfy the recurrence relation. The initial conditions for a sequence specify the terms that precede the first term where the recurrence relation takes effect.

Example1: let {a n } be a sequence that satisfies the recurrence relation a n = a n-1 - a n-2 for n=2,3,4,… and suppose that a 0 =3 and a 1 =5. what are a 2 and a 3 ? Example2: determine whether the sequence {a n } is a solution of the recurrence relation a n = 2a n-1 - a n-2 for n=2,3,4,…. (1) a n = 3n (2) a n = 2 n (3) a n = 5

Modeling with recurrence relation Example3: Compound Interest Suppose that a person depots $10000 in a saving account at a bank yielding 11% per year with interest compound annually. How much will be in the account after 30 years? Solution: P n =P n P n-1 =1.11P n-1 using a iterative approach to find a formula P n. P n =(1.11) n P 0 = (1.11) =$

Example4: Rabbits and the Fibonacci Numbers 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 number of pairs of rabbits on the island after n months, assuming that no rabbits ever die. Solution: f n =f n-1 +f n-2 with f 1 =1 and f 2 =1.

Example5: The Tower of Hanoi The Hanoi Tower consists of three pegs mounted on a board together with disks of different sizes. Initially these disks are placed on the first peg in order of size, with the largest on the bottom. The rule of the puzzle allow disks to be moved one at a time from one peg to another as long as a disk is never placed on top of a smaller disk. The goal of the puzzle is to have all the disks on the second peg in order of size, with the largest on the bottom. Let H n denote the number of moves needed to solve the Tower of Hanoi problem with n disks. Set up a recurrence relation for the sequence {H n }.

Solution: begin with n disk on peg one, we can transfer the top n-1 disks following the rules of puzzle, to peg three using H n-1 moves. Hence we have H n =2 H n-1 +1 with H 1 =1. using the iterative approach to solve this recurrence relation.

Example6: Find a recurrence relation and give initial conditions for the number of bit strings of length n that do not have two consecutive 0s. How many such bit strings are there of length five?

Solution: let a n denote the number of bit strings of length n that do not have two consecutive 0s. To obtain a recurrence relation for {a n }, note that by the sum rule, the number of bit strings of length n that do not have two consecutive 0s equals the number of such bit strings ending with a 0 plus the number of such bit strings ending with a 1. 1 Any bit string of length n-1 with no two consecutive 0s End with a 1 Any bit string of length n-2 with no two consecutive 0s End with a 0 1 0

We will assume that, so that the bit string has at least 3 bits. Hence we have a n =a n-1 +a n-2 for with a 1 =2.

Example7: Codeword Enumeration A computer system consider a string of decimal digits a valid codeword if it contains an even number of 0 digits. For instance, is valid, whereas is not valid. Let a n be the number of valid n-digit codeword. Find a recurrence relation for a n.

Solution: There are two ways to construct a valid string with n digits from a string with one fewer digit. (1)A valid string of n-digits can be obtained by appending a valid string of n-1 digits with a digit other than 0. namely 9a n-1 ways there are. (2)A valid string of n-digits can be obtained by appending a 0 to a string of length n-1 that is not valid. Then there are 10 n-1 -a n-1. Hence a n = 9a n n-1 -a n-1 = 8a n n-1 with a 1 =9.

Solving Recurrence Relations-1 Definition1 : A linear homogeneous recurrence relation of degree k with constant coefficients is a recurrence relation of the form where are real numbers, and. Example1: (1) P n =P n P n-1 =1.11P n-1 (2) f n =f n-1 +f n-2 with f 1 =1 and f 2 =1. (3) H n =2 H n-1 +1 with H 1 =1

Characteristic equation and characteristic roots Definition2: assume that a recurrence relation is then the equation is called characteristic equation ; and the solution of the equation are called characteristic roots.

Theorem1: Let c 1 and c 2 be real numbers. Suppose that r 2 -c 1 r-c 2 =0 has two distinct roots r 1 and r 2. then the sequence {a n } is a solution of the recurrence relation a n =c 1 a n-1 +c 2 a n-2 if and only if for n=0,1,2,… where are constants and are determined by the initial conditions.

Example2: what is the solution of the recurrence relation a n =a n-1 +2a n-2 with a 0 =2 and a 1 =7 ? Solution: the characteristic equation is r 2 =r+2, then the solution of the equation is r=2 and r=-1. hence a n =b 1 2 n +b 2 (-1) n with a 0 =2 and a 1 =7. thus we have b 1 = 3 and b 2 =-1. namely a n =3. 2 n -(-1) n

Theorem2: Let c 1 and c 2 be real numbers with c 2 ¹ 0, Suppose that r 2 - c 1 r- c 2 =0 has only one root r 0. then a sequence {a n } is a solution of the recurrence relation a n =c 1 a n-1 +c 2 a n-2 if and only if for n=0,1,2,… where are constants and are determined by the initial conditions.

Example3: what is the solution of the recurrence relation a n =6a n-1 -9a n-2 with a 0 =1 and a 1 =6? Solution: the root of r 2 - 6r+9=0 is r=3, hence a n =b 1 3 n +b 2 n3 n with a 0 =1 and a 1 =6. a n =3 n +n3 n with a 0 =1 and a 1 =6.

Theorem3: Let c 1, c 2, …, c k be real numbers. Suppose that r k - c 1 r k-1 - … -r- c k =0 has k distinct root r 1, r 2, …, r k. Then a sequence {a n } is a solution of the recurrence relation a n =c 1 a n-1 +c 2 a n-2 +…+ c k a n-k if and only if a n =b 1 r 1 n + b 2 r 2 n + …+ b k r k n for n=0,1,2,…, where b 1, …, b k are constants and are determined by the initial conditions.

Example4: Find the solution of the recurrence relation a n =6a n-1 -11a n-2 +6a n-3 with a 0 =2, a 1 =5 and a 2 =15? Solution: the root of r 3 - 6r 2 +11r-6=0 is r=1,2,3; hence a n =b 1 + b 2 2 n + b 3 3 n and b 1 =1, b 2 =-1, b 3 =2

Theorem4: Let c 1, c 2, …, c k be real numbers. Suppose that r k - c 1 r k-1 - … -r- c k =0 has t distinct root r 1, r 2, …, r t with multiplicities m 1, m 2,…, m t and m 1 +m 2 +…+m t =k. Then a sequence {a n } is a solution of the recurrence relation a n =c 1 a n-1 +c 2 a n-2 +…+ c k a n-k if and only if a n =(b 10 + b 11 n+ … + b 1m1-1 n m1-1 )r 1 n + + …+ (b t0 + b t1 n+ … + b tmt-1 n mt-1 ) r t n for n=0,1,2,…, where b ij are constants and are determined by the initial conditions.

Example5: what is the solution of the recurrence relation a n =-3a n-1 -3a n-2 -a n-3 with a 0 =1, a 1 =-2 and a 2 =-1? Solution: the root of r 3 +3r 2 +3r+1=0 is r=-1of multiplicity three; hence a n =(b 1 + b 2 n+ b 3 n 2 )(-1) n and b 1 =1, b 2 =3, b 3 =-2

Linear Nonhomogeneous Recurrence Relations with Constant Coefficients Definition: the recurrence relation a n =c 1 a n-1 +c 2 a n-2 +…+ c k a n-k +F(n) is called Linear Nonhomogeneous Recurrence Relations with Constant Coefficients. a n =c 1 a n-1 +c 2 a n-2 +…+ c k a n-k is called the associated homogeneous recurrence relation.

Theorem5: If {a n (p) } is a particular solution of the nonhomogeneous linear recurrence relation with constant coefficients a n =c 1 a n-1 +c 2 a n-2 +…+ c k a n-k +F(n), Then every solution is of the form {a n (p) + a n (h) }, where {a n (h) } is a solution of the recurrence relation of the associated homogeneous recurrence relation a n =c 1 a n-1 +c 2 a n-2 +…+ c k a n-k.

Example6: what is the solution of the recurrence relation a n =5a n-1 -6a n-2 +7 n with a 0 =2, a 1 =5 ? Solution: the solution of a n =5a n-1 -6a n-2 is a n (h) =b 1 3 n +b 2 2 n, since F(n)=7 n, assume that a n (p) =c 7 n, where c is a constant. Hence c 7 n =5 c 7 n-1 -6 c 7 n n , we have c =49/20, namely that a n (p) =(49/20) 7 n. Then we can determine the coefficients b 1 and b 2.

Theorem6: If {a n } satisfies the nonhomogeneous linear recurrence relation with constant coefficients a n =c 1 a n-1 +c 2 a n-2 +…+ c k a n-k +F(n) where c 1, c 2,…, c k are real numbers and F(n) =(b t n t + b t-1 n t-1 +…+ b 1 n+b 0 ) s n where b 0, b 1, …, b t and s are real numbers. (1)If s is not a characteristic root, then there is a particular solution of the form a n (p) =(p t n t + p t-1 n t-1 +…+ p 1 n+p 0 ) s n (2) If s is a characteristic root with multiplicity m, then there is a particular solution of the form a n (p) =n m (p t n t + p t-1 n t-1 +…+ p 1 n+p 0 ) s n

Example7: what is the solution of the linear nonhomogeneous relation a n =6a n-1 -9a n-2 +F(n) (1) F(n)=n 2 2 n (2) F(n)=3 n (3) F(n)=n 3 (1)Solution: let a n (p) =(p 2 n 2 +p 1 n+ p 0 ) 2 n.Then (p 2 n 2 +p 1 n+ p 0 ) 2 n = 6(p 2 (n-1) 2 +p 1 (n-1)+ p 0 ) 2 n-1 - 9(p 2 (n-2) 2 +p 1 (n-2)+ p 0 ) 2 n-2 + n 2 2 n we have that p 0 = 192 p 1 =48 p 2 =4. The characteristic root is r=3. hence a n =(b 1 +b 2 n)3 n is a solution of a n =6a n-1 -9a n-2.

Definition1: The generating function for the sequence a 0, a 1, …, a k, … of real numbers is the infinite series G(x)= a 0 + a 1 x+ …+a k x k +… Solving Recurrence Relations-2

Example1: the generating function for the sequences {a k } with a k =3, a k =2(k+1) and a k =2 k are Example2: what is the generating function for the sequence 1,1,1,1,1? Solution: G(x)= 1+ x+ x 2 +x 3 +x 4

Useful Facts About Power Series Example3: the function f(x)=1/(1-x)=1+ x+ x 2 +x 3 +x 4 + x 5 +… is the generating functions of the sequence 1,1,… the function f(x)=1/(1-ax)=1+ ax+ a 2 x 2 +… is the generating functions of the sequence 1,a, a 2,… the function f(x)=1/(1-x) 2 =1+ 2x+ 3x 2 +4x 3 +5x 4 + 6x 5 +… is the generating functions of the sequence 1,2,3, …, k+1, …

Definition2: Let u be a real number and k a nonnegative integer. Then the extended binomial coefficient C(u,k) is defined by Exmaple4: C(-2,3)=-4 C(1/2,3)=1/16 Exmaple5: when n<0 is an integer, then

Threorem2: THE EXTENDED BINOMIAL THREOREM Let x be a real number with -1<x<1 and u be a real number. Then Example6:

Counting Problems and Generating Functions Example7: Find the number of solutions of e 1 +e 2 +e 3 =17, where e 1, e 2 and e 3 are nonnegative integers with 2 £ e 1 £ 5, 3 £ e 2 £ 6 and 4 £ e 1 £ 7. Solution: the number of solutions with the indicated constraints is the coefficient of x 17 in the expansions of: (x 2 + x 3 + x 4 + x 5 ) (x 3 + x 4 + x 5 +x 6 ) (x 4 + x 5 + x 6 + x 7 ) This follows that the coefficient of x 17 is 3.

Example8: In how many different ways can eight identical cookies be distributed among three distinct children if each child receives at least two cookies and no more than four cookies. Solution: the coefficient of x 8 in the product (x 2 + x 3 + x 4 ) 3 is 7.

Example9: use generating functions to determine the number of ways to insert tokens worth $1, $2,and $5 into a vending machine to pay for an item that costs r dollars in both the cases when the order in which the tokens are inserted does not matter and when the order does matter. Solution: case1: no order is considered the answer is the coefficient of x r in the generating function (1+x+x 2 + … )(1 +x 2 +x 4 + … )(1+x 5 +x 10 + … )

case2: when the order does matter, then the number of ways to insert exactly n tokens to produce a total of r dollars is the coefficient of x r in the generating function (x+x 2 + x 5 ) n, since each of the r tokens may be a $1 token, a $2 token, or a $5 token. Since any number tokens may be inserted, the number of ways to produce r dollars is the coefficient of x r in 1+ (x+x 2 + x 5 )+ (x+x 2 + x 5 ) 2 + … =1/1- (x+x 2 + x 5 )

Example10: use generating function to find the number of k-combinations of a set with n elements. Assume that the Binomial Theorem has been established. Solution: each of the n elements in the set contributes the term (1+x) to the generating function f(x)=(1+x) n, by the binomial theorem, we have hence

Example11: use generating function to find the number of r-combinations from a set with n elements when repetition of elements is allowed. Solution: Let G(x)=(1+x+x 2 +…) n, then the coefficient of x r is the answer. Hence G(x)=(1+x+x 2 +…) n =(1+x) -n = å C(n+r-1,r)x r

Using Generating Functions TO Solve Recurrence Relations Example12: solve the recurrence relation a n =6a n-1 -9a n-2 with a 0 =1 and a 1 =6. Solution: let, Then

Using the recurrence relation, we have

Example13: Solve the recurrence relation a n =8a n n-1 with a 1 =9. Solution: Let then

Hence we have

Inclusion-Exclusion The Principle of Inclusion-Exclusion Theorem1: Let A 1, A 2, …, A n be finite sets. Then

1 An Alternative Form of Inclusion- Exclusion Let A i be the subset containing the elements that property P i. The number of elements with all the properties P i1, P i2, …, P ik will be denoted by N(P i1 P i2 … P ik ). Writing these quantities in terms of sets, we have If the number of elements with none of the properties P 1,P 2,…, P n, is denoted by and the number of elements in the set is denoted by N.

From the Principle of Inclusion-Exclusion, we see that

Example1: how many solutions does x 1 +x 2 +x 3 =11 have, where x 1, x 2 and x 3 are nonnegative integers with x 1 £3, x 2 £4 and x 3 £6? Solution: let P 1 denote the property of element of the set that x 1 >3, and P 2 : x 2 >4, P 3 : x 3 >6. Then

N=C(3+11-1,11)=78 N(P 1 )=C(3+7-1,7)=36 N(P 2 )=C(3+6-1,6)=28 N(P 3 )=C(3+4-1,4)=15 N(P 1 P 2 )=C(3+2-1,2)=6 N(P 1 P 3 )=C(3+0-1,0)=1 N(P 2 P 3 )=0 N(P 1 P 2 P 3 )=0 =6

THE SIEVE OF ERATOSTHENES To find the number of primes not to exceeding a specified positive integer. For instance, to find the number of primes not to exceeding 100. Note that a composite integer not to exceeding 100 must have a prime factor not to exceeding 10. The primes not to exceeding 100 are divisible by none of 2,3,5 and 7.

Let P 1, P 2, P 3, P 4 denote an integer is divisible by 2,3 5,7 respectively. Then the number of primes not to exceeding 100 is

The Number of Onto Functions Example2: how many onto functions are there from a set with six elements to a set with three elements? Solution: assume that the elements in the codomain are b 1, b 2, b 3. let P 1,P 2,P 3 be the properties that b 1, b 2 and b 3 are not in the range of the function, respectively. note that a function is onto if and only if it has none of the properties P 1,P 2 and P 3. hence

Theorem1: 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.

Derangements Example3: The Hatcheck Problem A new employee 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 at random from the remaining hats. What is the probability that no one receives the correct hat?

Remark: the answer is the number of ways the hats can be arranged so that there is no hat in its original position divided by n!. Definition: a derangement is a permutation of objects that no object in its original position. For example: is a derangement of Let D n denote the number of derangement of n objects.

Theorem2: the number of derangements of a set with n elements is

Proof: let a permutation have property P i if it fixes element i. The number of derangements is the number of permutations having none of the properties P i for i=1,2,…, n. This means that

Using the principle of inclusion-exclusion, it follows that

We can see that N(P i )=(n-1)! N(P i P j )=(n-2)! …… N(P i1 P i2 … P im )=(n-m)!

And And in general,

Hence we have

n D n /n! Table1 the probability of a derangement