CSCE 222 Lecture 23

From Notes
Jump to navigation Jump to search

« previous | Friday, April 1, 2011 | next »


Solving the Fibonacci sequence

f0=0=α1+α2f1=1=α1(1+52)1+α2(1−52)1f2=1=α1(1+52)2+α2(1−52)2α1=15α2=−15

Ruby Implementation

def fib n
  return 1 if n==0 or n==1
  fib(n-1) + fib(n-2)
end

This recursive function runs in T(n)=1+T(n−1)+T(n−2)=Θ( time.

In General

A polynomial of degree k has k distinct roots:

rk−c1rk−1+−c2rk−2−…−ck=0

A recursive function of degree k written as

an=c1an−1+c2an−2+…+ckan−k

can be rewritten as a polynomial:

an=α1r1n+α2r2n+…+αkrkn

where α1,α2,…,αk are constants.


Generating Functions

A generating function for sequence {an}n≥0 is the infinite series

G(x)=∑k=0∞akxk

Example

{an}n≥0 with ak=2k has the generating function

G(x)=∑k=0∞2kxk

Example

{an}n≥0 with ak=1 (i.e. (1,1,…,1) ) has the generating function

G(x)=∑k=0∞xk=(1+x+x2+x3+…)=11−x

Theorem

Suppose we have two generating functions f(x)=∑k=0∞akxk and g(x)=∑k=0∞bkxk.

f(x)+g(x)=∑k=0∞(ak+bk)xkf(x)⋅g(x)=∑k=0∞(∑j=0∞ajbk−j)xk

Example

11−x11−x=∑k=0∞(∑j=0k1)xk=∑k=0∞(k+1)xk


Extended Binomial Coefficient

Let u be a real number and k be a nonnegative integer. (Factorials on u are out of the question.

(uk)={u(u−1)(u−2)…(u−k+1)k!k>01k=0

Example

(−23)=(−2)(−3)(−4)3!=−4

Extended Binomial Theorem

(1+x)u=∑k=0∞(uk)xk


Footnotes

Get The Art of Computer Progamming vol. 1-4a