recurrences, phi and cf
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 PresentationTRANSCRIPT
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
Solve in integers
x1+x2+x3=11
x10; x23; x30
Warm-up
Solve in integers
x1+x2+x3=11
x10; x23; x30
[X11]
Warm-up
2
32
x)- (1xxx1
Find the number of ways to make change for $1 using
pennies, nickels, dimes and quarters
Make Change (interview question)
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
Find the number of ways to make change for $1 using
pennies, nickels, dimes and quarters
Make Change
10025x10x5xx 4321
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
Find the number of ways to partition the integer n
Partitions
nnx3x2xx n321 ...
Find the number of ways to partition the integer n
Partitions
)x- )...(1x- )(1x- x)(1- (1 n321
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.
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
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.
What is a closed form formula for Fn?
F0=0, F1=1,
Fn=Fn-1+Fn-2 for n2
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
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
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
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
Leonhard Euler (1765)
Fn
FHG
IKJ
n
n1
5
Fibonacci Power SeriesFibonacci Power Series
??0
k
kk xF
Fibonacci BamboozlementFibonacci Bamboozlement
Cassini’s IdentityCassini’s Identity
Fn+1Fn-1 - Fn
2 = (-1)n
We dissect FnxFn square and rearrange pieces into Fn+1xFn-1 square
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
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
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).
Which is the most attractive Which is the most attractive rectangle?rectangle?
Which is the most attractive Which is the most attractive rectangle?rectangle?
Golden Rectangle
1
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
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
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.
Expanding RecursivelyExpanding Recursively
11
012
Expanding RecursivelyExpanding Recursively
11
11
11
Expanding RecursivelyExpanding Recursively
11
11
11
11
11
11
Expanding RecursivelyExpanding Recursively
11
11
11
11
11
11
11
11
11
1 ....
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.
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
Continued Fraction RepresentationContinued Fraction Representation
8 11
15 11
11
11
= [1,1,1,1,1,0,0,0,…]
Recursively Defined Form For CFRecursively Defined Form For CF
CF whole number, or
1 = whole number
CF
Proposition: Any finite continued fraction evaluates to a rational.
Converse: Any rational has a finite continued fraction representation.
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
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
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
How to convert kilometers into miles?
Heads-onHeads-on
50 km = 34 + 13 + 3
50 = F9 + F7 + F4
F8 + F6 + F3 = 31 miles
Magic conversionMagic conversion
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
A Periodic CFA Periodic CF
3 13 13
12 31
31
31
31
31
31
31
33 ....
A period-2 CFA period-2 CF
...41
8
14
18
14
11
1
3
21
Proposition: Any quadratic solution has a periodic continued fraction.
Converse: Any periodic continued fraction is the solution of a quadratic equation
What about those non-periodic
continued fractions?
Non-periodic CFsNon-periodic CFs
11 1
11
11
11
11
11
11
11 ...
2
4
6.
e
What is the pattern?What is the pattern?
13
17
115
11
1292
11
11
11
12
1 ....
What a cool representation!
Finite CF: RationalsPeriodic CF: Quadratic
rootsAnd some numbers
reveal hidden regularity.
More recurrences!!More recurrences!!
Let us embark now on the Let us embark now on the Catalan numbersCatalan numbers
Count the number of binary trees with n
nodes.
Counting Binary TreesCounting Binary Trees
Let Tn represent the number of trees with
n nodes
T1=1, T2=2
Counting Binary TreesCounting Binary Trees
Counting Binary TreesCounting Binary Trees
Size n-1-k Size k
Size n =
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
Counting Binary TreesCounting Binary Trees
??0
k
kk xT
Count the number of ways to divide a
convex n-gon into triangles with
noncrossing diagonals.
TriangulationTriangulation
Study Bee
• Review GCD algorithm• Recurrences, Phi and CF• The Catalan numbers