Вы находитесь на странице: 1из 72

Recurrence Relations

Learning Objectives
❑Learn about recurrence relations
❑Learn the relationship between sequences and
recurrence relations
❑Explore how to solve recurrence relations by
iteration
❑Learn about linear homogeneous recurrence
relations and how to solve them
❑Become familiar with linear nonhomogeneous
recurrence relations

Discrete Mathematical Structures: Theory and Applications 2


Sequences and Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 3


Sequences and Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 4


Sequences and Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 5


Sequences and Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 6


Sequences and Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 7


Sequences and Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 8


Sequences and Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 9


Sequences and Recurrence Relations
❑ Tower of Hanoi

❑In the nineteenth century, a game called the Tower of


Hanoi became popular in Europe. This game represents
work that is under way in the temple of Brahma.

❑There are three pegs, with one peg containing 64


golden disks. Each golden disk is slightly smaller than
the disk below it.

❑The task is to move all


64 disks from the first
peg to the third peg.

Discrete Mathematical Structures: Theory and Applications 10


Sequences and Recurrence Relations

❑ The rules for moving the disks are as follows:


1. Only one disk can be moved at a time.
2. The removed disk must be placed on one of the
pegs.
3. A larger disk cannot be placed on top of a smaller
disk.
❑ The objective is to determine the minimum
number of moves required to transfer the disks
from the first peg to the third peg.

Discrete Mathematical Structures: Theory and Applications 11


Sequences and Recurrence Relations
❑First consider the case in which the first peg
contains only one disk.
❑The disk can be moved directly from peg 1 to peg
3.
❑Consider the case in which the first peg contains
two disks.
❑First move the first disk from peg 1 to peg 2.
❑Then move the second disk from peg 1 to peg 3.
❑Finally, move the first disk from peg 2 to peg 3.

Discrete Mathematical Structures: Theory and Applications 12


Sequences and Recurrence Relations
❑ Consider the case in which the first peg contains three
disks and then generalize this to the case of 64 disks
(in fact, to an arbitrary number of disks).

❑Suppose that peg 1 contains three disks. To move disk


number 3 to peg 3, the top two disks must first be
moved to peg 2. Disk number 3 can then be moved
from peg 1 to peg 3. To move the top two disks from
peg 2 to peg 3, use the same strategy as before. This
time use peg 1 as the intermediate peg.

❑Figure 8.2 shows a solution to the Tower of Hanoi


problem with three disks.

Discrete Mathematical Structures: Theory and Applications 13


Discrete Mathematical Structures: Theory and Applications 14
❑ Generalize this problem to the case of 64 disks. To begin, the
first peg contains all 64 disks. Disk number 64 cannot be
moved from peg 1 to peg 3 unless the top 63 disks are on the
second peg. So first move the top 63 disks from peg 1 to peg
2, and then move disk number 64 from peg 1 to peg 3. Now the
top 63 disks are all on peg 2.
❑ To move disk number 63 from peg 2 to peg 3, first move the
top 62 disks from peg 2 to peg 1, and then move disk number
63 from peg 2 to peg 3. To move the remaining 62 disks, follow
a similar procedure.
❑ In general, let peg 1 contain n ≥ 1 disks.
1. Move the top n − 1 disks from peg 1 to peg 2 using peg 3 as the
intermediate peg.
2. Move disk number n from peg 1 to peg 3.
3. Move the top n − 1 disks from peg 2 to peg 3 using peg 1 as the
intermediate peg.
Discrete Mathematical Structures: Theory and Applications 15
Sequences and Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 16


Sequences and Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 17


Discrete Mathematical Structures: Theory and Applications 18
Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 19


Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 20


Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 21


Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 22


Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 23


Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 24


Discrete Mathematical Structures: Theory and Applications 25
Discrete Mathematical Structures: Theory and Applications 26
Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 27


Discrete Mathematical Structures: Theory and Applications 28
Discrete Mathematical Structures: Theory and Applications 29
Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 30


Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 31


Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 32


Linear Homogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 33


Linear Nonhomogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 34


Linear Nonhomogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 35


Linear Nonhomogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 36


Linear Nonhomogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 37


Discrete Mathematical Structures: Theory and Applications 38
Linear Nonhomogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 39


Linear Nonhomogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 40


Discrete Mathematical Structures: Theory and Applications 41
Discrete Mathematical Structures: Theory and Applications 42
Linear Nonhomogenous Recurrence Relations

Discrete Mathematical Structures: Theory and Applications 43


❑ Remark 8.3.14
❑ There are two ways to solve a linear nonhomogeneous equation of
the form

with some given initial conditions.


1. First find a particular solution and then add the particular
solution to a solution of the associated linear
homogeneous recurrence relation.
2. First obtain a linear homogeneous recurrence relation
from the given linear nonhomogeneous recurrence
relation, as shown in this section. Then a solution of the
given linear nonhomogeneous recurrence relation is also
a solution of the linear homogeneous equation obtained.
Next find a solution of the homogeneous recurrence
relation and use the initial conditions of the
nonhomogeneous recurrence solution to find the
constants. Finally, verify that the solution obtained
satisfies the linear nonhomogeneous recurrence relation.
Discrete Mathematical Structures: Theory and Applications 44
1. Generating functions for basic sequences
2. Operations on generating functions
3. Solve recurrences
Generating Functions

