You are on page 1of 52

 At the end of the lecture, the student must

be able to:
 Solve problems involving recurrence
relations.
 Understand Fibonacci recurrence
relations and second-order recurrence
relations
 A recurrence relation is an infinite sequence
a1, a2, a3,…, an,…
 in which the formula for the nth term an
depends on one or more preceding terms,
with a finite set of start-up values or initial
conditions.
 Example:
 Initial condition:
a0 = 1
 Recursive formula:
a n = 1 + 2a n-1 for n>1
 First few terms are:
1, 3, 7, 15, 31, 63, …
 Example:
 Initial conditions:
a0 = 1, a1 = 2
 Recursive formula:
a n = 3(a n-1 + a n-2) for n > 2
 First few terms are:
1, 2, 9, 33, 126, 477, 1809, 6858,…
 Example: Fibonacci sequence
 Initial conditions:
 f1 = 1, f2 = 2
 Recursive formula:
 f n+1 = f n-1 + f n for n > 3
 First few terms:
n 1 2 3 4 5 6 7 8 9 10 11
fn 1 2 3 5 8 13 21 34 55 89 144
 Example: Fibonacci sequence application
 The Fibonacci numbers occur in the sums
of "shallow" diagonals in Pascal's triangle
 Example: Fibonacci sequence application
 These numbers also give the solution to
certain enumerative problems.
 The most common such problem is that
of counting the number of compositions
of 1s and 2s that sum to a given total n:
there are Fn+1 ways to do this.
 For example F6 = 8 counts the eight
compositions:
 Example: Fibonacci sequence application
 The Fibonacci numbers can be found
among the set of binary strings
 The number of binary strings of length n
without consecutive 1s is the Fibonacci
number Fn+2.
 Out of the 16 binary strings of length 4,
there are F6 = 8 without consecutive 1s –
 they are 0000, 0001, 0010, 0100, 0101, 1000,
1001 and 1010.
 Example: Fibonacci sequence history
 Medieval mathematician and businessman
Fibonacci (Leonardo Pisano) posed the
following problem:
 How many pairs of rabbits will be
produced in a year, beginning with a
single pair, if in every month each pair
bears a new pair which becomes
productive from the second month on?
 Example: Fibonacci sequence history
 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ...
 This is an example of a recursive sequence,
obeying the simple rule that to calculate the
next term one simply sums the preceding
two:
F(1) = 1
F(2) = 1
F(n) = F(n – 1) + F(n – 2)
 Example: Fibonacci sequence geometrically
 Example: Catalan numbers
 Eugene Catalan Belgian mathematician,
1814-1894
 Catalan numbers are generated by the
formula:
Cn = C(2n,n) / (n+1) for n > 0
 The first few Catalan numbers are:
n 0 1 2 3 4 5 6 7 8 9 10 11

Cn 1 1 2 5 14 42 132 429 1430 4862 16796 58786


 Example: Catalan Numbers: applications
 The number of ways in which a polygon with n+2
sides can be cut into n triangles
 Example: Catalan Numbers: applications
 The number of ways in which parentheses can
be placed in a sequence of numbers, to be
multiplied two at a time

 The number of rooted trivalent trees with n+1


nodes
 Example: Catalan Numbers: applications
 Cn is the number of permutations of {1, ..., n}
that avoid the pattern 123 (or any of the other
patterns of length 3); that is, the number of
permutations with no three-term increasing
subsequence.
 For n = 3, these permutations are 132, 213,
231, 312 and 321.
 For n = 4, they are 1432, 2143, 2413, 2431,
3142, 3214, 3241, 3412, 3421, 4132, 4213,
4231, 4312 and 4321.
 Example: Catalan Numbers: applications
 The number of paths of length 2n
through an n by n grid that do not rise
above the main diagonal
 The number of nonisomorphic binary
trees with n vertices
 Example: Towers of Hanoi
 Long ago, a group of Hindu priests were charged
with the daunting task of moving 64 giant golden
disks stacked on a giant pole to a different pole.
 The great, superior being that ordered them to do
the task instructed them that upon completion of
the restacking, the temple would turn to dust and
the world would vanish (end of the world).
 The priests had to not only move ginormous golden
disks one at a time but, also never to place a bigger
disk on top of a smaller one..
 Example: Towers of Hanoi

 1 1
 2 1, 2, 1
 3 1, 2, 1, 3, 1, 2, 1
 4 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1
 Example: Towers of Hanoi
 Start with three pegs numbered 1, 2 and 3
mounted on a board, n disks of different sizes
with holes in their centers, placed in order of
increasing size from top to bottom.
 Object of the game: find the minimum number
