0% found this document useful (0 votes)
26 views19 pages

Advanced Counting Techniques

Uploaded by

ahmedjhuar81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views19 pages

Advanced Counting Techniques

Uploaded by

ahmedjhuar81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Chapter Four - Advanced Counting Techniques

The Inclusion Exclusion Principle

Suppose that A1 and A2 are sets. Then |A1 ∪ A2 | = |A1 | + |A2 | − |A1 ∩ A2 |
Example How many bit strings of length eight either start with a 1 bit or
end with the two bits 00?
Solution There are 27 bit strings that start with 1 and 26 bit strings that
end with 00. 25 bit strings that start with 1 and end with 00.
Hence, bit strings that start with a 1 bit or end with 00 are
|A1 ∪A2 | = |A1 |+|A2 |−|A1 ∩A2 | = 27 +26 −25 = 25 (22 +2−1) = 32(5) = 160
Example A company receives 350 applications. Suppose 220 of these ap-
plicants majored in CS, 147 majored in business, and 51 majored both in
CS and business. How many of the applicants majored neither in CS nor in
business?
Solution Let N stand for the total number of applicants. Let A1 be the set
of CS majors and A2 denote the set of business majors.
|Ac1 ∩ Ac2 | = |(A1 ∪ A2 )c | = N − |A1 ∪ A2 | = N − (|A1 | + |A2 | − |A1 ∩ A2 |)
= 350 − (220 + 147 − 51) = 350 − 316 = 34
Example Let S represent the set of 100 students enrolled in 3 courses c1 , c2 ,
and c3 .
If N (c1 ) = 35, N (c2 ) = 30, N (c3 ) = 30,
N (c1 ∩ c2 ) = 9, N (c1 ∩ c3 ) = 11, N (c2 ∩ c3 ) = 10, and N (c1 ∩ c2 ∩ c3 ) = 5.
What is the number of students enrolled in neither of the three courses?

1
Solution N (c¯1 ∩ c¯2 ∩ c¯3 ) = N ((c1 ∪ c2 ∪ c3 )c ) = N − [N (c1 ∪ c2 ∪ c3 )]
However, N (c1 ∪ c2 ∪ c3 ) = N (c1 ) + N (c2 ) + N (c3 ) − {N (c1 ∩ c2 ) + N (c1 ∩
c3 ) + N (c2 ∩ c3 )} + N (c1 ∩ c2 ∩ c3 )
Hence, N (c1 ∪ c2 ∪ c3 ) = 35 + 30 + 30 − (9 + 11 + 10) + 5 = 70
Thus, N (c¯1 ∩ c¯2 ∩ c¯3 ) = 100 − 70 = 30
Example Determine the number of positive integers n where 1 ≤ n ≤ 100
and n is not divisible by 2, 3, or 5.
Solution S = {1, 2, 3, ..., 100}, N = 100
c1 = {n : 2|n}
c2 = {n : 3|n}
c3 = {n : 5|n}
N (c¯1 ∩ c¯2 ∩ c¯3 ) =?
N (c1 ) = ⌊100/2⌋ = 50
N (c2 ) = ⌊100/3⌋ = 33
N (c3 ) = ⌊100/5⌋ = 20
c1 ∩ c2 = {n : 2|n ∧ 3|n} = {n : 6|n}
c1 ∩ c3 = {n : 2|n ∧ 5|n} = {n : 10|n}
c2 ∩ c3 = {n : 3|n ∧ 5|n} = {n : 15|n}
c1 ∩ c2 ∩ c3 = {n : 2|n ∧ 3|n ∧ 5|n} = {n : 30|n}
N (c1 ∩ c2 ) = ⌊100/6⌋ = 16
N (c1 ∩ c3 ) = ⌊100/10⌋ = 10
N (c2 ∩ c3 ) = ⌊100/15⌋ = 6
N (c1 ∩ c2 ∩ c3 ) = ⌊100/30⌋ = 3

2
N (c¯1 ∩ c¯2 ∩ c¯3 ) = N − N (c1 ∪ c2 ∪ c3 )
However, N (c1 ∪ c2 ∪ c3 ) = N (c1 ) + N (c2 ) + N (c3 ) − {N (c1 ∩ c2 ) + N (c1 ∩
c3 ) + N (c2 ∩ c3 )} + N (c1 ∩ c2 ∩ c3 )
= 50 + 33 + 20 − (16 + 10 + 6) + 3 = 74
∴ N (c¯1 ∩ c¯2 ∩ c¯3 ) = 100 − 74 = 26

