recurrence relations - york university3 recurrence relation a recurrence relation for the sequence...
TRANSCRIPT
1
Review
A recursive definition of a sequence specifies
one or more initial terms
a rule for determining subsequent termsfrom those that precede them.
Example:
a0=3 a1=5 an= an-1 - an-2
a2 = a1 - a0 = 5 - 3 = 2
2
Review
A rule to determining subsequent terms from thosethat precede them is called a recurrence relation.
The terms that precede the first term where therecurrence relation takes effect are called initial
conditions.
The recurrence relation and initial conditions uniquelydetermine a sequence.
3
Recurrence relation
A recurrence relation for the sequence {an} is anequation that expresses an in terms of one or more ofthe previous terms of the sequence, namely, a0, a1,…, an-1, for all integers n with n n0, where n0 is anonnegative integer.
A sequence is called a solution of a recurrencerelation if its terms satisfy the recurrence relation.
4
Example
Determine whether the sequence {an}, where an = 3n for everynonnegative integer n, is a solution of the recurrencerelation 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
5
Example
Determine whether the sequence {an}, where an = 2n for everynonnegative 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)
6
Example
Determine whether the sequence {an}, where an = 5 forevery nonnegative integer n, is a solution of therecurrence relation an = 2an-1 - an-2 for n = 2,3,4,….
Assume a0=5 and a1=5.
Solution:
Check initial conditions
a0= 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
7
Modeling with recurrence relations
Recurrence relations can be used to model awide variety of problems.
8
Solving recurrence relations
Solving recurrence relationsGuess 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 asimilar one before, then you might be able to usethe same technique.
Verify your guessIt is usually pretty easy if you guessed right.
It is usually a straightforward argument usingmathematical induction
9
Example
Suppose that a person deposits $10,000 in a savingsaccount at a bank yielding 11% per year with interestcompounded 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 theinitial condition
an = an-1 + (0.11) an-1 = (1.11) an-1
a0 = 10,000
10
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
11
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
12
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 eachmonth.
Find a recurrence relation for the number of pairs of rabbits on the islandafter 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 rabbitsin the previous month plus the number of newborns (which is equalto the number of pairs in two months ago)
an = an-1 + an-2
13
Example (identifying arithmeticsequences)
Find a Solution for the following recurrence.
a0 = 12
a1 = 17
an = a n/2 + a n/2 - 12
Solution:
Guess a solution (formula) for an
a0 = 12 a1 = 17
a2 = 17 + 17 - 12= 22
a3 = 17 + 22 - 12 = 27
a4 = 22 + 22 - 12 = 32
:
To find a formula for an arithmetic sequence check thedifferences of successive terms.
5324
5273
5222
5171
-120
an-an-1ann
14
Example (identifying arithmeticsequences)
Find a Solution for the following recurrence.
a0 = 12
a1 = 17
an = a n/2 + a n/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)
15
Example (identifying polynomialsequences)
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
:
16
Example (identifying polynomialsequences)
Solution: :
To find a formula for a polynomial sequence check thedifferences of successive terms and then check the differencesof those and so on till you see that these differences form anarithmetic sequence.
So, an = bn2 + cn + d.
a0 = d = 7
a1 = b + c + 7 = 12
a2 = 4b + 2c + 7 = 21
So, b=2 and c=3.
an = 2n2 + 3n + 7
Prove the solution using induction
(exercise)425976
421725
4
4
4
-
-
bn-bn-1
17514
13343
9212
5121
-70
bn = an-an-1ann
17
Example (identifying geometricsequences)
The Tower of Hanoi consists of 3 pegs mounted on a boardtogether 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 aslong as a disk is never placed on top of a smaller disk.
18
Example (identifying geometricsequences)
Goal: have all disks on the second peg in order of size, withthe largest on the bottom.
Hn is the required number of moves needed to solve the Towerof Hanoi with n disks.
Find a recurrence relation and a solution for the sequence {Hn}.
19
Example (identifying geometricsequences)
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.)
20
Example (identifying geometricsequences)
Solution:
Guess a solution (formula) for an
H1 = 1
H2 = 2H1 + 1 = 3
H3 = 2H2 + 1 = 7
H4 = 2H3 + 1 = 15
H5 = 2H4 + 1 = 31
:
To find a formula for a geometric sequence check the ratiosbetween successive terms.
So, Hn = x2n + y.
H1 = 2x + y = 1
H2 = 4x + y = 3
So, x=1 and y=-1 and Hn = 2n - 1.
2.06315
2.14154
2.3373
332
-11
Hn/Hn-1Hnn
21
Example (identifying geometricsequences)
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.
22
Example
Find a recurrence relation and initial conditions for the number of bit stringsof 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 twoconsecutive 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 canbe 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
23
Example
A computer system considers a string of decimal digits a validcodeword 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
24
Example
Find a recurrence relation for Cn, the number of ways toparenthesize the product of n+1 numbers x0, x1, …, xn, tospecify 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))
25
Example
Find a recurrence relation for Cn, the number of ways to parenthesizethe product of n+1 numbers x0, x1, …, xn, to specify the order ofmultiplication.
Solution:
Determine recurrence relation of Cn
Parenthesizing of multiplication of n+1 numbers can beconstructed in different ways.
Parenthesizing of first number and parenthesizing nnumbers
Parenthesizing of first two number and parenthesizingn-1 numbers
Parenthesizing of first three numbers andparenthesizing n-2 numbers
….
26
Example
Find a recurrence relation for Cn, the number of ways toparenthesize 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
Cn = CkCn-k-1
n-1
K=0