of moves needed to have all n disks stacked in
the same order in peg number 3.
 Example: Towers of Hanoi
 Start with all disks stacked in peg 1 with
the smallest at the top and the largest
at the bottom.
 Use peg number 2 for intermediate
steps
 Only a disk of smaller diameter can be
placed on top of another disk
 Example: Towers of Hanoi
 Game ends when all disks are stacked in
peg number 3 in the same order they
were stored at the start in peg number 1.
 Is the minimum number of moves needed
the Catalan number C3 = 5?
 Example: Recurrence Relation for the
Towers of Hanoi
N No.Moves
 Given: T(1) = 1
1 1
 T(n) = 2 T( n-1 ) +1
2 3
3 7
4 15
5 31
 Exercise: Recurrence Relation for the
Towers of Hanoi
 Find the closed-form solution.
N Number of Moves
1 1
2 3
3 7
4 15
5 31
 Two main methods:
 Iteration
 Method for linear homogeneous
recurrence relations with constant
coefficients
 METHOD 1 Problem:
 Given a recursive expression with initial
conditions a0, a1
 try to express an without dependence on
previous terms.
 Example:
 an = 2an-1 for n > 1, with initial condition
a0 = 1
 Solution: an = 2n
 Example: Deer Population growth
 Deer population dn at time n
 Initial condition: d0 = 1000
 Increase from time n-1 to time n is 10%.
 Therefore the recursive function is
dn – dn-1 = 0.1dn-1
 dn = 1.1dn-1
 Solution: dn = 1000(1.1)n
 Example: Compound interest
 Given
 P = initial amount (principal)
 n = number of years
 r = annual interest rate
 A = amount of money at the end of n years
 At the end of:
 1 year: A = P + rP = P(1+r)
 2 years: A = P + rP(1+r) = P(1+r)2
 3 years: A = P + rP(1+r)2 = P(1+r)3
 Obtain the formula A = P (1 + r) n
 Method 2: Linear homogeneous recurrence
 Theorem: Given the second order linear
homogeneous recurrence relation with
constant coefficients
an = c1an-1 + c2an-2
 and initial conditions a0 = C0, a1 = C1
 If r is a root of t2 – c1t – c2 = 0, then the
sequence {rn}, n = 0, 1, 2,… is also a
solution.
 Case 1: Two different roots
 If r1 and r2 (r1  r2) are solutions of the
quadratic equation t2 – c1t – c2 = 0, then
there exist constants b and d such that
an = br1n + dr2n
 for n = 0, 1, 2, 3,…
 Case 2: One root of multiplicity 2
 If r is a root of multiplicity 2 satisfying the
equation
t2 – c1t – c2 = 0,
 then there exist constants b and d such that
an = brn + dnrn
 for n = 0, 1, 2, 3,…
 EXAMPLE: Solving Fibonacci
 Recipe solution has 3 basic steps:
 Assume solution of the form an = r n

 Find all possible r’s that seem to make this


work. Call these r1 and r2.
 Modify assumed solution to general solution
an = Ar1n +Br2n where A,B are constants.
 Use initial conditions to find A,B and obtain
specific solution.
 Solving Fibonacci
 Assume solution of the form an = r n :
 Plug this into an = an-1 + an-2 :
 r n = r n-1 + r n-2

 Notice that all three terms have a common rn-2


factor, so divide this out:
r n /r n-2 = (r n-1+r n-2 )/r n-2  r 2= r + 1
 This equation is called the characteristic equation
of the recurrence relation.
 Solving Fibonacci
 Find all possible r’s that solve the
characteristic equation r2 = r + 1
 Call these r1 and r2.
 Quadratic formula gives:
 r = (1  5)/2
 So r1 = (1+5)/2, r2 = (1-5)/2
 Solving Fibonacci
 General solution is
 an = Ar1n +Br2n
 where A,B are constants.
 General solution:
 an = A [(1+5)/2]n +B [(1-5)/2]n
 Solving Fibonacci
 an = A [(1+5)/2]n +B [(1-5)/2]n
 Use initial conditions a0 = 0, a1 = 1 to find A, B
and obtain specific solution.
 0=a0 = A [(1+5)/2]0 +B [(1-5)/2]0 = A +B
 1=a1 = A [(1+5)/2]1 +B [(1-5)/2]1
= A(1+5)/2 +B (1-5)/2
= (A+B )/2 + (A-B )5/2
 Solving Fibonacci
 First equation give B = -A.
 Plug into 2nd:
 1 = 0 +2A5/2
 so
 A = 1/5, B = -1/5
 Final answer:
