[go: up one dir, main page]

0% found this document useful (0 votes)
47 views28 pages

20 Recurrence Relations

Recurrence relations define sequences where subsequent terms are determined by preceding terms using a rule. The document provides examples of identifying and solving recurrence relations for arithmetic, polynomial, and geometric sequences. Initial conditions and verifying solutions using induction are also discussed.

Uploaded by

Wylson Almeida
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)
47 views28 pages

20 Recurrence Relations

Recurrence relations define sequences where subsequent terms are determined by preceding terms using a rule. The document provides examples of identifying and solving recurrence relations for arithmetic, polynomial, and geometric sequences. Initial conditions and verifying solutions using induction are also discussed.

Uploaded by

Wylson Almeida
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/ 28

Recurrence Relations

Niloufar Shafiei
Review
A recursive definition of a sequence specifies
 one or more initial terms
 a rule for determining subsequent terms
from those that precede them.

Example:
a0=3 a1=5 an= an-1 - an-2
a2 = a1 - a0 = 5 - 3 = 2

1
Review
 A rule to determining subsequent terms from those
that precede them is called a recurrence relation.

 The terms that precede the first term where the


recurrence relation takes effect are called initial
conditions.

 The recurrence relation and initial conditions uniquely


determine a sequence.

2
Recurrence relation
 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.

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

4
Example
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)

5
Example
Determine whether the sequence {an}, where an = 5 for
every nonnegative integer n, is a solution of the
recurrence relation an = 2an-1 - an-2 for n = 2,3,4,….
Assume a0=5 and a1=5.
Solution:
 Check initial conditions
a 0= 5 a1= 5
 Check if {5} satisfies an = 2an-1 - an-2
2an-1 - an-2 = 2(5) - 5 = 10 - 5 = 5 = an
 So, {5} is a solution for an = 2an-1 - an-2

6
Modeling with recurrence relations

Recurrence relations can be used to model a


wide variety of problems.

7
Solving recurrence relations
 Solving recurrence relations
 Guess a solution
 Do not make random guess, make educated guess
 Solving a recurrence often takes some creativity.
 If you are solving a recurrence and you have seen a
similar one before, then you might be able to use
the same technique.
 Verify your guess
 It is usually pretty easy if you guessed right.
 It is usually a straightforward argument using
mathematical induction
8
Example
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
9
Example
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
10
Example
Solution:
 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

11
Example
A young pair of rabbits 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.
Solution:
 Determine an
 an is “the number of pairs of rabbits after n months”.
 Find the recurrence relation that an satisfies and the initial condition
 a1 = 1 and a2 = 1
 The number of pairs after n months is equal to the number of rabbits
in the previous month plus the number of newborns (which is equal
to the number of pairs in two months ago)
 an = an-1 + an-2
12
Example (identifying arithmetic
sequences)
Find a Solution for the following recurrence. n a an-an-1
n
a0 = 12
0 12 -
a1 = 17
an = an/2 + an/2 - 12 1 17 5
Solution: 2 22 5
 Guess a solution (formula) for an 3 27 5
a0 = 12 a1 = 17 4 32 5
a2 = 17 + 17 - 12= 22
a3 = 17 + 22 - 12 = 27
a4 = 22 + 22 - 12 = 32
:
 To find a formula for an arithmetic sequence check the
differences of successive terms.
13
Example (identifying arithmetic
sequences)
Find a Solution for the following recurrence.
a0 = 12
a1 = 17
an = an/2 + an/2 - 12
Solution:
 So, an = 5n + d.
 Now we need to find d.
 a2 = 10 + d = 22, so d = 12.
 an = 5n + 12.
 Prove the solution using induction (exercise)

14
Example (identifying polynomial
sequences)
Find a Solution for the following recurrence.
a0 = 7
a1 = 12
an = an-2 + 8n - 2
Solution:
 Guess a solution (formula) for an
a0 = 7 a1 = 12
a2 = 7 + 16 - 2 = 21
a3 = 12 + 24 - 2 = 34
a4 = 21 + 32 - 2 = 51
a5 = 34 + 40 - 2 = 72
a6 = 51 + 48 - 2 = 97
:
15
Example (identifying polynomial
sequences)
Solution: :
 To find a formula for a polynomial sequence check the
differences of successive terms and then check the differences
of those and so on till you see that these differences form an
arithmetic sequence. n an bn = an-an-1 bn-bn-1
 So, an = bn + cn + d.
2
0 7 - -
a0 = d = 7
a1 = b + c + 7 = 12 1 12 5 -
a2 = 4b + 2c + 7 = 21 2 21 9 4
So, b=2 and c=3. 3 34 13 4
 an = 2n2 + 3n + 7 4 51 17 4
 Prove the solution using induction
5 72 21 4
(exercise)
6 97 25 4
16
Example (identifying geometric
sequences)
The Tower of Hanoi consists of 3 pegs mounted on a board
together with disks of different sizes.
Initially these disks are placed on the first peg in order of size,
with the largest on the bottom.
Disks can be moved one at a time from one peg to another as
long as a disk is never placed on top of a smaller disk.

