59
Recurrences, Phi and CF Recurrences, Phi and CF Great Theoretical Ideas In Computer Science Great Theoretical Ideas In Computer Science S. Rudich S. Rudich V. Adamchik V. Adamchik CS 15-251 Spring CS 15-251 Spring 2006 2006 Lecture 13 Lecture 13 Feb 28, 2006 Feb 28, 2006 Carnegie Mellon Carnegie Mellon University University

Recurrences, Phi and CF

  • Upload
    alaina

  • View
    24

  • Download
    1

Embed Size (px)

DESCRIPTION

Recurrences, Phi and CF. Warm-up. Solve in integers x 1 +x 2 +x 3 =11 x 1 r 0; x 2 b 3; x 3 r 0. Warm-up. Solve in integers x 1 +x 2 +x 3 =11 x 1 r 0; x 2 b 3; x 3 r 0 [X 11 ]. Make Change (interview question). - PowerPoint PPT Presentation

Citation preview

Page 1: Recurrences, Phi and CF

Recurrences, Phi and CFRecurrences, Phi and CF

Great Theoretical Ideas In Computer ScienceGreat Theoretical Ideas In Computer Science

S. RudichS. Rudich

V. AdamchikV. AdamchikCS 15-251 Spring CS 15-251 Spring

20062006

Lecture 13Lecture 13 Feb 28, 2006Feb 28, 2006 Carnegie Mellon Carnegie Mellon UniversityUniversity

Page 2: Recurrences, Phi and CF

Solve in integers

x1+x2+x3=11

x10; x23; x30

Warm-up

Page 3: Recurrences, Phi and CF

Solve in integers

x1+x2+x3=11

x10; x23; x30

[X11]

Warm-up

2

32