n n
1  1  5  1  1  5 
an    
5 2  5  2 
 Linear Recurrences with Constant Coefficients:
 DEF: A recurrence relation is said to be linear if an
is a linear combination of the previous terms plus a
function of n. I.e. no squares, cubes or other
complicated function of the previous ai can occur. If
in addition all the coefficients are constants then
the recurrence relation is said to have constant
coefficients.
 Question: Which of the following are linear
with constant coefficients?
 an = 2an-1
 an = 2an-1 + 2n-3 - an-3
 an = an-12
 Answer:
 an = 2an-1 YES
 an = 2an-1 + 2n-3 - an-3 YES
 an = an-12 NO. Squaring is not a
linear operation.
 Similarly an = an-1an-2 and
an = cos(an-2) are non-linear.
 Homogeneous Linear Recurrences
 DEF: A linear recurrence relation is said to
be homogeneous if it is a linear combination
of the previous terms of the recurrence
without an additional function of n.
 Q: Which of the following are homogeneous?
 an = 2an-1
 an = 2an-1 + 2n-3 - an-3
 Answer:
 an = 2an-1: YES
 an = 2an-1 + 2n-3 - an-3: No. There’s an extra
term f (n) = 2n-3
 Example: Towers of Hanoi
 Long ago, a group of Hindu priests were charged
with the daunting task of moving 64 giant golden
disks stacked on a giant pole to a different pole.
 The great, superior being that ordered them to do
the task instructed them that upon completion of
the restacking, the temple would turn to dust and
the world would vanish (end of the world).
 The priests had to not only move ginormous golden
disks one at a time but, also never to place a bigger
disk on top of a smaller one..
 Towers of Hanoi
 it will take 2n - 1 moves
 that comes out to
18,446,744,073,709,551,615 moves!
 Assuming these priest worked in shifts around
the clock, 24 hours a day, 7 days a week, 365
days a year, making an astounding and doubtful
ONE MOVE PER SECOND, it would take them
over 580 BILLION years to pull it off . . . only
to be reduced to ashes at the end.
 Example: The Nonhomogeneous Case
 Consider the Tower of Hanoi recurrence
an = 2an-1+1.
 Could solve using telescoping. Instead let’s
solve it methodically. Rewrite:
an - 2an-1 = 1
 1. Solve the homogeneous case.
 2. Find the particular solution.
General General Particular
Nonhomogeneous
L20 = homogeneous
+ Nonhomogeneous 45
 Example: an - 2an-1 = 1
 1. Solve with the RHS set to 0, i.e. solve the
homogeneous case.
an - 2an-1 = 0
 Characteristic equation: r - 2 = 0
 So unique root is r = 2.
 General solution to homogeneous equation is
an = A·2n
 Example: an - 2an-1 = 1
 2. Add a particular solution to get general
solution. I.e. use rule:
 There are little tricks for guessing particular
nonhomogeneous solutions.
 For example, when the RHS is constant, the
guess should also be a constant.
 So guess a particular solution of the form an=C.
 Plug into the original recursion:
 C – 2C = 1.
 Therefore C = -1.
 Example: an - 2an-1 = 1
 3. Combine the homogeneous and particular
solution to get general solution.
 General solution: an = A·2n -1.
 4. Finally, use initial conditions to get closed
solution. In the case of the Towers of Hanoi
recursion, initial condition is a1 = 1.
 Using general solution an = A·2n -1 we get:
1 = A·21 -1
 Therefore, 2 = 2A, so A = 1.
 Final answer: an = 2n -1
 EXERCISE:
 1. Solve an = 2an-1-an-2 , a0 = 1, a1 = 2.
 2. Solve an = 2an-1+an-2 , a0 = 1, a1 = 2
EG: Solve an = 2an-1-an-2 , a0 = 1, a1 = 2
Find characteristic equation by plugging in an = r
n:

r 2 - 2r +1 = 0
Since r 2 - 2r +1 = (r -1)2 the root r = 1 repeats.
If we tried to solve by using general solution
an = Ar1n+Br2n = A1n+B1n = A+B
which forces an to be a constant function ().
SOLUTION: Multiply second solution by n so
L20
general solution looks like: 50
n n
Solve an = 2an-1-an-2, a0 = 1, a1 = 2
General solution: an = A1n+Bn1n = A+Bn
Plug into initial conditions
1 = a0 = A+B·0·10= A
2 = a0 = A·11+B·1·11= A+B
Plugging first equation A = 1 into second:
2 = 1+B implies B = 1.
Final answer: an = 1+n
(CHECK IT!)

L20 51

You might also like