17
Example (identifying geometric
sequences)
Goal: have all disks on the second peg in order of size, with
the largest on the bottom.
Hn is the required number of moves needed to solve the Tower
of Hanoi with n disks.
Find a recurrence relation and a solution for the sequence {Hn}.

18
Example (identifying geometric
sequences)
Solution:
 Hn is “the number of moves needed to solve the Tower of Hanoi with n disks”.
 Find the recurrence relation that Hn satisfies and the initial condition
 H1 = 1 (One disk can be transfer from peg 1 to peg 2 in one move.)
 Determine recurrence relation of Hn
 To transfer n disks from peg 1 to peg 2
 We use Hn-1 moves to transfer n-1 disks from peg 1 to peg 3
 We transfer the largest disk from peg 1 to peg 2 in one move
 Finally, we use Hn-1 moves to transfer n-1 disks from peg 3 to peg 2
 Hn = 2Hn-1 + 1
Since Hn-1 might not be the minimum number of moves, Hn  2Hn-1 + 1.
Hn = 2Hn-1 + 1 requires some additional proof.
(We do not go through this additional proof here.)

19
Example (identifying geometric
sequences)
Solution:
n Hn Hn/Hn-1
 Guess a solution (formula) for an
H1 = 1 11 -
H2 = 2H1 + 1 = 3 23 3
H3 = 2H2 + 1 = 7 37 2.33
H4 = 2H3 + 1 = 15
H5 = 2H4 + 1 = 31 4 15 2.14
: 5 31 2.06
 To find a formula for a geometric sequence check the ratios
between successive terms.
 So, Hn = x2n + y.
 H1 = 2x + y = 1
 H2 = 4x + y = 3
 So, x=1 and y=-1 and Hn = 2n - 1.

20
Example (identifying geometric
sequences)
Solution:
 Verify your guess using induction
 P(n) is Hn=2n - 1.
 Basis step:
H1 = 21 - 1 = 1
 Inductive step: (k (Hk  Hk+1))
Assume Hk = 2k - 1.
Hk+1 = 2Hk + 1 (by recurrence relation)
= 2(2k - 1) + 1 (by inductive hypothesis)
= 2k+1 - 1
 So, the solution is valid.

21
Example
Find a recurrence relation and initial conditions for the number of bit strings
of length n that do not have two consecutive 0s.
Solution:
 an is “the number of of bit strings of length n that do not have two
consecutive 0s”.
 Find the recurrence relation that an satisfies and the initial conditions
 Determine recurrence relation of an
 Bit strings of length n that do not have two consecutive 0s can
be constructed in two ways.
 Adding 1 to such bit strings of length n-1
 Adding 10 to such bit strings of length n-2
 an = an-1 + an-2
 a1 = 2 a2 = 3

22
Example
A computer system considers a string of decimal digits a valid
codeword if it contains an even number of 0 digits.
Let an be the number of valid n-digit codewords.
Find a recurrence relation for an.
Solution:
 Determine recurrence relation of an
 n-digit codewords can be constructed in two ways.
 Adding a digit other than 0 to (n-1)-digit codewords
 Adding 0 to a string of length n-1 that is not valid
 an = 9an-1 + (10n-1 - an-1)
 a1 = 9 a2 = 82

23
Example
Find a recurrence relation for Cn, the number of ways to
parenthesize the product of n+1 numbers x0, x1, …, xn, to
specify the order of multiplication.

For example:
C3 = 5 , because there are 5 ways to parenthesize x0, x1, x2, x3.
((x0 . x1) . x2) . x3 (x0 . (x1 . x2)) . x3 (x0 . x1) . (x2 . x3)
x0 . ((x1 . x2) . x3) x0 . (x1 . (x2 . X3))

24
Example
Find a recurrence relation for Cn, the number of ways to parenthesize
the product of n+1 numbers x0, x1, …, xn, to specify the order of
multiplication.
Solution:
 Determine recurrence relation of Cn
 Parenthesizing of multiplication of n+1 numbers can be
constructed in different ways.
 Parenthesizing of first number and parenthesizing n
numbers
 Parenthesizing of first two number and parenthesizing
n-1 numbers
 Parenthesizing of first three numbers and
parenthesizing n-2 numbers
 ….
25
Example
Find a recurrence relation for Cn, the number of ways to
parenthesize the product of n+1 numbers x0, x1, …, xn,
to specify the order of multiplication.
Solution:
 Cn = C0Cn-1 + C1Cn-2 + … + Cn-2C1 + Cn-1C0
n-1
 Cn =  CkCn-k-1
K=0

26
Recommended exercises
1,8,9,11,13,15,17,19,27,29,35

Eric Ruppert’s Notes about Solving Recurrences


(http://www.cse.yorku.ca/course_archive/2007-
08/F/1019/A/recurrence.pdf)

27

You might also like