a sequence of numbers a function

a polynomial

Through this mapping, we can apply our techniques for manipulating functions.

1. Generating functions for basic sequences


2. Operations on generating functions
3. Solve recurrences
Ordinary Generating Functions

Given a sequence <g0,g1,g2,g3,………>

the ordinary generating function is:

We use a double sided arrow to indicate the correspondence.


Simple Examples

The pattern here is simple:


the i-th term in the sequence (indexing from 0) is the
coefficient of xi in the generating function.

What is the generating function for <1,1,1,1,1,1,1,………………………>?


Geometric Series

Gn ::= 1+ x + x2 + …… + xn-1 + xn + ……
What is the closed form expression of Gn?

Gn ::= 1+ x + x2 + ……
+ xn-1 + xn + ……

xGn = x + x2 + x3 + …… +xn + xn+1 + ……

Gn−xGn= 1

1-x n+1
Gn =
1-x
More Examples

These are all closed form generating functions.


1. Generating functions for basic sequences
2. Operations on generating functions
3. Solve recurrences
Operations on Generating Functions

manipulations on sequences manipulations on functions

There are a few basic operations we’ll learn.

1. Scaling
2. Addition
3. Right shift
4. Differentiation
5. Product

We can use these operations to get new sequences from known sequences,

and new generating functions from known generating functions.


Scaling

Multiplying a generating function by a constant


=> scales every term in the associated sequence by the same constant.

Multiply the generating function by 2 gives

which generates the sequence:


Addition

Adding generating functions corresponds to adding sequences term by term.

The same result as in the previous slide.


Right Shift

How to generate the sequence <0, 0, …, 0, 1, 1, 1, 1, 1…>?

k zeros

k zeros

Adding k zeros  multiplying xk on the generating function.


Differentiation

How to generate the sequence <1, 2, 3, 4, 5, …>?

The generating function is

How to obtain a closed form of this function?

We found a generating function for the sequence <1,2,3,…> of positive integers!


More Differentiation

How to generate the sequence <1, 4, 9, 16, 25, …>?

Nice idea. But not what we want.


More Differentiation

How to generate the sequence <1, 4, 9, 16, 25, …>?


Product

What is the sequence corresponds to the polynomial C(x) = A(x)B(x)?


1. Generating functions for basic sequences
2. Operations on generating functions
3. Solve recurrences
Solving Recurrences with Generating Functions

The Rabbit Population

• A mature boy/girl rabbit pair reproduces every month.


• Rabbits mature after one month.

wn::= # newborn pairs after n months

rn::= # reproducing pairs after n months

• Start with a newborn pair: w0 =1, r0 = 0


Rabbit Populations

wn::= # newborn pairs after n months


rn::= # reproducing pairs after n months

r1 = 1

rn = rn-1 + wn-1

wn = rn-1 so

rn = rn-1 + rn-2

How many rabbits after n months?

It was Fibonacci who was studying rabbit population growth.


Fibonacci Sequence

The Fibonacci sequence we want to analyze is:

Define a generating function for this sequence:

Remember

First we want to obtain a closed form for R(x)


Generating Function for Rabbits

R(x)::= r0+r1x+r2 +r3 x 2 x +…


3

-xR(x) = - r0x-r1x -r2x -…


2 3

-x R(x) =
2 -r0x -r1x -…
2 3

0
Remember
Generating Function for Rabbits

R(x)::= r0+r1x+r2 +r3 x 2 x +…


3

-xR(x) = - r0x-r1x -r2x -…


2 3

-x R(x) =
2 -r0x -r1x -…
2 3

0 0 …
Generating Function for Rabbits

R(x)::= r0+r1x
-xR(x) = - r0x
-x R(x) =
2

R(x)-xR(x)-x R(x)
2 =
r0+r1x-r0x = x
Closed Form for R(x)

What is the closed form of rn?

So rn = coefficient of xn in R(x)
Closed Form for Coefficients

So rn = coefficient of xn in R(x)
Tower of Hanoi

Post #1 Post #2 Post #3

Move1,2(n)::= Move1,3(n-1);
big disk 12;
Move3,2(n-1)
http://www.mazeworks.com/hanoi/
Generating Function

sn::=# steps by Move1,2(n)


sn = 2sn-1 + 1

s0 = 0

The sequence we want to analyze is:

Define a generating function for this sequence:

First we want to obtain a closed form for S(x)


Generating Function

S(x)::= s0+ s1x+ s2x2 + s3x3+…


-2xS(x)= -2s0x-2s1x -2s2x -…
2 3

-x/(1-x)= -1¢x - 1¢x2 - 1¢x3-…


0 0 0 …

sn = 2sn-1 + 1
Closed Form for S(x)

S(x) - 2xS(x) - x/(1-x) = s0 = 0

What is the closed form of sn?

so sn = 2n - 1

Вам также может понравиться