9-AdvancedCounting -1 - PowerPoint PPT Presentation

About This Presentation
Title:

9-AdvancedCounting -1

Description:

For n 3, an= an-1 an-2-an-3; Initial conditions: a0=1, a1=3, a2=4. ... each determined uniquely by its own initial conditions. ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 17
Provided by: ics9
Learn more at: https://ics.uci.edu
Category:

less

Transcript and Presenter's Notes

Title: 9-AdvancedCounting -1


1
Recurrence Relations (RRs)
  • 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 (i.e.,
    a0,a1,a2,,an-1) for all nn0.
  • Examples
  • a01, a13, a24for n 3, an an-1an-2-an-3
  • 1,3,4,6,7,9,10,12,13,15,16,18,19,21,22,
  • a02, a14, a23for n 3, an an-1an-2-an-3
  • 2,4,3,5,4,6,5,7,6,8,7,9,8,10,9,11,
  • a04, a13, a23for n 3, an an-1an-2-an-3
  • 4,3,3,2,2,1,1,0,0,-1,-1,-2,-2,-3,-3,-4,-4,

2
Solutions to Recurrence Relations
  • A sequence an is called a solution of the
    recurrence relation if its terms satisfy the
    recurrence relation.
  • Examples
  • For n 3, an an-1an-2-an-3 Initial conditions
    a01, a13, a24.Solution 1,3,4,6,7,9,10,12,13,1
    5,16,18,19,21,22,
  • For n 3, an an-1an-2-an-3 Initial conditions
    a02, a14, a23. Solution 2,4,3,5,4,6,5,7,6,8,
    7,9,8,10,9,11,
  • For n 3, an an-1an-2-an-3 Initial conditions
    a04, a13, a23. Solution 4,3,3,2,2,1,1,0,0,-1,
    -1,-2,-2,-3,-3,-4,-4,
  • Every recurrence relationship has many solutions
    each determined uniquely by its own initial
    conditions.
  • We say a function fN?R is a solution to a
    recurrence relation if the sequence f(n) is a
    solution to it.Example f(n)5 2n is a solution
    to the recurrence relation an2an-1.

3
Solving Recurrence Relations
  • If an4an-1 and a03, find a function f such that
    f(n)an.
  • an4an-142an-243an-3...4na03?4n.
  • If anan-1n and a04, find a function f such
    that f(n)an.
  • anan-1nan-2n(n-1) an-2n(n-1)(n-2)...a0
    n(n-1)(n-2)...14n(n1)/2(n2n8)/2.
  • If an2nan-1 and a05, find a function f such
    that f(n)an.
  • an2nan-122n(n-1)an-223n(n-1)an-3...2nn!a05?
    2nn!.
  • If an2an-11 and a00, find a function f such
    that f(n)an.
  • an2an-1122an-22123an-342124an-48421
    ...2n-12n-22n-3...84212n-1.

4
Modeling with Recurrence Relations
  • An initial deposit of P0 dollars deposited at 7
    annual interest.
  • Pn(10.07)Pn-1 is the value after n years.
    Pn(10.07)nP0
  • Rabbits on an island. Each pair producing a new
    pair every month.
  • Fibonacci Numbers f00, f11 for n 2, fn
    fn-1fn-2.
  • Tower of Hanoi
  • Disks of decreasing diameter on 1 of 3 pegs.
  • Move disks to another peg, always maintaining
    decreasing disk diameters on each peg.
  • Hn number of moves to transfer n disks from 1
    peg to another.
  • H11 for n 2, Hn Hn-11Hn-1 2Hn-11.
    1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,163
    83,32767,65535,
  • Hn 2n-1.

5
RRs for Counting Bit Strings
  • How many bit strings of length n do not contain 2
    consecutive 0s? b12 (0,1), b23
    (01,10,11)
  • For n 2 01counted or 1counted bn
    bn-2 bn-1 .
  • Recognize this?
  • How many bit strings of length n contain 2
    consecutive 0s? b0b10
  • For n 2 00any or 01counted or
    1counted bn 2n-2 bn-2
    bn-1 .

