You are on page 1of 7

The Toilet Paper Problem Author(s): Donald E. Knuth Reviewed work(s): Source: The American Mathematical Monthly, Vol.

91, No. 8 (Oct., 1984), pp. 465-470 Published by: Mathematical Association of America Stable URL: http://www.jstor.org/stable/2322567 . Accessed: 16/02/2013 10:04
Your use of the JSTOR archive indicates your acceptance of the Terms & Conditions of Use, available at . http://www.jstor.org/page/info/about/policies/terms.jsp

.
JSTOR is a not-for-profit service that helps scholars, researchers, and students discover, use, and build upon a wide range of content in a trusted digital archive. We use information technology and tools to increase productivity and facilitate new forms of scholarship. For more information about JSTOR, please contact support@jstor.org.

Mathematical Association of America is collaborating with JSTOR to digitize, preserve and extend access to The American Mathematical Monthly.

http://www.jstor.org

This content downloaded on Sat, 16 Feb 2013 10:04:50 AM All use subject to JSTOR Terms and Conditions

THE TOILET PAPER PROBLEM


DONALD E. KNUTH Science Computer Department, Stanford University, Stanford, 94305 CA

1. Introduction. toilet The paper in dispensersa certain building designed holdtwo are to rolls oftissues, a person useeither can and roll. Thereare twokindsof peoplewhouse therestrooms thebuilding: in big-choosers and A big-chooser takes pieceoftoilet a little-choosers. always the paperfrom rollthat currently is larger; little-chooser doesthe a always opposite. However, the rolls the when two are same size, or when only rollis nonempty, one chooses nearest everybody the nonempty When roll. both rolls areempty, everybody a problem. has the Let us assume people that enter toilet stalls independently at random, probability with p that are and they big-choosers probability 1 - p that are If the q= they little-choosers. janitor a supplies particular with fresh oftoilet stall two rolls paper, both length letMn be the of n, (p) left average number portions on onerollwhen other first of the roll empties. assume (We that of and the everyone the uses same amount paper, that lengths expressed terms this are in of unit.) Forexample, is easytoestablish it that M1(p) = 1, M2(p) = 2 -p, M3(p) = 3- 2p - p2 + p3; Mn(O) = n; Mn(1) = 1.
the The purposeof thispaperis to study asymptotic value of Mn (p) forfixedp as n 00. Wewillseethat generating the function Mn n hasa surprisingly form, which (p)z from simple En theasymptotic behavior readily deduced. be the can Along waywewillencounter several other interesting facts.

2. Recurrence the Relations. us begin generalizing problem,slightly, the Let by using notation for mean of one if number portions when rollempties,westart left with m n(p) tostand the Mn, on onerolland n on theother. Thus
Mn(p) = Mnn(P);
Mm0(P) Mnn(p) Mmn(p) = m; = Mn(n-1)(P)9 =PM(m-l)n(P) if n >

0;
if m > n > 0.

+ qMm(n-l)(p),

