Recurrence Relations - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Recurrence Relations

Description:

a way to solve the recurrence relation to obtain explicit or closed-form values for an ... A recurrence relation for a sequence an is an equation that expresses an in ... – PowerPoint PPT presentation

Number of Views:117
Avg rating:3.0/5.0
Slides: 19
Provided by: VasileiosH9
Category:

less

Transcript and Presenter's Notes

Title: Recurrence Relations


1
Recurrence Relations
  • Vasileios Hatzivassiloglou
  • University of Texas at Dallas

2
Recurrence relations
  • Often, we cannot find an directly, but we can
    tell how much an grows, i.e., relate an to a
    fixed number of earlier values an-1, an-2, ...
  • To find an, we need
  • a mathematical expression for this recurrence
    relation
  • initial values for a0, a1, ... (how many?)
  • a way to solve the recurrence relation to obtain
    explicit or closed-form values for an

3
Definitions
  • A recurrence relation for a sequence an is an
    equation that expresses an in terms of one or
    more of the previous terms in the sequence,
    namely a0, a1, ..., an-1 for all integers nn0,
    where n0 is a non-negative integer
  • A sequence is a solution for a recurrence
    relation if its terms satisfy the recurrence
    relation for all nn0

4
Example recurrence
  • Recurrence an an-1 an-2 for n2
  • If a03 and a16, then
  • a2 6 3 3
  • a3 3 6 -3
  • a4 -3 3 -6
  • We can similarly generate all other an values

5
Recurrence solutions
  • an 2an-1 an-2 for n2
  • Is an 3n a solution?
  • 3n ? 23(n-1) 3(n-2) 6n-6-3n6 3n YES
  • Is an 2n a solution?
  • 2n ? 22n-1 2n-2 2(1/2)2n (1/4)2n
    (3/4)2n NO
  • Is an 7 a solution?
  • 7 ? 27 7 7 YES

6
Example compound interest
  • Suppose you deposit P0 dollars in a savings
    account with a fixed interest rate of 5. How
    much money do you have after n years? (assume no
    withdrawals and no taxes)
  • Pn Pn-1 5 of Pn-1 Pn-1 0.05 Pn-1 1.05
    Pn-1
  • Pn 1.05 (1.05 Pn-2) 1.05 (1.05 (1.05 Pn-3))
    ... 1.05n P0

7
Bit string example
  • Suppose we know previous values of an
  • Then, among strings of length n,
  • If the final bit is 1, all legal strings will
    also be legal strings for the first n-1 bits
    (an-1 of them) and vice versa
  • If the final bit is 0, then the next-to-last bit
    cannot be 0, so the legal strings are the legal
    strings of length n-2 (an-2 of them) plus the two
    bits 10

8
Bit string recurrence
  • an an-1 an-2 for n3
  • For n1,
  • all two strings (0 and 1), so a12
  • For n2,
  • three of the four strings (01, 10, 11) are
    valid while 00 is not, so a23

9
Rabbit example
  • Let rn be the number of rabbit pairs in month n
  • rn (rabbit pairs in month n-1) (new rabbit
    pairs this month)
  • new rabbit pairs as many pairs as we had two
    months ago (those are reproducing)
  • rn rn-1rn-2
  • r1 1, r2 1 (no rabbits old enough to
    reproduce)
  • This sequence is the Fibonacci numbers

10
The Towers of Hanoi
  • A nineteen century puzzle created by a French
    mathematician
  • There are three pegs and n disks of different
    size. The disk are placed in order of size on the
    first peg, with the largest disk at the bottom.
    Disks can be moved one at a time to an empty peg
    or on top of a larger disk
  • Goal Move all disks to another peg

11
Towers of Hanoi
  • Interactive version where you can move the disks
    around
  • http//wipos.p.lodz.pl/zylla/games/hf.html
  • Watch the full solution for any number of disks
  • http//www.cut-the-knot.org/recurrence/hanoi.shtml

12
Solving the ToH puzzle
  • We observe that at some point we will need to
    move the bottom (largest) disk
  • In order to do so, all other disks will need to
    be off the original peg or the peg where the
    largest disk will go, i.e., on the third peg
  • Once this is achieved, we can move the largest
    disk and we can practically ignore it then move
    the remaining disks

13
Recursive solution
  • Solve (n, source, dest)
  • aux peg other than source and dest
  • Solve (n-1, source, aux)
  • Move (source, dest)
  • Solve (n-1, aux, dest)

14
Number of moves
  • For our proposed solution
  • Hn 2Hn-1 1, H1 1
  • Is this the only solution?
  • NO. For example, we can make extra moves of the
    top disks in any peg and back
  • Is there another solution with fewer moves?
  • NO because of the reasoning when we first
    presented the solution

15
Obtaining an explicit formula
  • Continuing the expansion,

16
Complexity of the ToH puzzle
  • Associated folklore stated that monks were
    actually working this puzzle in a tower in Hanoi
    using 64 gold disks, and the world would end when
    they solved it
  • How much time would that take?
  • H64 264-1 16260 16(210)6
    16(103)6161018 moves
  • If a move takes a second, about 500 billion years

17
Reading
  • Section 7.1 on recurrence relations

18
Review Questions
  • Find the terms a3 and a4 of the sequence an
    where an an-12 2an-2, a01, a11.
  • Which of the following sequences are solutions of
    the recurrence relation an 3an-1 4an-2? (a)
    an0 (b) an2 (c) an4n.
  • A colony of bacteria triples in size every hour.
    Find a recurrence relation for its size and the
    solution of this recurrence relation.
Write a Comment
User Comments (0)
About PowerShow.com