Computational Problem Solving: Lecture Notes on Recurrence Relations
VerifiedAdded 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.

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
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
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

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:
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:

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.
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.
β This is a preview!β
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

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 π(π).
β’ 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 π(π).
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

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
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

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
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
β This is a preview!β
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

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
ππ = ππβ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
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

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π
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π

π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:
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:
β This is a preview!β
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

π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
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
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

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 β π)
ππ+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 β π)

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.
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.
β This is a preview!β
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 20
Your All-in-One AI-Powered Toolkit for Academic Success.
Β +13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright Β© 2020β2025 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.