x)- (1xxx1

Page 4: Recurrences, Phi and CF

Find the number of ways to make change for $1 using

pennies, nickels, dimes and quarters

Make Change (interview question)

Page 5: Recurrences, Phi and CF

Find the number of ways to make change for $1 using

pennies, nickels, dimes and quarters

[X100]

Make Change

)x- )(1x- )(1x- x)(1- (11

25105

Page 6: Recurrences, Phi and CF

Find the number of ways to make change for $1 using

pennies, nickels, dimes and quarters

Make Change

10025x10x5xx 4321

Page 7: Recurrences, Phi and CF

Find the number of ways to partition the integer n

3 = 1+1+1=1+24=1+1+1+1=1+1+2=1+3=

2+2

Partitions

Page 8: Recurrences, Phi and CF

Find the number of ways to partition the integer n

Partitions

nnx3x2xx n321 ...

Page 9: Recurrences, Phi and CF

Find the number of ways to partition the integer n

Partitions

)x- )...(1x- )(1x- x)(1- (1 n321

Page 10: Recurrences, Phi and CF

Leonardo FibonacciLeonardo Fibonacci

In 1202, Fibonacci proposed a problem In 1202, Fibonacci proposed a problem about the growth of rabbit populations.about the growth of rabbit populations.

Page 11: Recurrences, Phi and CF

The rabbit reproduction The rabbit reproduction modelmodel

•A rabbit lives foreverA rabbit lives forever•The population starts as a single newborn The population starts as a single newborn pairpair•Every month, each productive pair begets Every month, each productive pair begets a new pair which will become productive a new pair which will become productive after 2 months oldafter 2 months old

FFnn= = # of rabbit pairs at the beginning of # of rabbit pairs at the beginning of the nthe nthth month month

monthmonth 11 22 33 44 55 66 77

rabbitrabbitss

11 11 22 33 55 881133

Page 12: Recurrences, Phi and CF

FFnn is called the is called the nnthth Fibonacci Fibonacci numbernumber

monthmonth 11 22 33 44 55 66 77

rabbitrabbitss

11 11 22 33 55 881133

F0=0, F1=1, and Fn=Fn-1+Fn-2 for n2

Fn is defined by a recurrence relation.

Page 13: Recurrences, Phi and CF

What is a closed form formula for Fn?

F0=0, F1=1,

Fn=Fn-1+Fn-2 for n2

Page 14: Recurrences, Phi and CF

Techniques you have seen so Techniques you have seen so farfar

Fn=Fn-1+Fn-2

Consider solutions of the form: Fn= cn

for some constant c

c must satisfy: cn - cn-1 - cn-2 = 0

Page 15: Recurrences, Phi and CF

cn - cn-1 - cn-2 = 0

iff iff cn-2(c2 - c - 1) = 0

iff c=0 or c2 - c - 1 = 0

Iff c = 0, c = , or c = -1/

(“phi”) is the golden ratio

Page 16: Recurrences, Phi and CF

c = 0, c = , or c = -(1/)

So for all these values of c the So for all these values of c the inductive condition is satisfied:inductive condition is satisfied:

cn - cn-1 - cn-2 = 0Do any of them happen to satisfy the base condition as well?

F0=0, F1=1

Page 17: Recurrences, Phi and CF

a,b a a,b a n n + b (-1/ + b (-1/ ))nn satisfies the inductive satisfies the inductive

conditionconditionAdjust a and b to fit the base conditions.Adjust a and b to fit the base conditions.

n=0: a+b = 0n=0: a+b = 0

n=1: a n=1: a 1 1 + b (-1/ + b (-1/ ))1 1 = 1= 1

a= 1/a= 1/5 b= -5 b= -1/1/5 5

Page 18: Recurrences, Phi and CF

Leonhard Euler (1765)

Fn

FHG

IKJ

n

n1

5

Page 19: Recurrences, Phi and CF

Fibonacci Power SeriesFibonacci Power Series

??0

k

kk xF

Page 20: Recurrences, Phi and CF

Fibonacci BamboozlementFibonacci Bamboozlement

Page 21: Recurrences, Phi and CF

Cassini’s IdentityCassini’s Identity

Fn+1Fn-1 - Fn

2 = (-1)n

We dissect FnxFn square and rearrange pieces into Fn+1xFn-1 square

Page 22: Recurrences, Phi and CF

AC

AB

AB

BCAC

BCAC

BC

AB

BC

BC

BC1

1 0

2

2

2

Golden Ratio Golden Ratio Divine ProportionDivine Proportion

Ratio obtained when you divide a line Ratio obtained when you divide a line segment into two unequal parts such that the segment into two unequal parts such that the ratio of the whole to the larger part is the ratio of the whole to the larger part is the same as the ratio of the larger to the smaller.same as the ratio of the larger to the smaller.

A B C

Page 23: Recurrences, Phi and CF

Ratio of height of the person Ratio of height of the person to height of a person’s navelto height of a person’s navel

Page 24: Recurrences, Phi and CF

AestheticsAesthetics

plays a central role in renaissance art plays a central role in renaissance art and architecture.and architecture.

After measuring the dimensions of After measuring the dimensions of pictures, cards, books, snuff boxes, pictures, cards, books, snuff boxes, writing paper, windows, and such, writing paper, windows, and such, psychologist Gustav Fechner claimed that psychologist Gustav Fechner claimed that the preferred rectangle had sides in the the preferred rectangle had sides in the golden ratio (1871).golden ratio (1871).

Page 25: Recurrences, Phi and CF

Which is the most attractive Which is the most attractive rectangle?rectangle?

Page 26: Recurrences, Phi and CF

Which is the most attractive Which is the most attractive rectangle?rectangle?

Golden Rectangle

1

Page 27: Recurrences, Phi and CF

Divina ProportioneDivina ProportioneLuca Pacioli (1509)Luca Pacioli (1509)

Pacioli devoted an entire book to the Pacioli devoted an entire book to the marvelous properties of marvelous properties of . The book . The book was illustrated by a friend of his was illustrated by a friend of his named:named:

Leonardo Da VinciLeonardo Da Vinci

Page 28: Recurrences, Phi and CF

Table of contentsTable of contents

•The first considerable effectThe first considerable effect•The second essential effectThe second essential effect•The third singular effectThe third singular effect•The fourth ineffable effectThe fourth ineffable effect•The fifth admirable effectThe fifth admirable effect•The sixth inexpressible effectThe sixth inexpressible effect•The seventh inestimable effectThe seventh inestimable effect•The ninth most excellent effectThe ninth most excellent effect•The twelfth incomparable effectThe twelfth incomparable effect•The thirteenth most distinguished effectThe thirteenth most distinguished effect

Page 29: Recurrences, Phi and CF

Divina ProportioneDivina ProportioneLuca Pacioli (1509)Luca Pacioli (1509)

""Ninth Most Excellent EffectNinth Most Excellent Effect" "

two diagonals of a regular pentagon two diagonals of a regular pentagon divide each other in the Divine divide each other in the Divine

Proportion. Proportion.

Page 30: Recurrences, Phi and CF

Expanding RecursivelyExpanding Recursively

11

012

Page 31: Recurrences, Phi and CF

Expanding RecursivelyExpanding Recursively

11

11

11

Page 32: Recurrences, Phi and CF

Expanding RecursivelyExpanding Recursively

11

11

11

11

11

11

Page 33: Recurrences, Phi and CF

Expanding RecursivelyExpanding Recursively

11

11

11

11

11

11

11

11

11

1 ....

Page 34: Recurrences, Phi and CF

A (Simple) Continued Fraction Is Any A (Simple) Continued Fraction Is Any Expression Of The Form:Expression Of The Form:

11

11

11

11

1

....

abcd

efg

hij

where a, b, c, … are whole numbers.

Page 35: Recurrences, Phi and CF

A Continued Fraction can have a A Continued Fraction can have a finite or infinite number of terms.finite or infinite number of terms.

We also denote this fraction by [a,b,c,d,e,f,…]

11

11

11

11

1

....

abcd

efg

hij

Page 36: Recurrences, Phi and CF

Continued Fraction RepresentationContinued Fraction Representation

8 11

15 11

11

11

= [1,1,1,1,1,0,0,0,…]

Page 37: Recurrences, Phi and CF

Recursively Defined Form For CFRecursively Defined Form For CF

CF whole number, or

1 = whole number

CF

Page 38: Recurrences, Phi and CF

Proposition: Any finite continued fraction evaluates to a rational.

Converse: Any rational has a finite continued fraction representation.

Page 39: Recurrences, Phi and CF

Euclid’s GCD = Continued Euclid’s GCD = Continued FractionsFractions

Euclid(A,B) = Euclid(B, A mod B)Stop when B=0

1

mod

A ABB B

A B

Page 40: Recurrences, Phi and CF

A Pattern forA Pattern for

Let rLet r11 = [1,0,0,0,…] = 1 = [1,0,0,0,…] = 1

rr22 = [1,1,0,0,0,…] = 2/1 = [1,1,0,0,0,…] = 2/1

rr33 = [1,1,1,0,0,0…] = 3/2 = [1,1,1,0,0,0…] = 3/2

rr44 = [1,1,1,1,0,0,0…] = 5/3 = [1,1,1,1,0,0,0…] = 5/3

and so on.and so on.

Theorem:Theorem:

rrnn = F = Fn+1n+1/F/Fnn

Page 41: Recurrences, Phi and CF

F

F

F

F

n

n

n

n

FHG

IKJ

FHG

IKJ

FHG

IKJ

FHG

IKJ

FHG

IKJ

1 1

1

1

1

1

1

1

1

1 1

1

1

n

n

n

n

n

n

n

n

n

n

nlim

Divine ProportionDivine Proportion

Page 42: Recurrences, Phi and CF

How to convert kilometers into miles?

Heads-onHeads-on

Page 43: Recurrences, Phi and CF

50 km = 34 + 13 + 3

50 = F9 + F7 + F4

F8 + F6 + F3 = 31 miles

Magic conversionMagic conversion

Page 44: Recurrences, Phi and CF

Quadratic EquationsQuadratic Equations

XX22 – 3x – 1 = 0 – 3x – 1 = 0

XX22 = 3X + 1 = 3X + 1

X = 3 + 1/XX = 3 + 1/X

X = 3 + 1/X = 3 + 1/[3 + 1/X] = X = 3 + 1/X = 3 + 1/[3 + 1/X] = ……

3 13

2X

Page 45: Recurrences, Phi and CF

A Periodic CFA Periodic CF

3 13 13

12 31

31

31

31

31

31

31

33 ....

Page 46: Recurrences, Phi and CF

A period-2 CFA period-2 CF

...41

8

14

18

14

11

1

3

21

Page 47: Recurrences, Phi and CF

Proposition: Any quadratic solution has a periodic continued fraction.

Converse: Any periodic continued fraction is the solution of a quadratic equation

Page 48: Recurrences, Phi and CF

What about those non-periodic

continued fractions?

Page 49: Recurrences, Phi and CF

Non-periodic CFsNon-periodic CFs

11 1

11

11

11

11

11

11

11 ...

2

4

6.

e

Page 50: Recurrences, Phi and CF

What is the pattern?What is the pattern?

13

17

115

11

1292

11

11

11

12

1 ....

Page 51: Recurrences, Phi and CF

What a cool representation!

Finite CF: RationalsPeriodic CF: Quadratic

rootsAnd some numbers

reveal hidden regularity.

Page 52: Recurrences, Phi and CF

More recurrences!!More recurrences!!

Let us embark now on the Let us embark now on the Catalan numbersCatalan numbers

Page 53: Recurrences, Phi and CF

Count the number of binary trees with n

nodes.

Counting Binary TreesCounting Binary Trees

Page 54: Recurrences, Phi and CF

Let Tn represent the number of trees with

n nodes

T1=1, T2=2

Counting Binary TreesCounting Binary Trees

Page 55: Recurrences, Phi and CF

Counting Binary TreesCounting Binary Trees

Size n-1-k Size k

Size n =

Page 56: Recurrences, Phi and CF

Counting Binary TreesCounting Binary Trees

Size n-1-k Size k

Size n =

TTnn = T = T00 T Tn-1n-1 + T + T11 T Tn-2n-2+…+T+…+Tn-1n-1 T T00

Page 57: Recurrences, Phi and CF

Counting Binary TreesCounting Binary Trees

??0

k

kk xT

Page 58: Recurrences, Phi and CF

Count the number of ways to divide a

convex n-gon into triangles with

noncrossing diagonals.

TriangulationTriangulation

Page 59: Recurrences, Phi and CF

Study Bee

• Review GCD algorithm• Recurrences, Phi and CF• The Catalan numbers