Recurrence Relations

A recurrence relation is a rule for determining subsequent terms of a sequence


from those that precede them.
Example Arthmetic sequence
an = an−1 + d, n ≥ 1, a0 = a
Example Geometric Sequence
an = an−1 r, n ≥ 1, a0 = 1
an = an−1 r = an−2 r2 = ... = a0 rn (Explicit formula)
If r = 2 and a0 = 5, i.e an = 5 · 2n
a5 = 5 · 25 = 160
Example The recursive relation
an = an−1 + n, a0 = 0 can be written as

3
a1 = a0 + 1

a2 = a1 + 2 = a0 + 1 + 2

a3 = a2 + 3 = a0 + 1 + 2 + 3
..
.
n
X
an = k
k=0

n(n+1)
Hence, an = 2
.

Modeling with recurrence relations

1. Fibonacci Sequence
fn = fn−1 + fn−2 , f1 = 1, f2 = 1
2. The tower of Hanoi
Hn = 2Hn−1 + 1
We can use iterative approach to solve this recurrence relation:

4
Hn = 2Hn−1 + 1

= 2(2Hn−2 + 1) + 1 = 22 Hn−2 + 2 + 1

= 2(2(2Hn−3 + 1) + 1) + 1

= 23 Hn−3 + 22 + 2 + 1
..
.

= 2n−1 H1 + 2n−2 + 2n−3 + ... + 22 + 2 + 1

= 2n−1 + 2n−2 + 2n−3 + ... + 22 + 2 + 1(H1 = 1)

Pn−1
Hence, Hn = i=0 2i = 2n − 1.
Example Find a recurrence relation for the number of bit strings of length
n that do not have two consecutive zeros. How many such bit strings are of
length 5?
Solution Clearly a1 = 2, a2 = 3. Assume n ≥ 3.
The number of bit strings of length n that do not have two consecutive 0’s
equals the number of such bit strings ending with a 0 plus the number of
such bit strings ending with a 1.
The bit strings of length n ending with 1 that do not have two consecutive
0’s are the bit strings of length n − 1 with no consecutive 0’s and a 1 added
at the end. Hence, an−1 such bit strings.

5
The bit strings of length n ending with 0 that do not have two consecutive
0’s are the bit strings of length n − 1 that end with 1. Hence, there are an−2
such bit strings.
∴ an = an−1 + an−2 , n ≥ 3
{an } satisfies the same recurrence relation as the Fibonacci sequence. Be-
cause a1 = f3 and a2 = f4 , it follows that an = fn+2 .
Definition A recurrence relation of the form

an = c1 an−1 + c2 an−2 + ... + ck an−k

where c1 , c2 , ..., ck are real numbers and ck ̸= 0,


* Is linear (depends linearly on previous terms, no power or product of pre-
vious terms)
Example an = a2n−1 + 1 or an = an−1 · an−2 are non-linear
* It is homogeneous;no terms occur that are not multiples of the aj ’s
Example Hn = 2Hn−1 + 1 and an = 2an−1 + n are nonhomogeneous
* The degree is k because an is expressed in terms of the previous k terms of
the sequence.
A sequence satisfying the recurrence relation

an = c1 an−1 + c2 an−2 + ... + ck an−k

is uniquely determined by this recurrence relation and the k initial conditions


a0 = C0 , a1 = C1 , ..., ak−1 = Ck−1 .

6
Solving linear homogeneous recurrence relations with constant co-
efficients

Given the recurrence relation

an = c1 an−1 + c2 an−2 + ... + ck an−k ,

we seek a solution of the form an = rn , where r is a constant.


an = rn is a solution if and only if

rn − c1 rk−1 − c2 rk−2 − ... − ck−1 r − ck = 0 · · · (∗)

an = rn is a solution if and only if r is a solution of (*).


We call (*) the characteristic equation of the recurrence relation. The so-
lutions of this equation are called the characteristic roots of the recurrence
relation.
For homogeneous relation of order two

an = c1 an−1 + c2 an−2 , n ≥ 2

Substituting an = rn , we get

r 2 − c1 r − c2 = 0

