You are on page 1of 7

Mathematics for Computer Science Book Stacking

MIT 6.042J/18.062J

Harmonic Series,
Integral Method,
Stirling’s Formula
table
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. . October 28,2005 L8-3.1 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.2

Book Stacking Book Stacking

How far out? One book center of mass


of book

?
overhang
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.3 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.4

Book Stacking Book Stacking

One book center of mass


of book
One book center of mass
of book

1
2

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.5 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.6

n books n books

center
of
mass
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.7 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.8

n books n books

Need
center of mass center of mass
over table of the whole stack

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.9 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.10

n+1 books

Δ overhang ::=
center of mass
of all n+1 books Horizontal distance from
at table edge

center of mass n-book to n+1-book


of top n books
at edge of book
centers-of-mass
N n+1

∆overhang

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.11 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.12

Δ overhang
Choose origin so center of n-stack at x = 0.
n
Now center of n+1st book is at x = 1/2, so
1
center of n+1-stack is at

}
Δ
1/2 n ⋅ 0 + 1 ⋅1 / 2 1
1 x= =
2 = 1 n +1 2(n + 1)
Δ=
n + 1 2(n + 1)
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.13 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.14

n+1 books Book stacking summary

Bn ::= overhang of n books


center of mass
of all n+1 books B1 = 1/2
at table edge 1
Bn+1 = Bn +
center of mass 2(n + 1)
of top n books
at edge of book
1⎛ 1 1 1⎞
n+1
Bn = ⎜1 + + + " + ⎟
}

1 2⎝ 2 3 n⎠
2(n + 1)
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. October 28,2005 L8-3.15 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.16

1 1 1 Estimate Hn :
H n ::= 1 + + +" +
1

2 3 n
Integral Method
1
nth Harmonic number 1
2
x+1

Bn = Hn/2 1
3

1 1 1
2 3

0 1 2 3 4 5 6 7 8
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.17 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.18

3
Book stacking

n
1 1 1 1
∫ x + 1 dx ≤
0
1+ + + ... +
2 3 n So Hn → ∞ as n→ ∞, and so

n+1
1 overhang can be any desired size.

1
x
dx ≤ H n

ln(n + 1) ≤ H n

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.19 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.20

Book stacking
Team Problem
Overhang 3: need Bn ≥ 3

Hn ≥ 6

Integral bound: ln (n+1) ≥ 6

So can do with n ≥ ⎡e6−1⎤ = 403 books

Actually calculate Hn :

Problem 1
227 books are enough.

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. L8-3.21 Copyright © Albert R. Meyer, 2004. April 5, 2004 L10-1.22
October 28,2005

Crossing a Desert 1 Tank of Gas


1 tank

Gas truck

depot

How big a desert can the truck cross? D1::= max distance on 1 tank = 1
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.23 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.24

4
n+1 Tanks of Gas
Let Dn ::=
x

1 −2x
max distance into the
1−2x

desert using n tanks


1−2x
n

of gas from the depot


1−x

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.25 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.26

n+1 Tanks of Gas depot at x


x
 
So have: (1−2x)n Set (1−2x)n + (1−x) = n.
+ (1−x)
Set depot at x
Then using n tank strategy
to be n tanks;
from position x, gives
continue from

x with n tank

Dn+1 = Dn + x
method.

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.27 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.28

1 1 1
(1−2x)n + (1−x) = n Dn = 1 + + + " +
3 5 2n −1
1 n
1
x= ∫ 2(x + 1) −1 dx ≤ Dn
2n+1 0

ln(2n +1)
1 ≤ Dn
Dn+1 = Dn + 2
2n+1
Can cross any desert!
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.29 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.30

5
Closed form for n!
Team Problem
Factorial defines a product: n
n! :: = 1 ⋅ 2 ⋅ 3 ⋅⋅⋅ (n − 1) ⋅ n = ∏ i
i=1

Problem 2 Turn product into a sum taking logs:


ln(n!) = ln(1 · 2 · 3 · · · (n – 1) · n)
= ln 1 + ln 2 + · · · + ln(n – 1) + ln(n)
n
= ∑ ln(i)
i=1
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.31 Copyright © Albert Meyer and RonittRubinfeld, , 2003. October 16, 2003

Integral Method n Integral Method

Integral Method to bound ∑ ln i


i=1
Bounds on ln(n!)

n n n

ln (x)
∫ ln( x) dx ≤ ∑ ln(i) ≤ ∫ ln( x + 1) dx
ln n

… ln (x+1)
ln 5
ln 4
1 i=1 1
ln 3
ln ln n
ln 2 ln 5 n-1
ln 3 ln 4
ln 2
1 2 3 4 5 n–2 n–1 n
Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.33 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.34

Integral Method Integral Method


Reminder: ⎛ x⎞
⎛ x⎞ ∫ ln x dx = x ln ⎜ ⎟
∫ ln x dx = x ln ⎜ ⎟=
⎝e⎠
⎝e⎠
= x ln x −
x
x(ln x − ln e) = x (ln x − 1)
Quickie:
= x ln x − x verify by differentiating.

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.35 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.36

6
Integral Method Integral Method

Bounds on ln(n!) n
1 ⎛n⎞
n ∑ ln(i) ≈ (n + 2 )ln ⎜⎝ e ⎟⎠

ln( x) dx ≤ ∑
ln(i) ≤ ∫
ln( x + 1) dx
n n
i =1
1 1
i =1 exponentiating:
⎛n⎞ n
⎛ n +1⎞
n ln ⎜ ⎟ + 1 ≤ ∑ ln(i) ≤ (n + 1) ⋅ ln⎜ ⎟ + 0. 6

e ⎠
⎝ e ⎠ n
i =1
⎛n⎞
So guess:
n
1 ⎛n⎞ n! ≈ n / e ⎜ ⎟
∑ ln(i) ≈ (n + 2 )ln ⎜⎝ e ⎟⎠
i =1
⎝e⎠
Copyright © Albert Meyer, 2003. October 16, 2003 Copyright © Albert Meyer , 2003. October 16, 2003

Stirling’s Formula Asymptotic Equivalence

A precise approximation: f(n) ~ g(n)


n

~ 2π n ⎛⎜ ⎞⎟
n
n! ⎛ f ( n) ⎞
⎝e⎠ lim ⎜ ⎟ =1
n →∞
⎝ g ( n ) ⎠

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.39 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.40

Team Problem

Problem 3

Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 L8-3.41

You might also like