Pick up sticks

Larry Shepp, Doron Zeilberger, Cun-Hui Zhang

October 22, 2012

1 Introduction

Break a ruler of length n inches with indentations at each inchmark into n sticks of length one by repeatedly picking up all the fragments which are still of length greater than one and throwing them down all at once until all the sticks are of length one. Assume that each stick breaks into exactly two sticks uniformly at the inchmarks. What is the expected number of throws needed to complete the n − 1 breaks?

We show that the answer to this question is (4.31107 …) · ln n · (1 + o(1)) by, as mathematicians are fond of doing, reducing it to an already solved problem. The problem that we reduce it to-or rather show that it is almost trivially equivalent to- is the problem of finding the asymptotic average height of a binary search tree. The latter problem was first solved by Luc Devroye[D], with a later refinement by Bruce Reed[Re].

We also present a possibly new (and we hope elegant) proof that (4.31107 …)·ln n ·(1+o(1)) is an upper bound , first proved in 1979 by Robson[Ro]. Our approach is to first prove a simple generating function for the number of throws needed to isolate the j\underline{th} stick and then use Chernoff’s inequality. The constant α = 4.31107 … is the root of α ln(2e/α) = 1.

The worst case, if you are extremely unlucky, requires n − 1 throws. In this case, first the stick breaks into a one-inch piece and an (n − 1)-inch piece, then the next throw breaks the (n − 1)-inch stick into a one-inch piece and an (n − 2)-inch piece and so on.

The best case (if n = 2^{k}) is log_{2} n. First it breaks into two equal pieces each of length n/2 inches, then into four pieces each of length n/4 inches etc., and in k = log_{2} n throws into n one-inch pieces.

But if you do it many times, and n is large, what is the expected number of throws? As we have already stated, the answer is (4.31107 …) · (ln n) · (1 + o(1)), so the ratio of the asymptotic average to the best case is only (4.31107 …) · ln 2 · (1 + o(1)) = 2.98821 + o(1).

Recall that a full binary tree is a “family tree” (but with single-parenthood), with a root (Eve), and where every vertex either has two children (called the left-child and the rightchild) or no children at all. Childless vertices are called leaves. The height of a full binary tree is the length of a maximal path from the root to a leaf.

Each scenario of completely breaking an n-inch stick into n one-inch pieces can be naturally associated with a full binary tree with n leaves. The first drop of the interval [0, n] results either in [0, 1] and [1, n], or [0, 2] and [2, n], …, or [0, n − 1] and [n − 1, n]. Now each of the two pieces goes its own way, generating its own full binary subtree. Of course, the “number of throws needed to completely break the stick” is the height of the corresponding full binary tree.

To see all the 14 breaking scenarios for a five-inch ruler go to:

http://www.math.rutgers.edu/~zeilberg/shepp/S5.html .

To see all the 42 breaking scenarios for a six-inch ruler go to:

http://www.math.rutgers.edu/~zeilberg/shepp/S6.html .

Now to each internal vertex (i.e. a vertex that is not a leaf) assign the label “number of leaves in the subtree whose root it is”. It is obvious that the probability of the breaking scenario corresponding to any given full binary tree is the product of 1/(i − 1) over all the labels of non-leaves, since a stick of length i may be broken into two smaller pieces in i − 1 equally likely ways.

So the expectation of the random variable “number of throws needed to completely break an n-inch ruler” is nothing but the expected height of all full binary trees with n leaves, under the above probability distribution. Let’s call it a(n).

Recall (or go to wikipedia) that any list of n different numbers gives rise to a binary search tree of n vertices where the first record, let’s call it i_{1} is put at the root, and its left (respectively right) subtree consists, recursively of the binary search tree of the sublist (in the same order) consisting of all entries smaller (respectively larger) than i_{1}. If a list is empty, then it corresponds to the empty tree with no vertices.

For example, the binary search tree corresponding to the permutation [4, 3, 9, 1, 5, 6, 2, 11, 7, 8, 10, 12] can be seen here:

http://www.math.rutgers.edu/~zeilberg/shepp/BS12.html .

It is obvious that a binary search tree corresponds to a (not-necesssarily full) binary tree, where every vertex may either have no children, or only a left-child, or only a right-child, or both left- and right-children with n vertices.

To see all the 14 binary search trees for the four records {1, 2, 3, 4} go to:

http://www.math.rutgers.edu/~zeilberg/shepp/BS4.html .

