0% found this document useful (0 votes)
33 views30 pages

CHP4 P2

The document discusses recurrence relations and their applications. It defines recurrence relations and provides examples of solving linear recurrence relations using forward and backward substitution. Applications discussed include the Fibonacci sequence, modeling compound interest, modeling rabbit populations, and the Tower of Hanoi puzzle. Recurrence relations can be used to model many problems by breaking them down into sub-problems with the same form.
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)
33 views30 pages

CHP4 P2

The document discusses recurrence relations and their applications. It defines recurrence relations and provides examples of solving linear recurrence relations using forward and backward substitution. Applications discussed include the Fibonacci sequence, modeling compound interest, modeling rabbit populations, and the Tower of Hanoi puzzle. Recurrence relations can be used to model many problems by breaking them down into sub-problems with the same form.
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/ 30

Learning Outcome

 Analyze problem and propose solutions


 Solving problems using recurrence relation
Outline
 Recurrence Relations
 Applications of Recurrence Relations
 Solving Linear Recurrence Relations
 Homogeneous Recurrence Relations
 Non-homogeneous Recurrence Relations
Introduction
 Recurrence relations play an important roles in the
study of algorithms.
 Complex problem can be solved recursively means to
find a way to break it down into smaller sub-problems
 each sub-problem having the same form as the
original problem. When the process is repeated many
times, the last of the sub-problems are small and easy
to solve
 The solutions of the sub-problems can be woven
together to form a solution to the original problem.
Recurrence Relations
Definition: 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.
 The initial conditions for a sequence specify the terms
that precede the first term where the recurrence
relation takes effect.
Recurrence Relations
Example 1: Let {an} be a sequence that satisfies the
recurrence relation an = an-1 + 3 for n = 1,2,3,4,….
Suppose that a0 = 2.
What are a1 , a2 and a3?
[Here a0 = 2 is the initial condition.]

Solution: We see from the recurrence relation that


a1 = a0 + 3 = 2 + 3 = 5
a2 = 5 + 3 = 8
a3 = 8 + 3 = 11
Recurrence Relations
Example 2: Let {an} be a sequence that satisfies the
recurrence relation an = an-1 – an-2 for n = 2,3,4,….
Suppose that a0 = 3 and a1 = 5.
What are a2 and a3?
[Here the initial conditions are a0 = 3 and a1 = 5. ]

Solution: We see from the recurrence relation that


a2 = a1 - a0 = 5 – 3 = 2
a3 = a2 – a1 = 2 – 5 = –3
Fibonacci Sequence
Definition: Define the Fibonacci sequence, f0 ,f1 ,f2,…, by:
 Initial Conditions: f0 = 0, f1 = 1
 Recurrence Relation: fn = fn-1 + fn-2

Example: Find f2 , f3 , f4 , f5 and f6 .

Answer:
f2 = f1 + f0 = 1 + 0 = 1,
f3 = f2 + f1 = 1 + 1 = 2,
f4 = f3 + f2 = 2 + 1 = 3,
f5 = f4 + f3 = 3 + 2 = 5,
f6 = f5 + f4 = 5 + 3 = 8.
Exercise 1

Solution:
Exercise 2

Solution:
Solving Recurrence Relations
Finding a formula for the nth term of the sequence
generated by a recurrence relation is called solving the
recurrence relation.
1) Need to find the formula by using method of
iteration namely
 Forward substitution
 Backward substitution
2) Then, proving of the formula can be done by using
mathematical induction.
Iterative Method 1: Forward Substitution