7
The roots r1 and r2 of this equation can determine the following three cases:
A) r1 and r2 are distinct real numbers
B) r1 and r2 are real but r1 = r2
C) r1 and r2 form a complex conjugate pair
Case (A) (Distinct Real Roots)
Theorem Let c1 and c2 be real numbers. Suppose that r2 − c1 r − c2 = 0
has two distinct roots r1 and r2 . Then the sequence {an } is a solution of the
recurrence relation
an = c1 an−1 + c2 an−2

if and only if an = α1 r1n + α2 r2n for n = 0, 1, 2, ... where α1 and α2 are con-
stants.
Example What is the solution of the recurrence relation an = an−1 + 2an−2
with a0 = 2 and a1 = 7?
Solution The characteristic equation is r2 − r − 2 = 0. The characteristic
roots are r = 2 and r = −1.
Hence, the sequence {an } is a solution to the recurrence relation if and only
if an = α1 2n + α2 (−1)n for some constants α1 and α2 .
From the initial conditions

8
α0 = 2 = α1 + α2

α1 = 7 = 2α1 − α2

=⇒ α1 = 3, α2 = −1
Hence, an = 3 · 2n − (−1)n .
Example Find an explicit formula for the Fibonacci sequence
Example The recurrence relation is given by fn = fn−1 + fn−2 with f0 = 0
and f1 = 1.
The characteristic equation is r2 − r − 1 = 0
√ √
1+ 5 1− 5
=⇒ r1 = 2
and r2 = 2
.
√ √
Hence, fn = α1 ( 1+2 5 )n + α2 ( 1−2 5 )n

f0 = 0 = α1 + α2
√ √
1+ 5 1− 5
f1 = 1 = α1 ( ) + α2 ( )
2 2

Since α1 = −α2 ,
√ √
f1 = 1 = α1 ( 1+2 5 ) − α1 ( 1−2 5 )
√ √
=⇒ α1 (1 + 5) − α1 (1 − 5) = 2

=⇒ 2 5α1 = 2

9
√1 −1
=⇒ α1 = 5
and α2 = √
5
√ √
Hence, fn = √1 [( 1+ 5 )n − ( 1−2 5 )n ]
5 2

Case (B) (Repeated Real Roots)


Theorem Let c1 and c2 be real numbers with c2 ̸= 0. Suppose that r2 −c1 r −
c2 = 0 has only one root r0 . A sequence {an } is a solution of the recurrence
relation
an = c1 an−1 + c2 an−2

if and only if an = α1 r0n + α2 nr0n for n = 0, 1, 2, ... where α1 and α2 are


constants.
Proof W.T.S If an = α1 r0n + α2 nr0n , then {an } is a solution of the recurrence
relation. Because r0 is a single root of the characteristic equation r2 − c1 r −
c2 = 0, it follows that (r − r0 )2 = r2 − 2r0 r + r02 = r2 − c1 r − c2
=⇒ c1 = 2r0 and c2 = −r02
We see that

c1 an−1 + c2 an−2 = c1 (α1 r0n−1 + α2 (n − 1)r0n−1 ) + c2 (α1 r0n−2 + α2 (n − 2)r0n−2 )

= α1 r0n−2 (c1 r0 + c2 ) + α2 r0n−2 ((n − 1)c1 r0 + (n − 1)c2 − c2 )

= α1 r0n + α2 r0n−2 ((n − 1)(c1 r0 + c2 ) + r02 )


| {z }
r02

= α1 r0n + α2 nr0n

= an

10
(The reverse direction) To show every solution {an } of the recurrence rela-
tion an = c1 an−1 + c2 an−2 has an = α1 r0n + α2 nr0n , we will show that there
are constants α1 and α2 such that the sequence {an } with an = α1 r1n + α2 r2n
satisfies the same initial conditions. This requires that

a0 = C 0 = α 1

a1 = C1 = α1 r0 + α2 r0

α2 r0 = C1 − C0 r0
C1 − C0 r0
α2 = , r0 ̸= 0
r0

Example What is the solution of the recurrence relation an = 6an−1 − 9an−2


with initial conditions a0 = 1 and a1 = 2?
Solution The characteristic equation is r2 − 6r + 9 = 0 =⇒ (r − 3)2 = 0
=⇒ r = 3 is a single root for the characteristic equation.
Hence, the solution of the recurrence relation is an = α1 3n + α2 n3n

a0 = 1 = α 1

a1 = 3 + α2 3 = 6 =⇒ α2 = 1

Hence, the solution to the recurrence relation and the initial conditions is
an = 3n + n3n .