To see all the 42 binary search trees for the five records {1, 2, 3, 4, 5} go to:

http://www.math.rutgers.edu/~zeilberg/shepp/BS5.html .

If you pick a permutation of {1, …, n} uniformly at random, it is clear that the probability of it having a certain binary search tree is simply the product of 1/i(v), over all vertices v of the tree, where i(v) is defined to be “the number of vertices in the subtree rooted at v”. For example, the probability of the tree shown in:

http://www.math.rutgers.edu/~zeilberg/shepp/BS12.html .

is

(1/12)(1/3)(1/2)(1/1)(1/8)(1/4)(1/3)(1/2)(1/1)(1/3)(1/1)(1/1) .

This is the probability assigned to a random binary search tree, and the average is defined according to that probability distribution.

In a famous paper in theoretical computer science, Bruce Reed[Re] improved on a seminal paper of Luc Devroye[D] (who only had the highest-order asymptotics) by proving that if b(n) is the average height of binary tree with n vertices under the above probability distribution, then

b(n) = α ln n − β ln ln n + O(1) ,

where α = 4.31107 … is the unique root in [2, ∞) of the equation

α ln((2e)/α) = 1 ,

and β = 1.953 . . ..

We are almost done! It is trivial to see (e.g. by induction) that a full binary tree with n leaves has n − 1 internal vertices (i.e. non-leaves). There is a well-known, obvious, bijection between binary trees with n − 1 vertices to full binary trees with n leaves. If a vertex has both children leave it alone. If it only has a left-child, create for it a right-child that is a leaf. If it only has a right-child, create for it a left-child that is a leaf. If it has no children (i.e. is a leaf in the original tree), create for it both a left- and right-child, both leaves. To go back is even easier! Remove all the leaves!

By removing all the leaves, the height gets reduced by one, (and all the labels as well, but the probability stays the same, due to the different definitions in both cases) so we have the following relation between the stick problem and the well-known average height of a random search tree problem:

a(n) = b(n − 1) + 1 .

Of course, the asymptotics of a(n) is the same as that of b(n).

2 A Quick Proof of the Upper Bound

We now give a quick argument that reproves the inequality a(n) ≤ α ln n · (1 + o(1)), first proved by Robson[Ro], thereby proving half of the Devroye result.

We hope, in the future, to extend our approach to proving the other half, namely a(n) ≥ α ln n · (1 + o(1)), thereby yielding a hopefully simpler proof, or at least an alternative one, of Devroye’s result.

2.1 The generating function for the time to isolate the j\underline{th} stick

Let τ_{j,n}, j = 1, …, n denote the number of throws needed until the j\underline{th} inch stick is isolated and let f_{j,n}(ρ) denote the generating function of τ_{j,n},

f_{j,n}(ρ) = 𝔼 [ρ^{τ_{j,n}}] .

It is clear that f_{1,1}(ρ) = 1, since τ_{1,1} = 0, and that the recurrence,

f_{1,n} = \frac{1}{n − 1} ∑_{k=1}^{n−1} ρf_{1,k}(ρ)

holds for the generating function of the number of throws needed to isolate the first stick. An easy induction shows that

f_{1,n}(ρ) = ∏_{l=1}^{n−1}(1 + \frac{ρ − 1}{l}).

Since the number of throws to isolate the j\underline{th} stick is the sum of the number of throws needed until the first break at j − 1 plus the number until the first break at the j\underline{th} inchmark, and these numbers are independent, so we see that f_{j,n}(ρ) = f_{1,j−1}(ρ)f_{1,n−j}(ρ) which gives the general result that

f_{j,n}(ρ) = ∏_{l=1}^{j−1}(1 + \frac{ρ − 1}{l}) ∏_{l′=1}^{n−j}(1 + \frac{ρ − 1}{l′}).

2.2 Expectation

We now prove that the expected total number of throws needed to completely break the stick is no greater than

α ln(n + 1) − 1.

Since max_{j≤n} τ_{j,n} is the number of throws needed, this assertion is equivalent to

∑_{x=1}^{n−1} P { max_{j≤n} τ_{j,n} ≥ x} ≤ α ln(n + 1) − 1.

The explicit formula of the generating function allows us to apply the Chernoff bound

P (τ_{j,n} > x) ≤ ρ^{−x}f_{j,n}(ρ)

to each τ_{j,n}. Let m = (n + 1)/2. For ρ ≥ 2, (1 + (ρ − 1)/k) ≤ (1 + 1/k)^{ρ−1}, so that