Working upward,
Let {an} be a sequence that satisfies the recurrence relation
an = an-1 + 3 for n = 2,3,4,…. and suppose that a1 = 2.
a2 = 2 + 3
a3 = (2 + 3) + 3 = 2 + 3 ∙ 2
a4 = (2 + 2 ∙ 3) + 3 = 2 + 3 ∙ 3
.
.
.
an = an-1 + 3 = (2 + 3 ∙ (n – 2)) + 3 = 2 + 3(n – 1)
Iterative Method 2: Backward Substitution
Working downward,
Let {an} be a sequence that satisfies the recurrence relation an = an-1 + 3 for n =
2,3,4,….
Suppose that a1 = 2.
an = an-1 + 3
= (an-2 + 3) + 3 = an-2 + 3 ∙ 2
= (an-3 + 3 )+ 3 ∙ 2 = an-3 + 3 ∙ 3
= (an-4 + 3 )+ 3 ∙ 3 = an-4 + 3 ∙ 4
=(an-5 + 3 )+ 3 ∙ 4 = an-5 + 3 ∙ 5
=(an-6 + 3 )+ 3 ∙ 5 = an-6 + 3 ∙ 6
.
.
= a4 + 3(n – 4)
= a3 + 3(n – 3)
= a2 + 3(n – 2) = (a1 + 3) + 3(n – 2) = 2 + 3(n – 1)
Guessing Sequences
Example: Conjecture a simple formula for an if the first 10 terms
of the sequence {an} are 1, 7, 25, 79, 241, 727, 2185, 6559, 19681,
59047.
Solution:
1)The ratio of each term to the previous approximates 3.
2)Compare with the sequence 3n .
3)Notice that the nth term is 2 less than the corresponding
power of 3. So a good conjecture is that an = 3n − 2.
Some Useful Summation Formulae
Solving Recurrence Relations
Example: Let a0 , a1 , a2 , … be the sequence of a
recurrence relation defined as follows:
 For all integers k>1 ,
1. ak = ak-1 + 2
2. Initial condition: a0 = 1
Solve the recurrence relation by using iterative
method.
Activity 1: Solve the recurrence relation
by iteration
1.

2.

3.
Activity 1: Solution
1. 2.

3.
Modeling with Recurrence Relations
 Recurrence relation can be used to model a wide
variety of problems.
 Example:
 finding compound interest
 counting rabbits in an island
 determining the number of moves in the Tower of Hanoi
puzzle
 counting bit strings with certain properties.
Example: Financial Application
Suppose that a person deposits $10,000.00 in a savings account
at a bank yielding 11% per year with interest compounded
annually. How much will be in the account after 30 years?
Solution: Let Pn denote the amount in the account after 30
years. Pn satisfies the following recurrence relation:
Pn = Pn-1 + 0.11Pn-1 = (1.11) Pn-1 with P0 = 10,000

Using Forward Substitution


P1 = (1.11)P0
P2 = (1.11)P1 = (1.11)2P0
P3 = (1.11)P2 = (1.11)3P0
:
Pn = (1.11)Pn-1 = (1.11)nP0 = (1.11)n 10,000
Pn = (1.11)n 10,000 (Can prove by induction)
P30 = (1.11)30 10,000 = $228,992.97
Rabbits & Fibonacci Numbers
Example: A young pair of rabbits (one of each gender) is placed on an
island. A pair of rabbits does not breed until they are 2 months old.
After they are 2 months old, each pair of rabbits produces another pair each
month.
Find a recurrence relation for the number of pairs of rabbits on the island
after n months, assuming that rabbits never die.
(This is the original problem considered by Leonardo Pisano (Fibonacci) in
the thirteenth century.)
Rabbits & Fibonacci Numbers (cont.)
Solution: Let fn be the number of pairs of rabbits after n months.
fn-1 , n = 1,2,3,… are the terms of the Fibonacci sequence.

 f1 = 1 pairs of rabbits on the island at the end of the first month.


 f2 = 1 because the pair does not breed during the first month.
 To find the number of pairs on the island after n months, add the
number on the island after the previous month, fn-1, and the
number of newborn pairs, which equals fn-2, because each newborn
pair comes from a pair at least two months old.

Consequently the sequence {fn } satisfies the recurrence relation :


fn = fn-1 + fn-2 for n ≥ 3 with the initial conditions f1 = 1 and f2 = 1.
The number of pairs of rabbits on the island after n months is given by
the nth Fibonacci number.
Tower of Hanoi Puzzle
In the late 19th century, the French mathematician Édouard Lucas
invented a puzzle consisting of three pegs on a board with disks of
different sizes. Initially all of the disks are on the first peg in order of
size, with the largest on the bottom.

Initial Position

Rules: You are allowed to move the disks one at a time from one peg to
another as long as a larger disk is never placed on a smaller.
Goal: Using allowable moves, end up with all the disks on the second
peg in order of size with largest on the bottom.
Tower of Hanoi Puzzle
(continued)

