Book Stacking Mathematics for Computer Science MIT 6.042J/18.062J Harmonic Series, Integral Method, Stirling’s Formula table Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. . L8-3.1 October 28,2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. Book Stacking L8-3.2 October 28,2005 Book Stacking How far out? One book center of mass of book ? overhang Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. L8-3.3 October 28,2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. Book Stacking One book L8-3.4 October 28,2005 Book Stacking One book center of mass of 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 1 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. n books October 28,2005 L8-3.8 n books Need center of mass over table center of mass 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 n+1 books center of mass of all n+1 books at table edge N center of mass of top n books at edge of book n+1 Δ overhang ::= Horizontal distance from n-book to n+1-book centers-of-mass ∆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 2 Δ 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 1 1 2 = n + 1 2(n + 1) Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. L8-3.13 October 28,2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. center of mass of all n+1 books at table edge } center of mass of top n books at edge of book n+1 1 2(n + 1) H n ::= 1 + October 28,2005 L8-3.15 1 1 1 + +" + 2 3 n Bn ::= overhang of n books B1 = 1/2 1 Bn+1 = Bn + 2(n + 1) 1⎛ 1 1 1⎞ ⎜1 + + + " + ⎟ 2⎝ 2 3 n⎠ Bn = Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. Estimate Hn : Integral Method 1 x+1 1 2 1 3 Bn = Hn/2 0 L8-3.17 1 3 1 2 1 October 28,2005 L8-3.16 October 28,2005 1 nth Harmonic number Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. L8-3.14 October 28,2005 Book stacking summary n+1 books Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. All rights reserved. n ⋅ 0 + 1 ⋅1 / 2 1 = n +1 2(n + 1) x= 1 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. 2 3 4 5 October 28,2005 6 7 8 L8-3.18 3 Book stacking n 1 ∫ x + 1 dx ≤ 1+ 0 n+1 ∫ 1 1 1 1 + + ... + 2 3 n So Hn → ∞ as n→ ∞, and so overhang can be any desired size. 1 dx ≤ H n x 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. Book stacking October 28,2005 L8-3.20 Team Problem Bn ≥ 3 Hn ≥ 6 Integral bound: ln (n+1) ≥ 6 So can do with n ≥ ⎡e6−1⎤ = 403 books Actually calculate Hn : 227 books are enough. Overhang 3: need Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 Problem 1 L8-3.21 Crossing a Desert April 5, 2004 Copyright © Albert R. Meyer, 2004. L10-1.22 1 Tank of Gas 1 tank Gas depot truck How big a desert can the truck cross? Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. October 28,2005 D1::= max distance on 1 tank = 1 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 ::= max distance into the desert using n tanks of gas from the depot Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. x 1 −2x 1−2x 1−2x 1−x L8-3.25 October 28,2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. n+1 Tanks of Gas Set (1−2x)n + (1−x) = n. (1−2x)n + (1−x) Set depot at x to be n tanks; continue from x with n tank method. Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. Then using n tank strategy from position x, gives Dn+1 = Dn + x October 28,2005 L8-3.27 October 28,2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. L8-3.28 October 28,2005 1 1 1 Dn = 1 + + + " + 3 5 2n −1 (1−2x)n + (1−x) = n 1 x= 2n+1 1 Dn+1 = Dn + 2n+1 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. L8-3.26 October 28,2005 depot at x x So have: n n 1 ∫ 2(x + 1) −1 dx ≤ Dn 0 ln(2n +1) ≤ Dn 2 Can cross any desert! 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. L8-3.31 October 28,2005 Integral Method Integral Method to bound Copyright © Albert Meyer and RonittRubinfeld, , 2003. Integral Method n ∑ ln i Bounds on ln(n!) i=1 … ln (x+1) ln 5 ln 4 ln 3 ln 2 ln 3 ln 4 ln 2 1 2 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. 3 ln 5 4 5 ln ln n n-1 n–2 n–1 October 28,2005 n n 1 i=1 1 n L8-3.33 Integral Method Reminder: October 28,2005 L8-3.34 ⎛ x⎞ = ln x dx x ln ⎜ ⎟ ∫ ⎝e⎠ = x ln x − x x(ln x − ln e) = x (ln x − 1) = x ln x − x October 28,2005 Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. Integral Method ⎛ x⎞ ln x dx x ln = ⎜ ⎟= ∫ ⎝e⎠ Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. n ∫ ln( x) dx ≤ ∑ ln(i) ≤ ∫ ln( x + 1) dx ln (x) ln n October 16, 2003 Quickie: verify by differentiating. 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 i =1 1 i =1 n ⎛n⎞ ⎛ n +1⎞ n ln ⎜ ⎟ + 1 ≤ ∑ ln(i) ≤ (n + 1) ⋅ ln⎜ ⎟ + 0. 6 ⎝ e ⎠ ⎝ e ⎠ i =1 exponentiating: ⎛n⎞ n! ≈ n / e ⎜ ⎟ ⎝e⎠ ⎛n⎞ 1 n So guess: ∑ ln(i) ≈ (n + 2 )ln ⎜⎝ e ⎟⎠ i =1 Copyright © Albert Meyer, 2003. Copyright © Albert Meyer , 2003. October 16, 2003 October 16, 2003 A precise approximation: Copyright © Albert R. Meyer and Ronitt Rubinfeld, 2005. n ~ 2π n ⎛⎜ ⎞⎟ n Asymptotic Equivalence Stirling’s Formula n! ⎛n⎞ ∑ ln(i) ≈ (n + 2 )ln ⎜⎝ e ⎟⎠ ∫ ln( x) dx ≤ ∑ ln(i) ≤ ∫ ln( x + 1) dx n 1 n f(n) ~ g(n) n ⎛ f ( n) ⎞ lim ⎜ ⎟ =1 n →∞ g ( n ) ⎝ ⎠ ⎝e⎠ 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 7