f(ρ) ≤ \{∏_{l=1}^{j−1} (1 + \frac{1}{l}) ∏_{l′=1}^{n−j} (1 + \frac{1}{l′})\}^{ρ−1} = \{j(n − j + 1)\}^{ρ−1} ≤ m^{2ρ−2}.

Let x > α ln m, y = x/ ln m and ρ = y/2. Since ρ > α/2 > 2,

P ( max_{j≤n} τ_{j,n} ≥ x) ≤ ∑_{j=1}^{n} ρ^{−x}f_{j,n}(ρ)

≤ 2 exp (ln m − y ln m ln ρ + (2ρ − 2) ln m)
= 2 exp ((−1 + y ln(2e/y)) ln m) .

Since (d/dt)((−1 + t ln(2e/t)) = ln(2/t) ≤ ln(2/α) for α ≤ t ≤ y,

(−1 + y ln(2e/y)) ln m ≤ (y − α) ln(2/α) ln m = (x − α ln m) ln(2/α).

It follows that P ( max_{j≤n} τ_{j,n} ≥ x) ≤ 2(2/α)^{x−α ln m}. Let u be the decimal part of α ln m − ln 2/ ln(2/α). We find

∑_{x=1}^{n−1} P ( max_{j≤n} τ_{j,n} ≥ x) ≤ ∑_{x=1}^{n−1} min {1, 2(2/α)^{x−α ln m}}
≤ α ln m − ln 2/ ln(2/α) − u + ∑_{k=1}^{∞}(2/α)^{k−u}.

Since the function −u + ∑_{k=1}^{∞}(2/α)^{k−u} is convex in u ∈ [0, 1] and takes a greater value at u = 1 than u = 0, its maximum, 1/(1 − 2/α) − 1 = 2/(α − 2), is attained at u = 1. Consequently, the expectation of max_{j≤n} τ_{j,n} is no greater than

α ln(n + 1) − α ln 2 − ln 2/ ln(2/α) + 2/(α − 2).

The conclusion follows from −α ln 2 − ln 2/ ln(2/α) + 2/(α − 2) < −1.

A slightly different simple argument using the Poisson dominance of Bernoulli yields an upper bound with the ln ln n term:

E max_{j≤n} τ_{j,n} ≤ α ln n − (β/3) ln ln n + O(1)

with β = (3/2)/ log(α/2) = 1.953026. However, the coefficient for the second order term, β/3, is not sharp according Reed’s refinement of Devroye’s result that states that

Remark. The individual times, τ_{j}, are rather smaller than the maximum of the τ’s. Indeed, using the generating function of τ_{j} it is not hard to show that as n → ∞,

τ_{j} = 2 log n + \sqrt{2 log n}η_{j} + o(\sqrt{logn})

where η_{j} is standard normal random variable. Thus, it is only the relative independence of the τ’s that allows the maximum to be as large as in Reed’s theorem, ∼ 4.13 … log n.

Acknowledgement: The stick problem was inspired by the interesting paper [IK].

3 Maple Packages

This article is accompanied by two Maple packges for experimenting, and simulating, both binary trees under the uniform distribution (not discussed in this article), and for the stick problem (alias binary search trees). The most important one is BinaryTrees and the lesser one is ArbresBinaires. There is yet another Maple package, EtzBinary, mainly for plotting, and that’s how we drew the pictures linked to above. All three packages, as well as some sample input and output files, can be gotten from the “front” of this article:

http://www.math.rutgers.edu/~zeilberg/mamarim/mamarimhtml/stick.html .

4 References

[D] Luc Devroye, A note on the height of a binary search tree, J. of the ACM 33(3) (July 1989), 489-493.

[IK] Yoshiaki Itoh and P. L. Krapivsky, Continuum cascade model of directed random graphs:

traveling wave analysis, http://arxiv.org/abs/1206.3711 .

[Re] Bruce Reed, The height of a random binary search tree, Journal of the ACM 50 (2003), 306-332.

[Ro] J.M. Robson, The height of binary search trees, Aust. Computing J. 11 (1979), 151-153.

Lawrence Shepp, Wharton School, University of Pennsylvania, shepp@wharton.upenn.edu Doron Zeilberger, Department of Mathematics, Rutgers University, zeilberg@math.rutgers.edu Cun-Hui Zhang, Department of Statistics, Rutgers University, czhang@stat.rutgers.edu