6
Counting Code Words
  • How many strings of n digits have an even number
    of 0s?
  • a19
  • For n 2
  • Either the first digit isnt 0 and the rest has
    an even number of 0s (there are 9an-1 of these)
  • or the first digit is 0 and the rest does not
    have an even number of digits (there are
    10n-1-an-1 of these)
  • an 9an-1(10n-1-an-1)8an-110n-1

7
Catalan Numbers
  • Cn number of ways to parenthesize the product
    of n1 numbers. C11 (1x2)
    C22 (1x(2x3)), ((1x2)x3)
  • C35 (1x(2x(3x4))), (1x((2x3)x4)),
    ((1x2)x(3x4)), ((1x(2x3))x4), (((1x2)x3)x4)
  • C0C11
  • CnC0Cn-1C1Cn-2C2Cn-3Cn-3C2Cn-2C1Cn-1C
    0
    (Covered in Sec.7.4, Ex.41)

Cn Number of binary trees with n1 leaves.
2
5
14
8
Solving Recurrence Relations
  • Weve seen several examples of Recurrence
    Relations
  • an aan-1 bn nbn-1
    fn fn-2 fn-1
  • bn2n-2bn-2bn-1 bn2n-3bn-3bn-2bn-1
    .
  • bn bn-1bn-2-bn-3 Hn2Hn-11
  • In each case, many sequences satisfy the
    relationship and one also needs to set/have
    initial conditions get a unique solution.
  • Goal closed form expression for function, f,
    for the sequence, giving the nth term in a
    formula that doesnt depend on earlier ones.
  • Example andan instead of an aan-1
  • Hn2n-1 instead of Hn2Hn-11
  • Well look at a class of useful recurrence
    relations where deriving a closed form formula is
    easy.

9
Recurrence Relations
  • When c1, c2, , ck are constants and ck?0, an
    c1an-1c2an-2ckan-k F(n)
  • is said to be a linear recurrence relation of
    degree k with constant coefficients .
  • Linear each aj appears only to the 1st
    power, no aj2 , aj3, . . .
  • degree k k previous terms, ck?0.
  • constant coefficients cj are constants,
    not functions cj(n).
  • Additionally, if F(n)0, the relation is called
    homogeneous.
  • Homogeneous linear recurrence relation of degree
    k with constant coefficientsan
    c1an-1c2an-2ckan-k where ck?0
  • We like these because we can solve them
    explicitly. ?

10
Examples of Recurrence Relations
  • HLRRwCC Homogeneous linear recurrence relation
    with constant coefficients
  • an aan-1 HLRRwCC of
    degree 1
  • an (an-1)2 Not Linear
  • an nan-1 Coefficients
    are not constant
  • fn fn-2 fn-1 HLRRwCC
    of degree 2
  • bn2n-2bn-2bn-1 . Not Homogeneous
  • bn2n-3bn-3bn-2bn-1 Not Homogeneous
  • an an-1an-2-an-4 HLRRwCC of degree 4
  • Hn2Hn-11 Not Homogeneous
  • Remember
  • A recurrence relation has many solutions.
  • Only when the initial conditions are specified is
    the solution unique.
  • For degree k, you need k contiguous initial
    conditions.

11
Solving Linear (degree 1) HLRRwCC
  • The relation is an can-1
  • All solutions are of the form an dcn
    The function is f (n) dcn
  • With the initial condition a0 specified, the
    unique solution is an a0cn
  • We saw this in computing compound interest
  • An initial deposit of P0 dollars deposited at 7
    annual interest.Pn(10.07)Pn-1 is the value
    after n years. Pn(10.07)nP0

