CPE204 Discrete Mathematics (Week 6)
CPE204 Discrete Mathematics (Week 6)
Recurrence Relations
Solving Linear Recurrence Relations
2
The second sequence is the famous Fibonacci
sequence where each term, after the second, is the
sum of the previous 2 terms. It can be written
◦ an+2=an+1+an, a0= 1, a1= 1
If the first 2 terms are different, there would be a
different sequence.
The first term(s) is(are) called the initial value(s).
In some cases they are not supplied and so only a very
general description can be made.
These two examples are examples of recurrence
relations
3
A sequence is a function from a subset of the set of
integers. We use the notation an to denote the image of
the integer n. We call an a term of the sequence.
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 called a solution of a recurrence relation if its
terms satisfy the recurrence relation.(A recurrence relation is said
to recursively define a sequence)
4
EXAMPLE 1: Let {an} be a sequence that satisfies the
recurrence relation an = an−1 + 3 for n = 1, 2, 3, . . . ,
and suppose that a0 = 2.
What are a1, a2, and a3?
◦ Solution: We see from the recurrence relation that
a1 = a0 + 3 = 2 + 3 = 5, a2 = a1 + 3= 5 +3= 8 and a3 = 8 + 3
= 11.
EXAMPLE 2: 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.
What are a2 and a3?
◦ Solution: We see from the recurrence relation that
a2 = a1 − a0 = 5 − 3 = 2 and a3 = a2 −a1 = 2 − 5 = −3.
We can find a4, a5, and each successive term in a similar way.
5
Any sequence whose terms (except the initial
terms) satisfy a recurrence relation is called a
(particular) solution of that recurrence relation.
To solve a recurrence relation, means to find
an explicit expression for general term of
the sequence whose terms (except the initial
ones) satisfy the recurrence.
6
Example1: Solve the following recurrence relation
an+1= 2an, a0= 3
◦ Solution: The first step of finding the solution is to find a1, a2, a3 then use
the pattern shown to find a formula(called a closed formula). Then show that
that formula satisfies the recurrence relation.
Notice how the 2's keep `piling up'. Also notice that the power of 2 is the same
as a's subscript. So the conjecture is an = 2n .3
Now to confirm that this is correct we check if it satisfies the recurrence relation
(and also the initial terms).
7
Example2: Solve the following recurrence relation
an = an−1 + 3 for n = 1, 2, 3, . . . , and suppose that a1 = 2.
◦ Solution:
a2 = 2 + 3
a3 = (2 + 3) + 3 = 2 + 3 · 2
a4 = (2 + 2 · 3) + 3 = 2 + 3 · 3
...
an = 2 + 3(n − 1)
Now to confirm that this is correct
an =an−1 + 3 = (an−2 + 3) + 3 = an−2 + 3 · 2 = (an−3 + 3) + 3 · 2
= an−3 + 3 · 3
...
= a2 + 3(n − 2) = (a1 + 3) + 3(n − 2) = 2 + 3(n − 1).
a1=2+3( 1-1)= 2 #
8
Example3: Determine whether the sequence {an},
where an = 3n for every nonnegative integer n, is a
solution of the recurrence relation an = 2an-1 - an-2
for n = 2,3,4,.... Assume a0=0 and a1=3.
◦ Solution:
Check initial conditions:a0 = 3(0)=0, a1 = 3(1) = 3
Check if {3n} satisfies an = 2an-1 - an-2
2an-1 - an-2 = 2[3(n-1)] - 3(n-2) = 6n - 6 - 3n + 6 = 3n = an
So, {3n} is a solution for an = 2an-1 - an-2
9
Example4: Determine whether the sequence {an},
where an = 2n for every nonnegative integer n, is a
solution of the recurrence relation an =2an-1 - an-2
for n = 2,3,4,.... Assume a0=1 and a1=2..
◦ Solution:
Check initial conditions: a0= 20 = 1, a1= 21 = 2
Check if {2n} satisfies an =2an-1 - an-2
2an-1 - an-2 = 2(2n-1) - 2n-2 = 2n-2(4-1) = 3(2n-2) ≠ 2n
So, {2n} is not a solution for an =2an-1 - an-2
◦ You can also disprove it by a counterexample
(a2 = 22 = 4, a2 = 2a1 - a0 = 2(2) - 1 = 3 ≠ 4)
10
We can use recurrence relations to model a
wide variety of problems(used for advanced
counting), such as finding compound interest
(see next Example), counting rabbits on an
island, determining the number of moves in
the Tower of Hanoi puzzle, and counting bit
strings with certain properties.
11
Example1: Suppose that a person deposits
$10,000 in a savings account at a bank yielding
11% per year with interest compounded annually.
How much will be is the account after 30 years?
◦ Solution:
◦ Determine an
an is “the amount in the account after n years”.
◦ Find the recurrence relation that an satisfies and the
initial condition
an = an-1 + (0.11) an-1 = (1.11) an-1
a0 = 10,000
12
◦ Solution:
an = (1.11) an-1 , a0 = 10,000
◦ Guess a solution (formula) for an
a1 = (1.11) a0 = (1.11) (10,000) , a2 = (1.11) a1 = (1.11)2 (10,000), a3 = (1.11) a2 = (1.11)3 (10,000)
:
an = (1.11) an-1 = (1.11)n (10,000)
◦ Verify your guess using induction
◦ Basis step: a0 = (1.11)0 (10,000) = 10,000
◦ Inductive step: (Ɐk (ak→ ak+1))
Assume ak = (1.11)k (10,000).
ak+1 = (1.11) ak (by recurrence relation)
= (1.11)(1.11)k (10,000) (by inductive hypothesis)
= (1.11)k+1 (10,000)
So, the solution is valid.
◦ a30 = (1.11)30 (10,000) = 228,922.97
13
Solving Linear Recurrence
Relations
14
A recursive definition of a sequence specifies
◦ Initial conditions
◦ Recurrence relation
15
1. Linear homogeneous recurrences
2. Linear non-homogeneous recurrences
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: previous terms appear with exponent1(not squares,
cubes, etc)
Homogeneous: no term other than the multiples of ai’s.
Degree k: expressed in terms of previous k terms
Constant coefficients: coefficients in front of the terms are
constants, instead of general functions.
16
Determine if the following recurrence relations are linear
homogeneous recurrence relations with constant coefficients.
Pn = (1.11)Pn-1
◦ a linear homogeneous recurrence relation of degree one
an = an-1 + a2n-2
◦ not linear
fn = fn-1 + fn-2
◦ a linear homogeneous recurrence relation of degree two
Hn = 2Hn-1+1
◦ not homogeneous
an = an-6
◦ a linear homogeneous recurrence relation of degree six
Bn = nBn-1
◦ does not have constant coefficient
17
Proposition 1:
◦ Let an = c1an-1 + c2an-2 + … + ckan-k be a linear
homogeneous recurrence.
◦ Assume the sequence an satisfies the recurrence.
◦ Assume the sequence a’n also satisfies the
recurrence.
◦ So, bn = an + a’n (solution)and dn=αan (initial conditions)are
also sequences that satisfy the recurrence.
◦ (α is any constant) (we need to find it)
18
It follows from the previous proposition, if we
find some solutions to a linear homogeneous
recurrence, then any linear combination of
them will also be a solution to the linear
homogeneous recurrence.
Our target is to try to find any solution of the
form an = rn that satisfies the recurrence
relation.
19
Assume we have recurrence relation
an = c1an-1 + c2an-2 + … + ckan-k
Try to find a solution of form rn
rn = c1rn-1 + c2rn-2 + … + ckrn-k
rn - c1rn-1 - c2rn-2 - … - ckrn-k = 0
rk - c1rk-1 - c2rk-2 - … - ck = 0 (dividing both sides by rn-k)
This equation is called the characteristic
equation.
20
Example1:
The Fibonacci recurrence is
Fn = Fn-1 + Fn-2
Its characteristic equation is (note: k=2)
r2 - r - 1 = 0
Example2:
The following recurrence is
an = -an-1 + 4an-2 + 4an-3
Its characteristic equation is (note: k=3)
r3 + r2 – 4r -4 = 0
21
Proposition 2:
r is a solution of rk - c1rk-1 - c2rk-2 - … - ck = 0 if and only if
rn is a solution of an = c1an-1 + c2an-2 + … +ckan-k.
Example:
consider the characteristic equation r2 - 4r + 4 = 0.
r2 - 4r + 4 = (r - 2)2 = 0
So, r=2.
So, 2n satisfies the recurrence Fn = 4Fn-1 - 4Fn-2.
2n = 4 . 2n-1 - 4 . 2n-2
2n-2 ( 4 - 8 + 4) = 0
22
Theorem 1:
Consider the characteristic equation
rk - c1rk-1 - c2rk-2 - … - ck =0
and the recurrence an = c1an-1 + c2an-2 + … + ckan-k.
Assume r1, r2, …and rm all satisfy the equation.
Let α1, α2, …, αm be any constants.
So, an = α1 r1n + α2 r2n + … + αm rmn satisfies the recurrence.
23
What is the solution of the recurrence relation
an = an-1 + 2an-2 with a0=2 and a1=7?
Solution:
Since it is linear homogeneous recurrence, first find its
characteristic equation:
r2 - r - 2 = 0 (Solution of quadratic equation)
(r+1)(r-2) = 0 r1 = 2 and r2 = -1
So, by theorem an = α12n + α2 (-1)n is a solution.
Now we should find α1 and α2 using initial conditions with the
solution.
a0= α1 + α2 = 2
a1= α1 2 + α2(-1) = 7
So, α1 = 3 and α2 = -1.
an = 3 . 2n - (-1)n is a solution #
24
What is the solution of the recurrence relation fn = fn-1 + fn-2 with f0=0
and f1=1?
Solution:
Since it is linear homogeneous recurrence, first find its characteristic
equation:
r2 - r - 1 = 0 (Solution of quadratic equation)
r1 = and r2 =
So, by theorem fn = α1 ( ) n + α2 ( )n is a solution.
Now we should find α1 and α2 using initial conditions.
f0= α1 + α2 = 0
f1= α1 + α2 =1
So, α1 = and α2 = - .
fn = .( )n - .( )n is a solution #
25
What is the solution of the recurrence relation an = -an-1 + 4an-2 + 4an-3
with a0=8, a1=6 and a2=26?
Solution:
Since it is linear homogeneous recurrence, first find its characteristic
Equation:
r3 + r2 - 4r - 4 = 0 (Solution of polynomial equation)
(r+1)(r+2)(r-2) = 0 r1 = -1, r2 = -2 and r3 = 2
So, by theorem an = α1(-1)n + α2(-2)n + α3 2n is a solution.
Now we should find α1, α2 and α3 using initial conditions.
a0= α1+ α2 + α3 = 8
a1= - α1 - 2 α2 + 2 α3 = 6
a2= α1 + 4 α2 + 4 α3 = 26
So, α1 = 2, α2 = 1 and α3 = 5.
an = 2 . (-1)n + (-2)n + 5 . 2n is a solution #
26
Theorem 2:
Consider the characteristic equation rk - c1rk-1 - c2rk-2 - … - ck = 0
and the recurrence an = c1an-1 + c2an-2 + … + ckan-k.
Assume the characteristic equation has t≤k distinct solutions.
Let ∀i (1 ≤ i ≤ t) ri with multiplicity mi be a solution of the
equation.
Let ∀ i,j (1 ≤ i ≤ t and 0 ≤ j ≤ mi-1) αij be a constant.
So,
27
28
29
30
After this slides just a help for
solving equations
31
32
r2 - r - 2 = 0
33
divide the polynomial by (x+1) or (x-1).
Example: x3+3x2+3x+1 r3 + r2 - 4r - 4 = 0
34
35