CSCE 222 Lecture 22

From Notes
Jump to navigation Jump to search

« previous | Wednesday, March 30, 2011 | next »


Recurrence Relations

A recurrence relation for the sequence of integers {an}n0 is an equation that expresses an as a function of some of the previous terms a0 to an1 starting from an integer n0

A linear homogeneous recurrence relation of degree k with constant coefficients is of the form:

an=C1an1+C2an2++Ckank
linear
ai is a linear function of the terms before it (no exponents).
EX: an=an1+an22 is not linear.
homogeneous
every term is a multiple of ai
degree
the number of ai terms added to get the current an.

This function can be rewritten as a series:

an=rn where r is a constant.


Theorem

Let c1 and c2 be real numbers. Suppose that r2c1rc2=0 has 2 distinct roots r1 and r2. Then an=c1an1+c2an2 has a solution {an} n0 iff an is of the form: an=α1r1n+α2r2n for constants α1 and α2.


Example 1: Fibonacci Numbers

Given f1=1 and f2=1,

fn=fn1+fn2for n3

The Fibonacci sequence is a linear homogeneous function of degree 2

From here, we can get {1,1,2,3,5,8,13,21,34,55,89}.

Using the theorem, we can rewrite an as a degree 2 polynomial: r12r21 has roots 1±52 (the golden ratio).

More complicated math can solve for the constants α1 and α2. Now we can solve the Fibonacci sequence in a single formula that runs in O(1) time:

fn=α1(1+52)n+α2(152)n

The sequence grows asymptotically according to Θ((1+52)n).

Example 2: Towers of Hanoi

Moving one disk at a time, move all n disks from peg 1 to peg 3. A larger disk cannot be placed on top of a smaller one.

In order to do this, the top n1 disks have to be moved to peg 2, the largest disk is moved to peg 3, then the top n1 disks are moved to peg 3.

Hn=Hn1+1+Hn1=2Hn1+1=2n1

The towers of hanoi function is linear, but not homogeneous since we add 1.

Given H1=1, we can find H2=3, H3=7.