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(152)1f2=1=α1(1+52)2+α2(152)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(n1)+T(n2)=Θ( time.

In General

A polynomial of degree k has k distinct roots:

rkc1rk1+c2rk2ck=0

A recursive function of degree k written as

an=c1an1+c2an2++ckank

can be rewritten as a polynomial:

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

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


Generating Functions

A generating function for sequence {an}n0 is the infinite series

G(x)=k=0akxk

Example

{an}n0 with ak=2k has the generating function

G(x)=k=02kxk

Example

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

G(x)=k=0xk=(1+x+x2+x3+)=11x

Theorem

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

f(x)+g(x)=k=0(ak+bk)xkf(x)g(x)=k=0(j=0ajbkj)xk

Example

11x11x=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(u1)(u2)(uk+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