AdvanceCountingCh4 (1)
AdvanceCountingCh4 (1)
Inclusion-Exclusion Principle
Recurrence Relations
Second-Order Linear Homogeneous Recurrence Relations
with Constant Coefficients
Linear Second-Order Nonhomogeneous Recurrence
Relations withe constant coefficients
4.1 Inclusion-Exclusion Principle
Solution
(a) |U| = 50, |C ∪ J ∪ P| = 45 ⇒ |C ∩ J ∩ P| = 50 − 45 = 5
(b) 45 = 35 + 23 + 18 − 15 − 12 − 8 + x ⇒ x = 4
We want a system that generalizes further and doesn’t
necessarily deal explicitly with sets.
Definition
Let c1 , c2 be conditions on a finite set S with |S| = N
N(c1 ) =Number of elements in S satisfying c1
N(c2 ) =Number of elements satisfying c2
N(c1 c2 ) =Number of elements satisfying c1 and c2
N(c1 or c2 ) =Number of elements satisfying c1 or c2
= N(c1 ) + N(c2 ) − N(c1 c2 )
N(c¯1 ) = N − N(c1 ) Number of elements not satisfying c1 .
N(c¯1 c¯2 ) =Number of elements not satisfying c1 and c2
N(c¯1 c¯2 ) = Number of elements not c1 and not c2
= N − N(c1 ) − Nc2 + N(c1 c2 )
Example
How many bit strings of length 6 either start with a 1 or end
with 00?
Solution
N(c1 )= No of strings of length 6 starts with a 1.
N(c2 )= No of strings of length 6 ends with 00.
N(c1 c2 )= No of strings of length 6 starts with 1 and ends
with 00.
N(c1 ) =1 × 2 × 2 × 2 × 2 2 = 32
|{z} |{z} |{z} |{z} |{z}
0,1 0,1 0,1 0,1 0,1
N(c2 ) = 2 × 2 × 2 × 2 ×1 × 1 = 16
|{z} |{z} |{z} |{z}
0,1 0,1 0,1 0,1
N(c1 c2 ) = 1 × 2 × 2 × 2 × 1 × 1 = 8
|{z} |{z} |{z} |{z} |{z} |{z}
1 0,1 0,1 0,1 0 0
N(c1 or c2 ) = N(c1 )+N(c2 )−N(c1 c2 ) = 32+16−8 = 40
The Principle of Inclusion-Exclusion
Let S be a set with |S| = N and conditions ci , 1 ≤ i ≤ t
The number of elements of S that satisfy none of the
conditions ci , 1 ≤ i ≤ t is denoted by N = N(c¯1 c¯2 · · · c¯t ),
is given by
Example
How many n ∈ {1, 2, · · · , 100} is n not divisible by 2,3, and 5?
(i) Find the number of positive integers that are not divisible
by 2 nor by 5 but are divisible by 3?
(ii) Find the number of positive integers that are not divisible
by 5 but are divisible by 2 and 3
Solution
S = {1, 2, 3, · , 100}, and N = 100.
For n ∈ S, n satisfies
condition c1 if n is divisible by 2.
condition c2 if n is divisible by 3.
condition c3 if n is divisible by 5.
N(c1 ) = ⌊ 100
2 ⌋ = 50 N(c1 c3 ) = ⌊ 100
10 ⌋ = 10
N(c2 ) = ⌊ 100
3 ⌋ = 33 N(c2 c3 ) = ⌊ 100
15 ⌋ = 6
N(c3 ) = ⌊ 100
5 ⌋ = 20 N(c1 c2 c3 ) = ⌊ 100
30 ⌋ = 3
N(c1 c2 ) = ⌊ 100
6 ⌋ = 16
Then the answer to this problem is N(c¯1 c¯2 c¯3 ).
Applying the principle of inclusion and exclusion, we find
N(c¯1 c¯2 c¯3 ) = N − S1 + S2 − S3
= N − [N(c1 ) + N(c2 ) + N(c2 )]
+ [N(c1 c2 ) + N(c1 c3 ) + N(c2 c3 )] − N(c1 c2 c3 )
= 100 − [50 + 33 + 20] + [16 + 10 + 6] − 3
= 26
Example
How many integer solutions are there to
x1 + x2 + x3 = 17,
where 0 ≤ xi ≤ 7, for 1 ≤ i ≤ 3.
Solution
Conditions: ci : xi ≥ 8
⇒ c¯i : xi ≤ 7
N(c¯1 c¯2 c¯3 ) = N − [N(c1 ) + N(c2 ) + N(c3 )]
+ [N(c1 c2 ) + N(c1 c3 ) + N(c2 c3 )] − N(c1 c2 c3 )
3+17−1 19
N= 17
= 17
= 19 × 9 = 171 = S0
c1 : x1 + x2 + x3 = 17, x1 ≥ 8, x2 ≥ 0, x3 ≥ 0.
x1′ + 8 + x2 + x3 = 17, x1′ ≥ 0, x2 ≥ 0, x3 ≥ 0.
x1′ + x2 + x3 = 9, x1′ ≥ 0, x2 ≥ 0, x3 ≥ 0.
3+9−1 11
⇒ N(c1 ) = 9
= 9
= 5(11) = 55
11
All conditions are the same, so N(c2 ) = 9
= N(c3 )
We can generalize S1 = 31 11 9
= 3(55) = 165
c1 c2 : x1 + x2 + x3 = 17, x1 ≥ 8, x2 ≥ 8, x3 ≥ 0
x1′ + 8 + x2′ + 8 + x3 = 17, xi′ ≥ 0, x2′ ≥ 0, x3 ≥ 0
x1′ + x2′ + x3 = 1, xi′ ≥ 0, x2′ ≥ 0, x3 ≥ 0
N(c1 c2 ) = 3+1−1
1
= 31 = 3
Because all the conditions are the same,
N(c1 c3 ) = 3 = N(c2 c3 )
We can generalize S2 = 32 31 = 9
Is it possible to have all the x ’s ≥ 8? No it’s not possible.
Because x1 + x2 + x3 has at least 24. N(c1 c2 c3 ) = 0 = S3
N(c¯1 c¯2 c¯3 ) = S0 − S1 + S2 − S3 = 171 − 165 + 9 − 0
= 15 number of integer solutions.
Number of onto functions from A to B with
|A| = m ≥ n = |B|
Total number of functions from A to B: nm
− Number of not onto functions from A to B
Number of onto function from A to B
Let A = {a1 , a2 , · · · , am },
B = {b1 , b2 · · · , bn }, and
S = the set of all functions from f : A → B.
Then N = |S| = S0 = nm .
Let ci (1 ≤ i ≤ n) be the condition on S where a function
f : A → B satisfies ci if bi is not in the range of f .
N(c¯i )=No of functions in S that have bi in their range
N(c¯1 c¯2 · · · c¯n )=No of onto functions f : A → B.
N(ci ) = (n − 1)m , because each element of B, except bi ,
can be used as the second component.
N(ci cj ) = (n − 2)m , 1 ≤ i < j ≤ n
n
S1 = [N(c1 ) + N(c2 ) · · · + N(cn )] = 1
(m − 1)n
S2 = [N(c1 c2 ) + N(c1 c3 ) · · · + N(cn−1 cn )] = n2 (n − 2)m
In general for each 1 ≤ k ≤ n, !
n
(n − k)m
X
Sk = N(ci1 ci2 · · · cik ) =
1≤i1 <i2 <···<ik ≤n k
By the principle of Inclusion and Exclusion, the number of
onto function from A to B is
N(c¯1 c¯2 · · · c¯n ) = S0 − S1 + S2 − S3 + · · · (−1)n Sn
! !
m n n
=n − (n − 1)m + (n − 2)m
1 2
!
n
− (n − 3)m + · · · + (−1)n (n − n)m
3
n
!
i n
(n − i)m
X
N(c¯1 c¯2 · · · c¯n ) = (−1)
i=0 i
For m < n, N(c¯1 c¯2 · · · c¯n ) = 0
The number of onto functions from A to B with
|A| = m ≥ n = |B| is given by
n
!
i n
(n − i)m
X
(−1)
i=0 i
Example
What is the characteristic equation of
an − an−1 − 4an−2 + 4an−3 = 0?
Solution
The characteristic equation is r 3 − r 2 − 4r + 4 = 0
Theorem
Let x be a root of the characteristic equation. Then
an = cx n , c ̸= 0, satisfies the recurrence relation.
If an = r1n , an = r2n , · · · , an = rkn are solutions for
c0 an + c1 an−1 + · · · + ck an−k = 0 for n ≥ k, then
an = A1 r1n + A2 r2n + · · · + Ak rkn is also a solution,
where A′i s are arbitrary constants and ri′ s non zero
constants.
4.3 Second-Order Linear Homogeneous Recurrence
Relations with Constant Coefficients
c0 x 2 + c1 x + c2 = 0 (5)
Solution
(a) a0 = 5, an = 3an−1 , n ≥ 1 :
X’c equation: x − 3 = 0 ⇒ r = 3.
General solution solution: an = A (3n ) .
Give Condition: a0 = 5 ⇒ A30 = 5 ⇒ A = 5.
So the solution is an = 5 · 3n .
(b) 2an+2 − 11an+1 + 5an = 0, n ≥ 0, a0 = 2, a1 = −8.
X’c equation: 2x 2 − 11x + 5 = 0 ⇒ x = 12 or x = 5.
General solution: an = A (2−n ) + B (5n ) .
(
a0 = 2 ⇒ A+B =2
Given Conditions:
a1 = −8 ⇒ A2 + 5B = −8
B = −2, A = 4.
Thus the solution is an = 22−n − 2 (5n ).
(c) an+2 = 4an+1 − 4an , n ≥ 0, a0 = 1, a2 = 3.
X’c equation: r 2 − 4r + 4 = 0 ⇒ r = 2.
General solution: an = (A + Bn) 2n .
(
a0 = 1 ⇒ A = 1
Given Conditions: 1
a1 = 3 ⇒ (A + B) 2 = 3 → B = 2
Hence the solution is an = (2 + n)2n−1 .
(d) a0 = 1, a1 = 2, an = 2 (an−1 − an−2 ) , n ≥ 2.
X’c equation: r 2 − 2r + 2 = 0 ⇒ r = 1 ± i.
√
r = 2 and θ = tan−1 11 = π4
h i
General solution: an = 2n/2 A cos( π4 n) + B sin( π4 n) .
(
a0 = 1 ⇒ A = 1
Conditions:
a1 = 2 ⇒ A + B = 2 ⇒ B = 1
n
h i
π π
Solution: an = 2 2 cos 4
n + sin 4
n .
(e) an+2 + 4an = 0. n ≥ 0, a0 = 2, a1 = 5
X’c equation: x 2 + 4 = 0 ⇒ x = ±4i
r = 4, θ = π/2
h i
nπ nπ
General solution: an = 4n A cos 2
+ B sin 2
(
a0 = 2 ⇒ A = 2
Conditions: 5
a1 = 5 ⇒ 4B = 5, B = 4
h i
nπ
Solution: an = 4n−1 8 cos 2
+ 5 sin nπ
2
2. an = c1 + c2 (7n ), is solution of an+2 + ban+1 + can = 0
X.c’s equation: (x − 1)(x − 7) = 0 or x 2 − 8x + 7 = 0
So the recurrence equation is an+2 − 8an+1 + 7an = 0
b=-8, and c=7
Solution
X’c equation: x − 1 = 0 ⇒ x = 1
General homogeneous solution: an(h) = A(1n ) = A
Particular solution: an(p) = n(A1 n + A0 ) = A1 n2 + A0 n
Find A1 , A0 , by substituting
an(p) = A1 n2 + A0 n in an+1 = an + n
(p)
an+1 = A1 (n + 1)2 + A0 (n + 1)
= An2 + (2A1 + A0 )n + (A1 + A0 )
an(p) = A1 n2 + A0 n
(p)
an+1 a− n(n) = 2A1 n + (A1 + A0 ) = n
(
2A1 = 1 ⇒ A1 = 12
A1 + A0 = 0 ⇒ A0 = −A1 = − 21
an(p) = 12 (n2 − n)
an = an(h) + an(p) = A + 12 (n2 − n)
Since a0 = 3 = A
Therefore an = 3 + 12 (n2 − n) is the solution.
Example
Solve an+2 − 6an+1 + 9an = 12(3n ), where n ≥ 0,
and a0 = 1, a1 = 4
Solution
X’C equation: x 2 − 6x + 9 = (x − 3)2 = 0 ⇒ x = 3
General homogeneous solution: an(h) = (A + Bn)3n
f (n) = 12(3n ) ⇒ an(p) = A0 n2 (3n )
(p) (p)
an+2 − 6an+1 + 9an(p) = A0 (n + 2)2 3n+2 − 6A0 (n + 1)2 3n+1
+ 9A0 n2 (3n )
= 3n+2 A0 2n2 − 2n2 + 4n − 4n + 4 − 2
= 2A0 3n+2
2A0 (3n+2 ) = 12(3n ) ⇒ A0 = 32
an(p) = 23 n2 (3n ) = 2n2 (3n−1 )
∴ an = (A + Bn)3n + 2n2 3n−1 is a general solution.
General solution: an = (A + Bn)3n + 2n2 3n−1 , n ≥ 0
Conditions: a0 = 1, a1 = 4
(
a0 = 1 ⇒ A = 1
a1 = 4 ⇒ (A + B) 3 + 2 = 4, B = − 31
Thus an = (2n2 − n + 3)3n−1 is the solution of the
recurrence relation an+2 − 6an+1 + 9an = 12(3n ), n ≥ 0,
and a0 = 1, a1 = 4
Steps to solve: c0 an + c1 an−1 + c2 an−2 = f (n), n ≥ 2,
a 0 = x0 , a 1 = x1 .
1 Write the X’c equation: c0 x 2 + c1 x + c2 = 0
replace an by x 2 , an−1 by x 1 = x , and an−2 by x 0 = 1,
√
−c1 ± c12 −4c0 c2
2 Solve the X’c equation: x = 2c0
3 Write the general homogeneous solution an(h)
(h)
an = Ar1n + Br2n for r1̸= r2 real roots
(h) n
c1 c1
an = (A + Bn) − 2c 0
for r1 = r2 = − 2c 0
(h)
an = [A cos(nθ) + B sin(nθ)] r n for
x = a ± ib = r (cos θ + i sin θ)
4. Guess an(p) , particular solution using f (n) and X’c roots.
For example, an − an−2 = 3n2n , n ≥ 2, a0 = 2, a1 = 6.
(p)
f (n) = 3n2n and an = ns (A1 n + A0 ) 2n , where
s=0 if 2 is not a root of the X’c equation
s=1 if 2 is a root of the X’c equation
s=2 if 2 is a repeated root of the X’c equation
X’c equation: x 2 − 1 = 0 ⇒ x = ±1
s=0 since 2 is not a root to the X’c equation.
(h)
an = A(1)n + B(−1)n = A + B(−1)n
(p)
an = (A1 n + A0 ) 2n , A1 , A0 undetermined coefficients.
5. Determine the values of the undetermined coefficents: by
substituting an(p) in the given recurrence relation.
an(p) = (A1 n + A0 ) 2n
(p)
an−2 = [A1 (n − 2) + A0 ] 2n−2
(p)
an(p) − an−2 = (4A1 n + 4A0 − A1 n + 2A1 − A0 ) 2n−2 = 3n2n
(3A1 n + 2A1 + 3A0 ) 2n−2 = 12n2n−2
(
3A1 = 12 ⇒ A1 = 4
2A1 + 3A0 = 0 ⇒ A0 = − 38
8
an(p) = 4n − 3
2n is the particular solution.
6. Write the general solution:
(h) (p) 8
an = an + an = A + B(−1)n + 4n − 3 2n
7. Use the given conditions to find the values of the
arbitrary constants.
Conditions: a0
= 2, a1 = 6
a0 = 2 ⇒ A + B − 83 = 2
a1 = 6 ⇒ A − B + 83 = 6
2A = 8 ⇒ A = 4
2
B= 3
an = 4 + 23 (−1)n + 4n − 8
3
2n is the solution.
Exercise
Solve the following recurrence relations
2
1 an+1 an = n , n ≥ 0, a0 = 1.
n
2 an − 2an−1 + an=2 = 2 , n ≥ 2, a0 = 1, a1 = 2.
Example (Application of Recurrence Relations: Bacteria)
The number of bacteria in a colony doubles every hour. If the
colony begins with 5 bacteria, how many present in n hours?
Find the recursive definition and solution
Solution
Recursive definition:
an = 2an−1 , n ≥ 1,
a0 = 5
Solution:
an = 2an−1
an = 2 (2an−2 ) = 22 an−2
an = 2 (2 (an−3 )) = 23 an−3
···
Example (Application of Recurrence Relations: Interest)
The bank pays 12% annual interest compounded monthly. You
initially invest 1000 Birr. Find the recursive definition and
explicit solution.
How much money is in the account after 1 year?
Solution
The sequence is a geometric sequence with first term
a0 = 100 and common ratio r = 1.01
Recursive definition:
a0 = 100, an = (1.01) an−1
Solution of the recurrence relation: an = 1000(1.01)n