11
Case (C) Complex Roots
Recall De Moiver’s Theorem
(cosθ + isinθ)n = cosnθ + isinnθ, n ≥ 0
p
If z = x + iy ∈ C, z ̸= 0, z = r(cosθ + isinθ) where r = x2 + y 2 and
y
tanθ = x

Example Solve the recurrence relation

an = 2(an−1 − an−2 ), n ≥ 1, a0 = 1, a1 = 2

Solution The characteristic equation is r2 − 2r + 2 = 0 whose roots are 1 ± i.


Hence, the general solution is α1 (1 + i)n + α2 (1 − i)n

√ π π
1+i= 2[cos( ) + isin( )]
4 4

and

√ −π −π
1−i= 2[cos(
) + isin( )]
4 4
√ π π
= 2[cos( ) − isin( )]
4 4

12
Hence,

an = α1 (1 + i)n + α2 (1 − i)n
√ π π √ −π −π n
= α1 [ 2(cos( ) + isin( ))]n + α2 [ 2(cos( ) + isin( ))]
4 4 4 4
√ nπ nπ √ nπ nπ
= α1 ( 2)n (cos( ) + isin( )) + α2 ( 2)n (cos( ) − isin( ))
4 4 4 4
√ n nπ nπ
= ( 2) ((α1 + α2 )cos( ) + (α1 − α2 )isin( ))
4 4
√ n nπ nπ
= ( 2) (k1 cos( ) + k2 sin( ))
4 4

where k1 = α1 + α2 and k2 = (α1 − α2 )i

a0 = 1 = k1
√ 1 1
a1 = 2 = 2(k1 √ + k2 √ )
2 2


=⇒ k2 = 1 ∴ an = ( 2)n [cos( nπ
4
) + sin( nπ
4
)], n ≥ 0

Let’s generalize the above result to linear homogeneous recurrence relation


with degree greater than two.
Theorem Let c1 , c2 , ..., ck be real numbers. Suppose that the characteristic
equation

rk − c1 rk−1 − ...ck = 0

13
has k distinct roots r1 , r2 , ..., rk . Then a sequence an is a solution of the
recurrence relation

an = c1 an−1 + c2 an−2 + ... + ck an−k

if and only if
an = α1 r1n + a2 r2n + ... + ak rkn

for n = 0, 1, 2, ... where α1 , α2 , ..., αk are constants.


Example Find the solution to the recurrence relation
an = 6an−1 − 11an−2 + 6an−3 with initial conditions a0 = 2, a1 = 5, and
a2 = 15.
Solution The characteristic equation is r3 − 6r2 + 11r − 6 = 0 and the char-
acteristic roots are r = 1, r = 2 and r = 3.
Hence, an = α1 · 1n + α2 · 2n + α3 · 3n

a0 = 2 = α1 + α2 + α3

a1 = 5 = α1 + 2α2 + 3α3

a2 = 15 = α1 + 4α2 + 9α3

The solution is α1 = 1, α2 = −1, and α3 = 2.


Hence, an = 1 − 2n + 2 · 3n .
Theorem Let c1 , c2 , ..., ck be real numbers. Suppose that the characteristic

14
equation
rk − c1 rk−1 − ... − ck = 0

has t distinct roots r1 , r2 , ..., rt with multiplicities m1 , m2 , ..., mt , respec-


tively, so that mi ≥ 1 for i = 1, 2, ..., t and m1 + m2 + ... + mk = k. Then a
sequence {an } is a solution of the recurrence relation

an = c1 an−1 + c2 an−2 + ... + ck an−k

if and only if

an = (α1,0 + α1,1 n + ... + α1,m1 −1 nm1 −1 )r1n

+ (α2,0 +α2,1 n + ... + α2,m2 −1 nm2 −1 )r2n

+ ... + (αt,0 +αt,1 n + ... + αt,mt −1 nmt −1 )rtn

for n = 0, 1, 2, ... where αi,j are constants for 1 ≤ i ≤ t and 0 ≤ j ≤ mi − 1.


Example Find the solution to the recurrence relation

an = −3an−1 − 3an−2 − an−3

with initial conditions a0 = 1, a1 = −2, and a2 = −1.


Solution The characteristic equation is r3 + 3r2 + 3r + 1 = 0.
=⇒ (r + 1)3 = 0 i.e -1 is a characteristic equation of multiplicity 3.
Hence, an = (α1,0 + α1,1 n + α1,2 n2 )(−1)n .