Solution: Let {Hn} denote the number of moves needed to solve the Tower of Hanoi Puzzle
with n disks. Set up a recurrence relation for the sequence {Hn}. Begin with n disks on peg 1.
Transfer the top n −1 disks, following the rules of the puzzle, to peg 3 using Hn−1 moves.
Use 1 move to transfer the largest disk to the second peg. Then, transfer the n −1 disks from
peg 3 to peg 2 using Hn−1 additional moves. This can not be done in fewer steps.
Hence, Hn = 2Hn−1 + 1.
The initial condition is H1= 1 since a single disk can be transferred from peg 1 to peg 2 in one
move.
 Use an iterative approach to solve this recurrence relation by repeatedly expressing Hn in
terms of the previous terms of the sequence.
Hn = 2Hn−1 + 1
= 2(2Hn−2 + 1) + 1 = 22 Hn−2 +2 + 1
= 22(2Hn−3 + 1) + 2 + 1 = 23 Hn−3 +22 + 2 + 1

= 2n-1H1 + 2n−2 + 2n−3 + …. + 2 + 1
= 2n−1 + 2n−2 + 2n−3 + …. + 2 + 1 because H1= 1
= 2n − 1 using the formula for the sum of the terms of a geometric series
Counting Bit Strings
Example 4: Find a recurrence relation and give initial conditions for the number of bit
strings of length n without two consecutive 0s. How many such bit strings are there of length
five?
Solution: Let an denote the number of bit strings of length n without two consecutive 0s.
To obtain a recurrence relation for {an } note that the number of bit strings of length n that do
not have two consecutive 0s is the number of bit strings ending with a 0 plus the number of
such bit strings ending with a 1.

Assume that n ≥ 3.
 The bit strings of length n ending with 1 without two consecutive 0s are the bit strings of length
n −1 with no two consecutive 0s with a 1 at the end. Hence, there are an−1 such bit strings.
 The bit strings of length n ending with 0 without two consecutive 0s are the bit strings of length
n −2 with no two consecutive 0s with 10 at the end. Hence, there are an−2 such bit strings.
We conclude that an = an−1 + an−2 for n ≥ 3.
Bit Strings (continued)
The initial conditions are:
 a1 = 2, since both the bit strings 0 and 1 do not have consecutive 0s.
 a2 = 3, since the bit strings 01, 10, and 11 do not have consecutive 0s, while 00 does.

If the bit length is 5, ie. n=5, we need to obtain a5 . We use the recurrence relation three times to
find that:

 a3 = a2 + a1 = 3 + 2 = 5
 a4 = a3 + a2 = 5+ 3 = 8
 a5 = a4 + a3 = 8+ 5 = 13

Note that {an } satisfies the same recurrence relation as the Fibonacci
sequence. Since a1 = f3 and a2 = f4 , we conclude that an = fn+2 .
Counting the Ways to Parenthesize a
Product
Example: Find a recurrence relation for Cn , the number of ways to parenthesize the product of
n + 1 numbers, x0 ∙ x1 ∙ x2 ∙ ⋯ ∙ xn, to specify the order of multiplication.
For example, C3 = 5, since all the possible ways to parenthesize 4 numbers are

((x0 ∙ x1 )∙ x2 )∙ x3 , (x0 ∙ (x1 ∙ x2 ))∙ x3 , (x0 ∙ x1 )∙ (x2 ∙ x3 ), x0 ∙ (( x1 ∙ x2 ) ∙ x3 ), x0 ∙ ( x1 ∙ ( x2 ∙ x3 ))

Solution: Note that however parentheses are inserted in x0 ∙ x1 ∙ x2 ∙ ⋯ ∙ xn, one “∙” operator remains
outside all parentheses. This final operator appears between two of the n + 1 numbers, say xk and xk+1.
Since there are Ck ways to insert parentheses in the product x0 ∙ x1 ∙ x2 ∙ ⋯ ∙ xk and Cn−k−1 ways to insert
parentheses in the product xk+1 ∙ xk+2 ∙ ⋯ ∙ xn, we have

The initial conditions are C0 = 1 and C1 = 1.


The sequence {Cn } is the sequence of Catalan Numbers. This recurrence relation
can be solved using the method of generating functions; see Exercise 41 in Section
8.4 (Rosen’s book).

You might also like