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