0% found this document useful (0 votes)
166 views49 pages

Lecture 9 RECURRENCE RELATION

This document discusses recurrence relations and methods for solving them. It begins by defining a recurrence relation as a sequence where the nth term depends on preceding terms, using initial values. Examples are given including the Fibonacci sequence. Methods are presented for solving homogeneous linear recurrence relations with constant coefficients, including finding the characteristic polynomial and roots. The Towers of Hanoi problem is used to illustrate a recurrence relation solution.

Uploaded by

jovanni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views49 pages

Lecture 9 RECURRENCE RELATION

This document discusses recurrence relations and methods for solving them. It begins by defining a recurrence relation as a sequence where the nth term depends on preceding terms, using initial values. Examples are given including the Fibonacci sequence. Methods are presented for solving homogeneous linear recurrence relations with constant coefficients, including finding the characteristic polynomial and roots. The Towers of Hanoi problem is used to illustrate a recurrence relation solution.

Uploaded by

jovanni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 49

MATH140

RECURRENCE RELATION
OBJECTIVES
 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
RECURRENCE RELATION
 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.
RECURRENCE RELATION
 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, …
RECURRENCE RELATION
 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,…
RECURRENCE RELATION
 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
RECURRENCE RELATION
 Example: Fibonacci sequence application
 The Fibonacci numbers occur in the sums
of "shallow" diagonals in Pascal's triangle
RECURRENCE RELATION
 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:
RECURRENCE RELATION
 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.
RECURRENCE RELATION
 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?
RECURRENCE RELATION
 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)
RECURRENCE RELATION
 Example: Fibonacci sequence geometrically
1.6180339887
RECURRENCE RELATION
 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


RECURRENCE RELATION
 Example: Catalan Numbers: applications
 The number of ways in which a polygon with n+2
sides can be cut into n triangles
RECURRENCE RELATION
 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
RECURRENCE RELATION
 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.
RECURRENCE RELATION
 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
RECURRENCE RELATION
 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..
RECURRENCE RELATION
 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
RECURRENCE RELATION
 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.
RECURRENCE RELATION
 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
RECURRENCE RELATION
 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?
RECURRENCE RELATION
 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
RECURRENCE RELATION
 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
LINEAR RECURRENCE RELATIONS WITH
CONSTANT COEFFICIENTS
 A recurrence relation of order k is a function of the form

that is, where the nth term of a sequence is a function of the


preceding k terms , , . . . , (and
possibly n). In particular, a linear kth-order recurrence relation
with constant coefficients is a recurrence relation
of the form
LINEAR RECURRENCE RELATIONS WITH
CONSTANT COEFFICIENTS

 
Where , . . . , are constants with , and f (n) is a function of n.
The meanings of the names linear and constant coefficients
follow:

If f (n) = 0, then the relation is also said to be homogeneous.


LINEAR RECURRENCE RELATIONS WITH
CONSTANT COEFFICIENTS
Consider each of the following recurrence relations.
LINEAR RECURRENCE RELATIONS WITH
CONSTANT COEFFICIENTS
Consider each of the following recurrence relations.
SOLVING SECOND-ORDER HOMOGENEOUS LINEAR
RECURRENCE RELATIONS
SOLVING SECOND-ORDER HOMOGENEOUS LINEAR
RECURRENCE RELATIONS
SOLVING SECOND-ORDER HOMOGENEOUS LINEAR
RECURRENCE RELATIONS
SOLVING SECOND-ORDER HOMOGENEOUS LINEAR
RECURRENCE RELATIONS

 Trythis:
Consider the second-order homogeneous recurrence relation
with initial conditions , ,

(a) Find the next three terms of the sequence.

(b) Find the general solution.

(c) Find the unique solution with the given initial conditions.
SOLVING RECURRENCE RELATION
 Solving Fibonacci
 Consider the celebrated Fibonacci sequence:
SOLVING RECURRENCE RELATION
 Solving Fibonacci
 Consider the celebrated Fibonacci sequence:
Solution when Roots of the Characteristic
Polynomial are Equal
Solution when Roots of the Characteristic
Polynomial are Equal

Example: Consider the following homogeneous recurrence


relation:

Suppose we are also given the initial conditions


Solution when Roots of the Characteristic
Polynomial are Equal
RECURRENCE RELATION
 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..
RECURRENCE RELATION
 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.
RECURRENCE RELATION
 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 42
RECURRENCE RELATION
 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
RECURRENCE RELATION
 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.
RECURRENCE RELATION
 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
SOLVING RECURRENCE RELATION
 EXERCISE:
 1. Solve an = 2an-1-an-2 , a0 = 1, a1 = 2.
 2. Solve an = 2an-1+an-2 , a0 = 1, a1 = 2
RECURRENCE RELATION
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
general solution looks like:
L20
an = Ar1n+Bnr1n 47
RECURRENCE RELATION
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 48
PREPARATION FOR THE COURSE

You might also like