Computational Problem Solving: Lecture Notes on Recurrence Relations

Verified

Added on Β 2023/01/13

|20
|6833
|97
Homework Assignment
AI Summary
This document comprises lecture notes from a Computational Problem Solving course, focusing on recurrence relations and recursive algorithms. It begins with an introduction to recursive algorithms, using the factorial function as an example, and then delves into the classic Towers of Hanoi problem, detailing the problem's constraints, solution strategy, and the derivation of the minimum number of moves (2^n - 1) through mathematical induction. The notes then formally define recurrence relations, distinguishing between linear homogeneous and non-homogeneous types. The Fibonacci and Lucas sequences are used as applications, and the document concludes with an overview of recursion implementation in Python, accompanied by example code. This assignment is available on Desklib, providing students with comprehensive study resources.
Document Page
Lecture Notes
Computational Problem Solving
Week 7:
Recurrence Relations and Algorithms
Contents
Recursive Algorithms ............................................................................................................................................. 1
Towers of Hanoi .................................................................................................................................................... 1
Recurrence Relations ............................................................................................................................................ 5
Second Order Linear Homogeneous Recurrence Relations .................................................................................. 8
Application: Fibonacci and Lucas Recurrence Relations ....................................................................................... 9
Extension Topic: General Homogeneous Recurrence Relations ......................................................................... 11
Extension Topic: Non-homogeneous Recurrence Relations ........................................................................... 12
Recursion in Python ............................................................................................................................................ 13
Recursive Algorithms
Recursive algorithms are those that call themselves. For example, to find the factorial of an integer is:
5! = 5 Γ— 4 Γ— 3 Γ— 2 Γ— 1
And more generally as:
𝑛! = 𝑛 Γ—(𝑛 βˆ’ 1) Γ— (𝑛 βˆ’ 2) Γ— … Γ— 3 Γ— 2 Γ— 1
As (𝑛 βˆ’ 1)! =(𝑛 βˆ’ 1) Γ— (𝑛 βˆ’ 2) Γ— … Γ— 3 Γ— 2 Γ— 1we can rewrite the above as:
𝑛! = 𝑛 Γ—(𝑛 βˆ’ 1)!
Where 1! = 1as a base condition. As we can see recursive algorithms have similar ideas to what we used to
prove statements by mathematical induction.
Towers of Hanoi
This involves n discs of various sizes on three posts
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
The disc starts on one of the posts with the largest disc on the bottom of the stack, with the smaller discs
resting on top of a larger disc, so ordered with respect to size.
The exercise is to move all the discs to another post, with the largest on the bottom and the smallest on top
without a larger disc resting on a small disc.
The question is: what is the minimum number of moves needed?
Understanding the Problem:
Objective:
Place the pile of discs on a different peg
Constraints:
- no disc can sit on a smaller disc
- only top disc may be moved
- you can only move one disc at a time
We are being asked to work out the minimum number of moves to move the discs from one peg to another.
We could build a model of the problem (as it was originally in Vietnam). Or we can use diagrams to help us
model the moves. We cannot really restate the problem.
The unknown is the minimum number of moves as well as the number of discs. Also, we are not sure how we
can make those moves to obtain the minimal number of moves. We have not made any assumptions apart
from the constraints of the problem and that there are a fixed number of pegs which is 3 (i.e. we are not
generalising the number of pegs).
Devising a Plan
We haven’t solved this problem before. However, we have looked at noughts and crosses. In that problem we
broke it down by seeing what happens if we add an extra column or row.
We can do a similar approach here too. We can look at the number of moves for 1 disc, 2 discs, etc to see if
we can build up a pattern.
We can then look to see how we make those moves for 2 discs, 3 discs to see what happens if we add a disc
to the source peg. We already said in part (1) that we can use diagrams to help us.
We haven’t left anything out from the problem statement. To move three discs, we may find via trial and
error:
Document Page
Following a similar strategy, we may find the number of ways to move the discs when we have 2, 3, 4, etc
discs.
Number of discs Number of moves breakdown
1 1 1
2 3 1 + 1 + 1
3 7 3 + 1 + 3
4 15 7 + 1 + 7
5 31 15 + 1 + 15
Generalising this, we may find the number of moves is:
(number of moves for 𝑛 βˆ’ 1discs) + 1 + (number of moves for 𝑛 βˆ’ 1discs)
Alternatively, we may note that the number of moves is one less than a power of 2. Therefore, the number of
moves is 2𝑛 βˆ’ 1. Hence given 𝑛 discs on a peg it will take 2𝑛 βˆ’ 1moves (minimum) to move the discs from
one peg to another peg given the constraints. But, how do we make those moves? This is where the first
strategy proves helpful. To write an algorithm for Tower of Hanoi, first we need to learn how to solve this
problem with lesser amount of discs, say β†’ 1 or 2. We mark three towers with
name, source, destination and aux (only to help moving the discs). If we have only one disc, then it can easily
be moved from source to destination peg.
If we have 2 discs βˆ’
β€’ First, we move the smaller (top) disc to aux peg.
β€’ Then, we move the larger (bottom) disc to destination peg.
β€’ And finally, we move the smaller disc from aux to destination peg.
If we then say that the larger (bottom) disc is the rest of the discs and using the relationship between the
number of moves: number of moves for 𝑛 βˆ’ 1discs) + 1 + (number of moves for 𝑛 βˆ’ 1discs), we can form a
generalised strategy.
Document Page
Approach:
β€’ Recursively Move N-1 disc from source to Auxiliary peg.
β€’ Move the last disc from source to destination.
β€’ Recursively Move N-1 disc from Auxiliary to destination peg
The steps to follow are:
Step 1 βˆ’ Move n-1 discs from source to aux
Step 2 βˆ’ Move nth disc from source to dest
Step 3 βˆ’ Move n-1 discs from aux to dest
From which we can produce pseudo-code to solve the Towers of Hanoi
problem.
START Procedure Hanoi(disc, source, dest, aux)
IF disc == 1, THEN
move disc from source to dest
ELSE
Hanoi(disc - 1, source, aux, dest) // Step 1
move disc from source to dest // Step 2
Hanoi(disc - 1, aux, dest, source) // Step 3
END IF
END Procedure STOP
Which, in Python, is:
def TowerOfHanoi(n , source, destination, auxiliary):
if n==1:
print ("Move disc 1 from source",source,"to destination",destination)
return
TowerOfHanoi(n-1, source, auxiliary, destination)
print ("Move disc",n,"from source",source,"to destination",destination)
TowerOfHanoi(n-1, auxiliary, destination, source)
# test code
n = 4
TowerOfHanoi(n,'A','B','C')
# A, C, B are the name of rods
To test this, we may look at the solutions or prove it via induction.
For the Tower of Hanoi, we have the number of moves, 𝑆𝑛 is 𝑆𝑛 = 2𝑛 βˆ’ 1for 𝑛 discs, this is our 𝑃(𝑛).
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Base case, 𝑃(1): 𝑆1 = 21 βˆ’ 1 = 2 βˆ’ 1 = 1. We know it takes one move to move one disc, so 𝑃(1)is true.
We assume that 𝑃(π‘˜): π‘†π‘˜ = 2π‘˜ βˆ’ 1is true.
Now, for 𝑃(π‘˜ + 1): π‘†π‘˜+1 = 2π‘˜+1 βˆ’ 1
π‘†π‘˜+1 = (π‘›π‘’π‘šπ‘π‘’π‘Ÿ π‘œπ‘“ π‘šπ‘œπ‘£π‘’π‘  π‘Ÿπ‘’π‘žπ‘’π‘–π‘Ÿπ‘’π‘‘ π‘‘π‘œ π‘šπ‘œπ‘£π‘’ π‘˜ 𝑑𝑖𝑠𝑐𝑠 π‘œπ‘“ π‘‘β„Žπ‘’ π‘π‘œπ‘‘π‘‘π‘œπ‘š π‘‘π‘–π‘ π‘˜)
+ (1 π‘šπ‘œπ‘£π‘’ π‘‘π‘œ π‘šπ‘œπ‘£π‘’ π‘‘β„Žπ‘’ π‘π‘Žπ‘ π‘’ 𝑑𝑖𝑠𝑐)
+ (π‘›π‘’π‘šπ‘π‘’π‘Ÿ π‘œπ‘“ π‘šπ‘œπ‘£π‘’π‘  π‘Ÿπ‘’π‘žπ‘’π‘–π‘Ÿπ‘’π‘‘ π‘‘π‘œ π‘šπ‘œπ‘£π‘’ π‘‘β„Žπ‘’ π‘˜ 𝑑𝑖𝑠𝑐𝑠 π‘π‘Žπ‘π‘˜ π‘œπ‘›π‘‘π‘œ π‘‘β„Žπ‘’ π‘π‘Žπ‘ π‘’ 𝑑𝑖
= π‘†π‘˜ + 1 + π‘†π‘˜ = 2π‘†π‘˜ + 1 = 2(2π‘˜ βˆ’ 1) + 1
= 2 Γ— 2π‘˜ βˆ’ 2 + 1 = 21 Γ— 2π‘˜ βˆ’ 1 = 2π‘˜+1 βˆ’ 1
Hence 𝑃(π‘˜ + 1) is true provided that 𝑃(π‘˜)is true.
Therefore, by mathematical induction, the number of moves for the Tower of Hanoi is 𝑆𝑛 = 2𝑛 βˆ’ 1
We therefore have the number of moves is 2𝑛 βˆ’ 1. We note that:
𝑆1 = 1
𝑆2 = 3 = 2 Γ— 1 + 1 = 2𝑆1 + 1
𝑆3 = 7 = 2 Γ— 3 + 1 = 2𝑆2 + 1
𝑆4 = 15 = 2 Γ— 7 + 1 = 2𝑆3 + 1
By looking at the pattern, we have
𝑆𝑛 = 2π‘†π‘›βˆ’1 + 1, 𝑆1 = 1
As our recursive formula.
Assessing the result:
Our solutions meets the requirements, we have found the minimal number of moves and how to make those
moves using recursion. We can then test the algorithm on 2 discs and 3 discs, etc and we get the correct
number of moves as well as the method to achieve those moves.
We could possibly make some aspects easier; however, the most simple solution in this case is the recursive
approach
Describing what we have learnt:
We learnt that we can use recursion to help solve problems and strengthen the idea of breaking a problem up
to look at simpler cases before generalising.
This problem was difficult in that the approach used is different to the noughts and crosses problem due to
the increased complexity of the solution and the exponential nature of number of moves rather than the
quadratic nature.
Documenting the solution:
Reread our solution, is there anything that should be rewritten?
Not in this case, we cannot see anything that is difficult to understand
Recurrence Relations
We have already met recurrence relations, although not formally defined what they are. Consider the
following instructions for generating a sequence:
1. Start with 5
Document Page
2. Given any term, add 3 to get the next term
If we list the terms of this sequence, we obtain
5, 8, 11, 14, 17, …
The first term is 5 because of instruction 1.
The second term is 8 because instruction 2 says to add 3 to 5 to get the next term, 8
The third term is 11 because instruction 2 says to add 3 to 8 to get the next term, 11, etc
Instructions 1 and 2 do not give an explicit formula for the nth term of the sequence in the sense of providing
a formula that we can plug n into to obtain the value of the nth term, but by computing term by term we can
eventually compute any term of the sequence.
If we denote the sequence as π‘Ž1, π‘Ž2, …, we may rephrase instruction 1 as
π‘Ž1 = 5
And instruction 2 as:
π‘Žπ‘› = π‘Žπ‘›βˆ’1 + 3, 𝑛 β‰₯ 2
π‘Ž1 = 5
π‘Žπ‘› = π‘Žπ‘›βˆ’1 + 3, 𝑛 β‰₯ 2
If we take 𝑛 = 2, we obtain π‘Ž2 = π‘Ž1 + 3 = 5 + 3 = 8
If we take 𝑛 = 3, we obtain π‘Ž3 = π‘Ž2 + 3 = 8 + 3 = 11
We can then compute any term in the sequence just as we did with instructions 1 and 2. The instructions
above are equivalent to this.
This equation is an example of a recurrence relation. A recurrence relation defines a sequence by giving the
nth value in terms of its previous values. In order for a recurrence relation to define a sequence, a start up
value (or initial conditions) must be given.
Consider the following instructions for generating a sequence:
1. Start with 5
2. Given any term, add 3 to get the next term
The following forms the function recursively (on the left) and iteratively (on the right).
Now, we will write the formal definition of a recurrence relation.
Definition 7.1
A recurrence relation for the sequence
π‘Ž0, π‘Ž1, π‘Ž2, …
Is an equation that relates π‘Žπ‘› to its predecessors π‘Ž0, π‘Ž1, … π‘Žπ‘›βˆ’1
Initial conditions for the sequence π‘Ž0, π‘Ž1, …are explicitly given values for a finite number of the terms of
the sequence
Document Page
For example, the Fibonacci sequence is defined by the recurrence relation
𝑓𝑛 = π‘“π‘›βˆ’1 + π‘“π‘›βˆ’2 𝑛 β‰₯ 3
With initial conditions 𝑓1 = 1, 𝑓2 = 1
We can form this sequence both recursively (on the left) and iteratively (on the right).
We can now have some definition. The first is a linear homogeneous recurrence relation and the second is for
the non-homogeneous case.
Definition 7.2
A linear homogeneous recurrence relation of order π‘˜ with constant coefficients is a recurrence relation of
the form
π‘Žπ‘› = 𝑐1π‘Žπ‘›βˆ’1 + 𝑐2π‘Žπ‘›βˆ’2 + β‹― + π‘π‘˜π‘Žπ‘›βˆ’π‘˜ , π‘π‘˜ β‰  0
Notice that a linear homogeneous recurrence relation of order π‘˜ with constant coefficients, together with
the π‘˜ initial conditions
π‘Ž0 = 𝐢0, π‘Ž1 = 𝐢1, … , π‘Žπ‘˜βˆ’1 = πΆπ‘˜βˆ’1
Uniquely defines a sequence π‘Ž0, π‘Ž1, ….
Similarly, we have non-homogeneous relations:
Definition 7.3
A linear non-homogeneous recurrence relation of order π‘˜ with constant coefficients is a recurrence
relation of the form
π‘Žπ‘› = 𝑐1π‘Žπ‘›βˆ’1 + 𝑐2π‘Žπ‘›βˆ’2 + β‹― + π‘π‘˜π‘Žπ‘›βˆ’π‘˜ + 𝑓(π‘Ž), π‘π‘˜ β‰  0
In other words, a non-homogenous recurrence has extra terms which are not related to previous terms.
If 𝑓(π‘Ž) = 0 then it is homogeneous.
In this module, we only look at the homogeneous cases and mostly the second order cases. This is because
this is a computer science course and to solve generalised cases involve more maths. The most important
takeaway is to understand what a recurrence relation is and how we can produce the sequence using
recursion.
Going back to the (infamous) Fibonacci sequence, the relation
𝑓𝑛 = π‘“π‘›βˆ’1 + π‘“π‘›βˆ’2
is an example of a linear homogeneous recurrence relation of order 2.
Worked Example:
What is the order of the following recurrence relations? Are they homogeneous or non-
homogeneous?
a) π‘Žπ‘› = 11π‘Žπ‘›βˆ’1 βˆ’ 39π‘Žπ‘›βˆ’2 + 45π‘Žπ‘›βˆ’3 Third order, homogeneous.
b) π‘Žπ‘› = π‘Žπ‘›βˆ’1 + 2π‘Žπ‘›βˆ’2 Second order, homogeneous
c) π‘₯𝑛 = π‘₯π‘›βˆ’2 Second order, homogeneous
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
d) π‘Žπ‘› = π‘Žπ‘›βˆ’1 + 4 First order, non-homogeneous
e) π‘Žπ‘› = 5π‘Žπ‘›βˆ’1 βˆ’ 4π‘Žπ‘›βˆ’2 + 𝑛2 Second order, non-homogeneous.
Your turn:
What is the order of the following recurrence relations? Are they homogeneous or non-
homogeneous?
a) π‘Žπ‘› = 3π‘Žπ‘›βˆ’1 + π‘Žπ‘›βˆ’2 + π‘Žπ‘›βˆ’4
b) π‘Žπ‘› = 5π‘Žπ‘›βˆ’1 βˆ’ 3π‘Žπ‘›βˆ’2 βˆ’ 1
Second Order Linear Homogeneous Recurrence Relations
Let
π‘Žπ‘› = 𝑐1π‘Žπ‘›βˆ’1 + 𝑐2π‘Žπ‘›βˆ’2
Be a second order, linear homogeneous recurrence relation with constant coefficients.
If 𝑆and 𝑇are solutions, then π‘ˆ = 𝑏𝑆 + 𝑑𝑇is also a solution of *.
If π‘Ÿ is a root of the characteristic (or auxiliary) equation defined as:
𝑑2 βˆ’ 𝑐1𝑑 βˆ’ 𝑐2 = 0
Then the sequence π‘Ÿπ‘›, 𝑛 = 0,1, …is a solution. If π‘Ž is the sequence defined by *,
π‘Ž0 = 𝐢0, π‘Ž1 = 𝐢1
And π‘Ÿ1 and π‘Ÿ2 are roots of * with π‘Ÿ1 β‰  π‘Ÿ2, then there exist constants 𝑏 and 𝑑 such that
π‘Žπ‘› = π‘π‘Ÿ1
𝑛 + π‘‘π‘Ÿ2
𝑛
This is called the general solution.
Given a set of initial conditions, finding the values of 𝑏 and 𝑑 result in the particular solution.
Worked Example:
What is the general and particular solutions to the recurrence relation π‘Žπ‘› = 7π‘Žπ‘›βˆ’1 βˆ’ 12π‘Žπ‘›βˆ’2 with
initial conditions π‘Ž1 = 1 and π‘Ž2 = 4?
Rearranging gives:
Therefore, the characteristic solution is:
𝑑2 βˆ’ 7𝑑 + 12 = 0
This can be factorised as
(𝑑 βˆ’ 4)(𝑑 βˆ’ 3) = 0
And has solutions 𝑑 = 4and 𝑑 = 3. Therefore, the general solution is
π‘Žπ‘› = 𝑏 Γ— 4𝑛 + 𝑑 Γ— 3𝑛
Substituting the first two values in π‘Ž1 = 1 and π‘Ž2 = 4 gives
π‘Ž1: 1 = 4𝑏 + 3𝑑
Document Page
π‘Ž2: 4 = 16𝑏 + 9𝑑
Solving these simultaneous equations gives the solution 𝑏 =1
4 and 𝑑 = 0.
Therefore, the particular solution is π‘Žπ‘› = 1
4 Γ— 4𝑛 + 0 Γ— 3𝑛 = 1
4 Γ— 4𝑛 or π‘Žπ‘› = 4π‘›βˆ’1
Your turn:
What is the general and particular solutions to the recurrence relation π‘Žπ‘› = 7π‘Žπ‘›βˆ’1 βˆ’ 12π‘Žπ‘›βˆ’2 with
initial conditions π‘Ž1 = 1 and π‘Ž2 = 3
Application: Fibonacci and Lucas Recurrence Relations
The relation
𝑓𝑛 = π‘“π‘›βˆ’1 + π‘“π‘›βˆ’2
Can be rewritten as 𝑓𝑛 βˆ’ π‘“π‘›βˆ’1 βˆ’ π‘“π‘›βˆ’2, 𝑛 β‰₯ 3and initial conditions 𝑓1 = 1, 𝑓2 = 1.
We begin by using the quadratic formula to solve
𝑑2 βˆ’ 𝑑 βˆ’ 1 = 0
The solution of this quadratic is 𝑑 =1±√5
2
𝑑 =1 ±√5
2
Thus, the general solution is:
𝑓𝑛 = 𝑏( 1 +√5
2 )
𝑛
+ 𝑑( 1 βˆ’βˆš5
2 )
𝑛
To find the particular solution:
𝑓𝑛 = 𝑏( 1 +√5
2 )
𝑛
+ 𝑑( 1 βˆ’βˆš5
2 )
𝑛
To satisfy the initial conditions, we must have
𝑏( 1 +√5
2 ) + 𝑑( 1 βˆ’βˆš5
2 ) = 1
And
𝑏( 1 +√5
2 )
2
+ 𝑑( 1 βˆ’βˆš5
2 )
2
= 1
𝑓𝑛 = 𝑏( 1 +√5
2 )
𝑛
+ 𝑑( 1 βˆ’βˆš5
2 )
𝑛
Using the initial conditions and the first term of the sequence, we have:
Document Page
𝑓1 = 1 β‡’ 𝑏( 1 +√5
2 ) + 𝑑( 1 βˆ’βˆš5
2 ) = 1
Which results in:
𝑏(1 + √5) + 𝑑(1 βˆ’ √5) = 2
Taking the second term in the sequence.
𝑓2 = 1 β‡’ 𝑏( 1 +√5
2 )
2
+ 𝑑( 1 βˆ’βˆš5
2 )
2
= 1
Which results in:
𝑏(3 + √5) + 𝑑(3 βˆ’ √5) = 2
We then have the system of equations:
𝑏(1 + √5) + 𝑑(1 βˆ’ √5) = 2
𝑏(3 + √5) + 𝑑(3 βˆ’ √5) = 2
Which can be solved simultaneously for 𝑏 and 𝑑, to obtain
𝑏 = 1
√5, 𝑑 = βˆ’
1
√5
Therefore, the particular solution is:
𝑓𝑛 = 1
√5( 1 +√5
2 )
𝑛
βˆ’ 1
√5( 1 βˆ’βˆš5
2 )
𝑛
Surprisingly, even though 𝑓𝑛 is an integer, the formula involves the irrational number √5.
The number 1+√5
2 which is called the golden ratio, πœ™ = 1+√5
2 and has the property 1
πœ™ = πœ™ βˆ’ 1.
The Fibonacci sequence is fascinating and has many interesting properties.
The first eight Fibonacci numbers is then
1, 1, 2, 3, 5, 8, 13, 21, …
If we sum these, we get
1, 2, 4, 7, 12, 20, 𝑒𝑑𝑐
These look like they are one less than term two ahead, I,e,
𝑓1 + 𝑓2 + β‹― + 𝑓𝑛 = 𝑓𝑛+2 βˆ’ 1
We can prove this by mathematical induction:
Let 𝑃(𝑛): 𝑓1 + 𝑓2 + β‹― + 𝑓𝑛 = 𝑓𝑛+2 βˆ’ 1
Then,
𝑓1 = 1, 𝑓3 βˆ’ 1 = 2 βˆ’ 1 = 1
So, 𝑃(1)is true.
Assuming 𝑃(π‘˜): 𝑓1 + 𝑓2 + β‹― + π‘“π‘˜ = π‘“π‘˜+2 βˆ’ 1is true, then
𝑃(π‘˜ + 1): 𝑓1 + 𝑓2 + β‹― + π‘“π‘˜ + π‘“π‘˜+1 = π‘“π‘˜+3 βˆ’ 1
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Now, as 𝑃(π‘˜)is true
π‘“π‘˜+2 βˆ’ 1 + π‘“π‘˜+1 = π‘“π‘˜+3 βˆ’ 1
As π‘“π‘˜+1 + π‘“π‘˜+2 = π‘“π‘˜+3 by definition. Therefore 𝑃(π‘˜ + 1)is true. Therefore, by mathematical induction, as
𝑃(π‘˜) β†’ 𝑃(π‘˜ + 1)is true and 𝑃(1)is true, then
𝑓1 + 𝑓2 + β‹― + 𝑓𝑛 = 𝑓𝑛+2 βˆ’ 1
Extension Topic: General Homogeneous Recurrence Relations
This section is not examinable.
So far, we have only considered recurrence relations whose characteristic equation results in two distinct
solutions. Sometimes when solving a quadratic equation, you might get a repeated solution or no real
solution. We will consider here those types of recurrence relations.
If we have repeated (equal) roots of the characteristic equation, we have to make a slight modification as can
be seen in the following example.
To solve the recurrence relation π‘Žπ‘› = 6π‘Žπ‘›βˆ’1 βˆ’ 9π‘₯π‘›βˆ’2, we first look at the characteristic equation π‘š2 βˆ’
6π‘š + 9 = 0which factorises to (π‘š βˆ’ 3)(π‘š βˆ’ 3) = 0 with the solution π‘š = 3. Therefore, the general
solution would look like π‘Žπ‘› = 𝐴 Γ— 3𝑛 where normally we would expect two solutions for a second order
recurrence relation. If we consider the expression π‘Žπ‘› = 𝑛 Γ— 3𝑛, then π‘Žπ‘›βˆ’1 = (𝑛 βˆ’ 1) Γ— 3π‘›βˆ’1 and π‘Žπ‘›βˆ’2 =
(𝑛 βˆ’ 2) Γ— 3π‘›βˆ’2. Substituting these into the recurrence relation, we have:
𝐿𝐻𝑆 = 𝑛 Γ— 3𝑛
𝑅𝐻𝑆 = 6(𝑛 βˆ’ 1) Γ— 3π‘›βˆ’1 + 18 Γ— 3π‘›βˆ’2
= 6𝑛 Γ— 3π‘›βˆ’1 βˆ’ 9𝑛 Γ— 3π‘›βˆ’2 βˆ’ 6 Γ— 3π‘›βˆ’1 + 18 Γ— 3π‘›βˆ’2
= 2𝑛 Γ— 3𝑛 βˆ’ 𝑛 Γ— 3𝑛 = 𝑛 Γ— 3𝑛 = 𝐿𝐻𝑆
Therefore, the left- and right-hand sides are equal and 𝑛 Γ— 3𝑛 is also a solution to the recurrence relation.
The general solution is then
π‘Žπ‘› = 𝐴 Γ— 3𝑛 + 𝐡𝑛 Γ— 3𝑛
In general, we can show that if there is only one root (in reality two repeated roots) π‘š of the auxiliary
equation, the general equation is then:
π‘Žπ‘› = π΄π‘šπ‘› + π΅π‘›π‘šπ‘› = (𝐴 + 𝐡𝑛)π‘šπ‘›
In our example above, the general solution is π‘Žπ‘› = (𝐴 + 𝐡𝑛)3𝑛.
We will use a second example to help illustrate how to solve recurrence relations when there are no real
roots. If we consider finding the general solution π‘Žπ‘› = βˆ’3π‘Žπ‘›βˆ’2, 𝑛 β‰₯ 2and then the particular solution when
π‘Ž0 = 1 and π‘Ž1 = 2. The characteristic equation is 𝑑2 = βˆ’4which has complex solutions π‘š = 2𝑖and π‘š =
βˆ’2𝑖. The general solution is then:
π‘Žπ‘› = 𝐴(βˆ’2)𝑖𝑛 + 𝐡(2𝑖)𝑛
Now, as π‘Ž0 = 1 and π‘Ž1 = 2, π‘Ž0 = 𝐴 + 𝐡 = 1and π‘Ž1 = βˆ’2𝑖𝐴 + 2𝑖𝐡 = 2 β‡’ βˆ’π΄ + 𝑏 = βˆ’π‘–. Solving these
simultaneously for 𝐴and 𝐡 gives:
𝐴 =1
2(1 + 𝑖)
𝐡 =1
2(1 βˆ’ 𝑖)
Document Page
The particular solution is π‘Žπ‘› = 1
2 (1 + 𝑖)(βˆ’2𝑖)𝑛 + 1
2 (1 βˆ’ 𝑖)(2𝑖)𝑛.
Extension Topic: Non-homogeneous Recurrence Relations
Non-homogeneous recurrence relations are more difficult to generally solve than that of homogeneous
relations. There is no completely systematic way to solve these but sometimes a form can be suggested.
For example, taking the recurrence relation π‘Žπ‘› + 3π‘Žπ‘›βˆ’1 + 2π‘Žπ‘›βˆ’2 = 𝑛2.
Firstly, we take the homogeneous part of the relation π‘Žπ‘› + 3π‘Žπ‘›βˆ’1 + 2π‘Žπ‘›βˆ’2 = 0 whose characteristic
equation is
π‘₯2 + 3π‘₯ + 2 = 0
Factorising gives:
(π‘₯ + 2)(π‘₯ + 1) = 0
Giving solutions π‘₯ = βˆ’1and π‘₯ = βˆ’2which are the roots of the characteristic equation. This gives us the
solution to the homogeneous part in the form
π‘Žπ‘› = 𝐴(βˆ’1)𝑛 + 𝐡(βˆ’2)𝑛
This is called the general solution.
As the righthand side is a quadratic, then we can form the particular solution as
π‘Žπ‘› = 𝐢𝑛2 + 𝐷𝑛 + 𝐸
Where we need to find what 𝐢, 𝐷and 𝐸are to obtain the particular solution. We may do this by substituting
this into our recurrence relation with 𝑖 = 𝑛, 𝑛 βˆ’ 1, 𝑛 βˆ’ 2:
(𝐢𝑛2 + 𝐷𝑛 + 𝐸) + 3(𝐢(𝑛 βˆ’ 1)2 + 𝐷(𝑛 βˆ’ 1) + 𝐸) + 2(𝐢(𝑛 βˆ’ 2) + 𝐷(𝑛 βˆ’ 2) + 𝐸) = 𝑛2
Simplifying we get:
6𝐢𝑛2 + (βˆ’14𝐢 + 6𝐷)𝑛 +(11𝐢 βˆ’ 7𝐷 + 6𝐸) = 1𝑛2 + 0𝑛 + 0
We can then equate coefficients:
6𝐢 = 1, = 14𝐢 + 6𝐷 = 0, 11𝐢 βˆ’ 7𝐷 + 6𝐸 = 0
Solving these three equations, we get 𝐢 =1
6 , 𝐷 =
14
36 and 𝐸 = 32/216. Hence the general solution is:
π‘Žπ‘› = 1
6𝑛2 + 14
36𝑛 + 32
216+ 𝐴(βˆ’1)𝑛 + 𝐡(βˆ’2)𝑛
And finally, 𝐴and 𝐡 may be found if the initial conditions are known, as before.
chevron_up_icon
1 out of 20
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]