15
a0 = 1 = α1,0

a1 = −2 = −(α1,0 + α1,1 + α1,2 )

a2 = −1 = (α1,0 + 2α1,1 + 4α1,2 )

Solving we get, α1,1 = 3 and α1,2 = −2


Hence, an = (1 + 3n − 2n2 )(−1)n .

Linear Nonhomogeneous Recurrence Relations with Constant Co-


efficients

Recurrence relation of the form

an = c1 an−1 + c2 an−2 + ... + ck an−k + F (n)

where c1 , c2 , ..., ck are real numbers and F (n) ̸= 0 is called a linear nonhomo-
geneous recurrence relation with constant coefficients and

an = c1 an−1 + c2 an−2 + ... + ck an−k

is the associated homogeneous recurrence relation.


Example The recurrence relations an = an−1 + 2n is linear nonhomogeneous
an = an−1 is the associated linear homogeneous equation.

16
(p)
Theorem If {an } is a particular solution of the nonhomogeneous linear
recurrence relation with constant coefficients

an = c1 an−1 + c2 an−2 + ... + ck an−k + F (n) · · · (∗)

(h)
and {an } is a solution of the associated homogeneous recurrence relation

an = c1 an−1 + c2 an−2 + ... + ck an−k ,

(p) (h)
then every solution of (*) is of the form {an + an }.
Example Find all solutions of the recurrence relation an + 3an−1 + 2n. What
is the solution with a1 = 3?
Solution The associated linear homogeneous recurrence relation is an =
(h)
3an−1 . Hence, an = α3n , where α is a constant.
(p)
F (n) = 2n. A reasonable guess for a particular solution is an = cn + d.
Since an = 3an−1 + 2n, cn + d = 2(c(n − 1) + d) + 2n,
=⇒ (2c + 2)n + (2d − 3c) = 0.∀n
−3
=⇒ c = −1, d = 2

an = −n − 32 + α · 3n , where α is a constant.
If a1 = 3, an = −n − 32 + ( 11
6
)3n .
Example Find all solutions of the recurrence relation an = 5an−1 −6an−2 +7n
Solution The associated homogeneous equation is an = 5an−1 − 6an−2 and
r = 2 and r = 3 are the characteristic roots.
(h)
Hence, an = α1 · 3n + α2 · 2n where α1 and α2 are constants.

17
(p)
Because F (n) = 7n , a reasonable guess for the an = A7n , substituting we
get
A7n = 5A7n−1 − 6A7n−2 + 7n

=⇒ 49A = 35A − 6A + 49
49
=⇒ A = 20
(p)
Hence, an = ( 49
20
)7n
an = α1 3n + α2 2n + ( 49
20
)7n
Theorem Suppose that {an } satisfies the linear nonhomogeneous recurrence
relation
an = c1 an−1 + c2 an−2 + ... + ck an−k + F (n)

where c1 , c2 , ..., ck are real numbers, and

F (n) = (bt nt + bt−1 nt−1 + ... + b1 n + b0 )sn

where b0 , b1 , ..., bt and s are real numbers. When s is not a root of the char-
acteristic equation of the associated linear homogeneous recurrence relation,
there is a particular solution of the form (pt nt + pt−1 nt−1 + ... + p1 n + p0 )sn
when s is a root of this characteristic equation and its multiplicity is m, there
is a particular solution of the form

nm (pt nt + pt−1 nt−1 + ... + p1 n + p0 )sn .

18
Example What form does a particular solution of the linear nonhomoge-
neous recurrence relation an = 6an−1 − 9an−2 + F (n) have when F (n) = 3n ,
F (n) = n3n , F (n) = n2 2n , and F (n) = (n2 + 1)3n ?
Solution The associated linear homogeneous equation is an = 6an−1 −9an−2 .
The characteristic equation is r2 − 6r + 9 = (r − 3)2 = 0.
(p)
=⇒ r = 3 is a characteristic root of multiplicity 2. Hence, an = p0 n2 3n if
F (n) = 3n
(p)
an = (p1 n + p0 )n2 3n if F (n) = n3n
(p)
an = (p2 n2 + p1 n + p0 )n2 3n if F (n) = n2 3n
(p)
an = (p2 n2 + p1 n + p0 )2n if F (n) = (n2 + 1)2n

19

You might also like