Thevalueof Mn(p) canbe computed all n from for these since recurrence relations, no pairs
(m',n') withm' < n' willarise. pointsin theplane,wherethearc from n) to (m - 1, n) has weight and from n) to (n, p (m, 1 (m, n - 1) has weight forall 0 < n < m; thearc from n) to (n, n - 1) has weight forall q, (m, n > 0; andthere no other ThenMmn( is the are arcs. over the p) sum, all k > 1,of k times sum

the It is convenient visualize recurrence drawing to certain between arcs by lattice adjacent

ofthe of from n) to(k,0), where weight a path the the of of is product the weights allpaths (m, individual weights. arc A path it that starts the at diagonal to returns point n) must first (n,n - 1); then either (n, go A number paths of from n - 1) to (k,1) whose do touch diagonal. path the (n, points notever ornever returns thediagonal all; itfollows to at that
thatstarts (n, n) either at returns thediagonalforthefirst to timeat somepoint(n - k, n - k), to thediagonalat (n - 1, n - 1) or goes to (n, n - 2), etc.Let Ck be thenumber pathsfrom of do and (n, n) to (n - k, n - k) whoseintermediate points nottouchthediagonal, let dnkbe the

work is at The author Fletcher Jones Professor Computer of Science Stanford is University. mainlife's "My such in but whatI liketo call the analysis algorithms, I also enjoydoingresearch supporting of disciplines as and combinatorial discrete and mathematics, programming languages, digital typography." 465

This content downloaded on Sat, 16 Feb 2013 10:04:50 AM All use subject to JSTOR Terms and Conditions

466
Mn(p)
=

DONALDE. KNUTH
C1PMn-1(P)
O<k<n

[October
1pfllq1-2M1(p)

+ C2p2qM-2(P)
lMn-k(P)

+ *

+c,

+ Ln(p)

Ckpkqk

+ Lnfl(P);

Ln(p)

2<k<n

kdnkpn-kqn-l forn ,3 2;

Lj(p) = 1.

pkqk-l ifno intermediate diagonal points (Eachpathfrom n) to (n - k,n - k) hasweight (n, 1 there k steps weight and are of p since to areinvolved, thestep (n, n - 1) hasweight andthen each order. path (n, k - 1 ofweight insome Similarly, diagonal-avoiding from n - 1) to(k, 1) q, hasweight pn-kqn-2.) and Catalan The coefficients are thewell-known numbers, thecoefficients are the Ck dnk ballot that numbers arisein theclassical see, [2, well-known problem; forexample, III.1],[3, of that values observing dnkis thenumber the We exercise by 2.2.1-4]. can discover required

or decreases either left the component the is a to (1,k), where "decreasing path" anypaththat between there a 1-1correspondence is This because at right component unity eachstep. follows by and the do paths all decreasing from n - 1) to(k,1) that touch diagonal all decreasing paths (n, after the the starting the from n - 1) to (1,k); theidea[1]is toreflect pathabout diagonal, (n, of the a Since number decreasing from b) to it touches diagonal paths (a, point. placewhere first for a > c and b > d, wehave all =(a+b--d) (c,d) is (a+bc-d)
(2n - k2) (2nk

of the pathsfrom n - 1) (n, decreasing pathsfrom n - 1) to (k, 1) minus number decreasing (n,

2)

(2n

-k

2)k-

Furthermorecn-1 = dn2 hence ,


n

(2n - 2)1 n-l Jn n

for numbers function Catalan The series. generating 3. Special power


C(Z) = C1Z+ C2Z2+
=

n - -

4z

use For it best canbe derived many in identity ways. ourpurposes seems tomake ofthegeneral
( ) , + w ( ~~~2k )k=
, /

(~1

w.

numbers it canbe proved holds all Thiswell-known easily contour by w; identity for complex side of right-hand is of The expansion the integration: coefficientzk in theMaclaurin
2 rriI

14z

(1

-2Z I

dz

dt

if we make the substitutions t = 2(1 - v1 - 4z),

of is i.e., integral the residueof the integrand, the coefficient tk in (1 - t)w-k- 1, namely (-w -k - 1)( 1)k = (2k+ '). (A moreelementary in be found [3, exercise can 1.2.6-26].) proof we w to of Thederivative C(z)/z with respect z is C(Z)2/(Z2 1 - 4z); hence canreplace by

z = t - t2, dz = (1 - 2t) dt. The latter

formula the w + 1 in (*) andintegrate, obtaining companion


k+ w k )z (

)w when the is this by w, Again, result validforall complex ifwe evaluate coefficient continuity for function Catalan reducesto the generating k + w = 0. The case w = 1 of this formula earlier. stated numbers
2z

This content downloaded on Sat, 16 Feb 2013 10:04:50 AM All use subject to JSTOR Terms and Conditions

1984]

THE TOILET PAPER PROBLEM

467

z only side the converge IzI < 1/4,because righthand is singular when for These power series when = pq, p > 0, z what toconsider happens It or is infinite V1 - 4z is singular. is interesting
q>O,andp+q=1:Wehave1 -4z=(p-q)2,

hence

1-4z

= Ip - ql = max(p, q) - min(p, q), E

the formula andweobtain interesting


C(pq) =

(2n -2)

pnqn = min(p, q)

limit holds latter byAbel's case, formula alsoin the Wehavepq < 1/4unless = q = 1/2; the p theorem. Let 4. Generating functions. us nowset
M(z)=
n1

, Mn(p)Zn;

L(z) = E, Ln(p)zn.
n>1

to 2 relation M,(p) insection is equivalent for Therecurrence


M(z) - L(z)
=

q-1C(pqz)M(z),

andwealsohave
L(z)
= =

z+ 2
E qklk

_ -l

1k(k
(2k+ kk-i

1)pnk(2n

2)zn

k 2)(qZ)j+k 2j + k - 2 )
pz'

k-l~~k
Eqk>O

lkz

-k 1
jk-E1

sum in 3, latter is Bytheidentity section the


=
=

2qk1kzk

V/l

2pqz

4pqz

k-

Z E kpl-kC(pqz)k-l
k> 0

p Z

(p

C(pqz))2

for a We can noweliminate L(z) and solveforM(z), obtaining "closedform" thedesired function: generating
M(z )
=

C(pqz)

q -

C(pqz))

more! have We we but for form M(z) is unexpected; infact, cando even Sucha simple
(p - C(pqz))(q
- C(pqz)) = pq - C(pqz) +
C(pqZ)2
=

pq(l - z),

because C(z)

of simplified: C(Z)2 = z. Hence thedenominator M(z) can be vastly M(z)= z

q-C(pqz)
c2p2qz2
c3p3q2z3 ** ), so the

This is the product(z + 2Z2 + 3z3 + ***(1-cpz-

of coefficientzn canbe written

This content downloaded on Sat, 16 Feb 2013 10:04:50 AM All use subject to JSTOR Terms and Conditions

468

DONALD E. KNUTH

[October

it havea simple explanation. theauthor But When formula outtobe so simple, must a turns the reason, (p) is notonly expected For proof. some of hasn't beenableto think anydirect M, it one empties,is alsothe expected ofthe value "first return to roll remaining when roll sizeofthe in the paperrollsstart thefullstate in sense:Suppose twotoilet thediagonal," thefollowing state until empty (0,0) is reached; and by are (n, n),andthey used big-choosers little-choosers the
of return (n - k, n - k) foreach k < n, and 1 - clp - * to probability first

for from follows ourformula M (p), because pkqk-l is the value k is Mn(p).(This of average Ck
- pn lq -2

become equal in size again at state(n - k, n - k). Then the and supposethatthe rollsfirst

is until (0, that diagonal notencountered state 0) is reached.) is theprobability the valueoccurs bothproblems? in The that sameexpected the an Is there easywayto prove values thesame. are but mean are distributionsdifferent, the
valueof Mn(p) forfixedp as n -- oo. to deducetheasymptotic function 4pq Let'sassume that # q. Then < 1,andthe first p C(pqz) = 2(1 - 01 - 4pqz) is a of in for analytic lzl < 1/(4pqz); so it is analytic a neighborhood z = 1. In fact, simple

form, areready we simple a M(z) hasbeenputinto fairly behavior. that Now 5. Thelimiting

at z the numbers once that series thepoint = 1 involves Catalan proves itsTaylor computation
again:
C(pqz) = min(p, q) + (max(p, q) -

min(, i(,)C(

q)

pqz -1))
(

)2)

q).) that our observation C(pq) = min(p, generalizes previous (Thisformula to If q < p, ourformula M(z) reduces for
MW z
(I
_

q -p
Z)2 q p (

pq(z -I)
(p -q)

) + C3

z
p

=1l-z
-

P~

C2(pq)3
(

p2q -q

p3q25(-)
p)

) +

1-zp-q

the in f(z) is analytic theregion < 1/(4pq).Thisdetermines valueof Mn(p) quite where IzI accurately:
THEOREM

than4pq. Then 1. Let r be anyvaluegreater


fIPl(P- q) ((q-p)/q)n
+ 0(r n)

+ p/(q-p)

+ O(rn),

ifq < p; ifq > p.

depend p and r, butnoton n.) on formulas by implied 0 in these (The constants of is Proof.If q < p, thevalueof Mn(p) is thecoefficient znin M(z), which p/(p - q) plus of whenz = l/r, henceits nth absolutely thecoefficient zn in f(z). But f(z) converges

coefficient 0(rn). is

from for the If q > p, thestated result follows theformula q < p, using identity
qMn(p) + pn = pMn(q) + qn

4. of for (p) which an immediate is consequence theformula Mn in section QED.


p

n but roll closeto2, when is large; when 2 to 1, theaverage oftheremaining willbe very size
=

outnumber little-choosers by if For example, p = 2/3 and q = 1/3, so thatbig-choosers will jn 1/3 and q = 2/3 theaverage be approximately + 1.

If the larger will roll tend predominate,sizeofthe Thisagrees our with intuition:little-choosers

This content downloaded on Sat, 16 Feb 2013 10:04:50 AM All use subject to JSTOR Terms and Conditions

1984]

THE TOILET PAPER PROBLEM

469

are the roll to tobe proportionaln,when smaller is usedup.Butifbig-choosers in themajority, size of initial n. size, to to the larger will roll tend be reduced a bounded independentthe of about boundary p = q? Does itleadtolengths the 6. Thetransition Butwhat point. case, in 1, order ororder orsomethingbetween? n, that to case because = q = 1/2is equivalent saying p Thisis actually simplest toanalyze, the "random walk." fact, In simple is reduces a fairly to the everybodya random-chooser;problem [2, by as match problem" discussed Feller box with "Banach's dealing here we areessentially function this is simply in case formula, generating the to According ourgeneral IX.3(f)]. ~z
M(Z) Z)(1
)3/72

form: is in so there a solution closed


Mn( 1)= (-3/2)(_1)n-1
= 2n(2n)

following result: we approximationhavethe ByStirling's


THEoREM 2.

Mn(p) = 2

'IT

4i

rn-

+ O(n3-3/2

when = q. p

in 2n The function Mn(p) is a polynomial p of degree - 3, forn > 2, and it decreases from to thing from monotonically n down 1 as p increases 0 to 1. Theremarkable aboutthis when rather in it 1/2. suddenly p passes decrease that changes character is 1 of We can'tusetheformulas Theorem when is too closeto 1/2,evenif n is extremely p
100

80

60

40

.0

.1

.2

.3

.4

.5

.6

.7

.8

.9

1.0

This content downloaded on Sat, 16 Feb 2013 10:04:50 AM All use subject to JSTOR Terms and Conditions

470

GEORGE BOOLOS

[October

1 in if large.For example, n = 1010 and p = 1 + 10-20, bothapproximations Theorem givethe (1/2) is of orderVn,so the estimate ridiculous Mn(p) = I X 1020. Indeed,we knowthat Mn is of order1/ n at least. can approximations be validonlywhenIP P to M(z) by The slope of Mn(p) at p = 1/2 can be calculated differentiating withrespect p of is the and extracting coefficient zn. The derivative z
(l_z)2

dp

d (C(p(1-p)z

1- p

z
(1_ z)2 ( (1- 2p)zC'(p(I -P -p)z) Hence + C(p(I -p)z) ~(1-_p)2

and at p

1/2 thisequals -2z(1

_ z)-2

+ 2z(l

z)-3/2.

Mn(1/2) = -2n + 2Mn(1/2); 0 fromn to a smallvalue as p goes from to 1/2. The withMn(p) dropping thisis consistent graphof Mloo(p) is shownon page 469.
University for science building Stanford at of the I wish Acknowledgements. to thank architect thecomputer of that for and Beigel theinsight led to theclosedform L(z). Andrei this suggesting problem, Richard implicitly in was the of comments computed graph Mloo(p). My research supported partby and offered Broder helpful MCS-83-00984. Foundation grant National Science References 105 Acad.Sci. Paris, Rendus, Comptes resolu M. Bertrand, par du directe probkme Solution 1. DesireAndre, (1887)436-437. NewYork, vol. and to Theory itsApplications, 1,2nded.,Wiley, Feller, IntroductionProbability An 2. William 1957. Addison-Wesley, Algorithms, vol. Programming, 1: Fundamental The 3. DonaldE. Knuth, Artof Computer xxii+ 634pp. MA,1968, Reading,

THE LOGIC OF PROVABILITY


GEORGE BOOLOS MA Cambridge, 02139 of InstituteTechnology, Massachusetts and ofLinguistics Philosophy, Department

by first of branch logic, investigated an in way which ancient article the is of Thesubject this of of on to light a branch logic been has as logic, recently found shed and Aristotle known modal by begun DavidHilbert itself, study the date, mathematical ofmathematics a study later much Godel. to by andbrought fruition Kurt a and of in studied modallogicare those necessity possibility: concepts The fundamental since be if Thus, and be if "necessary"it must true, "possible" it might true. is statementcalled but is in will "there be a war 2000" possible, the year be might a warinthe there 2000, statement " there will the On other hand, statement notbe a warthen. the might as itis notnecessary,there
was where supervisor Raymond my at degree an After undergraduate in mathematicsPrinceton, Boolos: George a everto receive Ph.D. in person I at in and degree philosophy Oxford, becamethefirst Smullyan, a graduate yearsat for I Putnam. taught three under Hilary theory on a MIT, writing thesis hierarchy from philosophy to In of I to and Columbia in 1969returned MIT, where am nowa professor philosophy. addition a bookon the with and Computability Logic(co-authored and ofConsistency, a textbook, The article, Unprovability topicof this in a of I have Jeffrey), writtennumber articles logicandphilosophy. Richard

This content downloaded on Sat, 16 Feb 2013 10:04:50 AM All use subject to JSTOR Terms and Conditions

You might also like