Download presentation
Presentation is loading. Please wait.
Published byClaribel Black Modified over 9 years ago
1
Chapter 7 Advance Counting Techniques
2
Content Recurrence relations Generating function The principle of inclusion-exclusion
3
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.
4
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
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-1 +0.11P 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) 30 10000=$228922.97
6
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.
7
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 }.
8
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.
9
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?
10
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
11
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.
12
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, 1230407869 is valid, whereas 120987045608 is not valid. Let a n be the number of valid n-digit codeword. Find a recurrence relation for a n.
13
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-1 + 10 n-1 -a n-1 = 8a n-1 + 10 n-1 with a 1 =9.
14
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-1 +0.11P 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
15
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.
16
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.
17
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
18
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.
19
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.
20
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.
21
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
22
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.
23
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
24
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.
25
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.
26
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-2 + 7 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.
27
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
28
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.
29
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
30
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
31
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, …
32
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
33
Threorem2: THE EXTENDED BINOMIAL THREOREM Let x be a real number with -1<x<1 and u be a real number. Then Example6:
34
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.
35
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.
36
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 + … )
37
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 )
38
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
39
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
40
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
41
Using the recurrence relation, we have
42
Example13: Solve the recurrence relation a n =8a n-1 +10 n-1 with a 1 =9. Solution: Let then
43
Hence we have
44
Inclusion-Exclusion The Principle of Inclusion-Exclusion Theorem1: Let A 1, A 2, …, A n be finite sets. Then
45
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.
46
From the Principle of Inclusion-Exclusion, we see that
47
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
48
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
49
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.
50
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
51
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
52
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.
53
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?
54
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: 21453 is a derangement of 12345. Let D n denote the number of derangement of n objects.
55
Theorem2: the number of derangements of a set with n elements is
56
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
57
Using the principle of inclusion-exclusion, it follows that
58
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)!
59
And And in general,
60
Hence we have
61
n 234567 D n /n!0.50000.3333 0.375 0 0.36670.3681 0.367 8 Table1 the probability of a derangement
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.