12
Fibonacci Solved
  • Degree 1 f(n)cf(n-1) solution f(n)arn
    for some a and r
  • Degree 2 f(n)c1f(n-1)c2f(n-2) solution
    ?
  • Consider Fibonacci numbers F(n)F(n-1)F(n-2),
    and lets try F(n)rn.
  • It follows that r2r1.
  • There are 2 solutions to this quadratic equation
    r1(1v5)/2, r2(1-v5)/2
  • Therefore F1(n)(1v5)/2n and
    F2(n)(1-v5)/2n are both solutions.
  • Observe If F1,F2 are solutions then so is F(n)
    d1F1(n) d2F2(n)
  • Theorem (next slide) Every solution to this
    recurrence relation is of the form F(n)
    d1F1(n) d2F2(n) for some d1,d2
  • For our initial conditions
  • F(0)0 and F(1)1 we get d1d20 and
    d1r1d2r21
  • Therefore 1d1(r1-r2 )d1(v5). Therefore d1
    1/v5 and d2 -1/v5
  • Therefore the closed formula for Fibonacci
    numbers is

13
Solutions to HLRRwCC
  • We like HLRRwCC because we can solve them
    explicity.That is, we can find functions fN?R
    so that thesequence f(n) solves the recurrence
    relation.Heres part of the reason why.
  • Lemma If functions f and g are solutions to the
    HLRRwCC an c1an-1c2an-2c3an-3ckan-k
    then fg is also a solution as is df for any
    constant d.
  • Definitions The characteristic equation of this
    HLRRwCC is rk c1rk-1c2rk-2c3rk-3ck-1r
    ck The solutions (roots) of this equation are
    called the characteristic roots of the
    recurrence relation

14
(Fibonacci) Degree 2 HLRRwCC
  • 1) Write out the characteristic equation. (For
    Fibonacci r2r1)
  • 2) Find the characteristic roots (r1 and r2).
    (r1(1v5)/2, r2(1-v5)/2)
  • 3) Any function of the form f(n)d1r1 n d2r2
    n(d1 and d2 constants) solves this recurrence
    relation.
  • 4a) If the characteristic roots are distinct, we
    can pick d1 and d2 to produce the required
    initial values.
  • 4b) If there is only 1 characteristic root
    (r1r2r1), then any function of the form
    f(n)(d1d2n)r n (d1 and d2 constants) solves
    the recurrence relation.
  • Example
  • a01, a14 for n 2, an 4an-1-4an-2
    1,4,12,32,80,192,448,
  • Characteristic Equation r24r-4 ? r2-4r40
    ? r2 (twice)
  • f(n)(d1d2n)2 n 1d1 42d12d2 ?
    d1d21
  • f(n)(1n)2n
  • Check f(6)(16)26764448

15
All Solutions For Any HLRRwCC
  • Thrm If rk c1rk-1c2rk-2ck-1rck (ck?0) has
    k distinct roots, r1,r2,,rk,
  • then every solution of the recursion
    relation
  • anc1an-1c2an-2ckan-k has the
    form
  • an d1r1nd2r2ndkrkn for some
    d1, d2, , dk
  • and every such sequence solves/satisfies
    the recursion relation.
  • If there are t distinct roots, each with
    multiplicity mi,
  • the sequences an solving the recursion
    relation are given by

16
Degree 3 HLRRwCC Examples
  • a02, a15, a215 for n 3, an 6an-1-11an-2-
    6an-3
  • r3 6r2-11r-6 ? r3-6r211r60 ?
    (r-1)(r-2)(r-3)0
  • General solution an x1ny2nz3n .
  • Initial values 2xyz 5x2y3z 15x4y9z
    ? x1 y-1 z2
  • Specific solution an 1-2n23n .
  • a01, a1-2, a2-1 for n 3, an
    -3an-1-3an-2-an-3
  • r3 -3r2-3r-1 ? r33r23r10 ? (r1)30
    ? r-1 with multiplicity 3
  • General solution an(xynzn2)(-1)n .
  • Initial values 1x 2xyz -1x2y4z ? x1
    y3 z-2
  • Specific solution an (13n-2n2) (-1)n.
Write a Comment
User Comments (0)
About PowerShow.com