Skip to content
Vamshi Jandhyala

Mathematics

Fifty Strings in a Box

PDF

A MoMath Monthly Mindbender: fifty strings have their loose ends tied at random until none remain. The expected number of loops is 1 + 1/3 + 1/5 + ... + 1/99 = 2.938, a shade under three. Since that sum is H(2n) - H(n)/2, the count grows only like half a logarithm, so even a thousand strings average fewer than five loops.

Problem

To keep your visiting five-year-old niece busy, you mix 50 strings of orange yarn in a box and ask her to successively grab two random ends and tie them together until there are no loose ends remaining. The result will of course be some number of loops of string. How many, on average?

Credit: Peter Winkler, Monthly Mindbenders, National Museum of Mathematics, May 2026, a variation of a classic.

One tie at a time

Write LnL_n for the expected number of loops made from nn strings. A box of nn strings holds 2n2n loose ends, every tie consumes two of them, so there are exactly nn ties and the box always finishes with nothing loose in it.

Look at the first tie. Pick up any end at all; by symmetry it does not matter which one, since nothing has been tied yet and the ends are interchangeable. That end gets joined to one of the other 2n12n-1 ends, each equally likely. Exactly one of those candidates is the other end of the same piece of string, and that single case behaves quite differently from the rest.

  • With probability 12n1\frac{1}{2n-1} the end meets its own partner. The string closes into a loop, the loop leaves the box, and it is never touched again. One loop completed, n1n-1 strings remaining.
  • With probability 2n22n1\frac{2n-2}{2n-1} the end meets an end belonging to a different string. The two strings become one longer string with two free ends. No loop completed, and again n1n-1 strings remaining.

Both branches leave n1n-1 strings in the box, each with two free ends. Nothing about what happens next depends on how long any of those strings is, or on which ties produced it, so the process simply restarts on n1n-1 strings and the expected number of loops still to come is Ln1L_{n-1} either way. Conditioning on the first tie,

Ln=12n1(1+Ln1)+2n22n1Ln1=12n1+Ln1.L_n = \frac{1}{2n-1}\bigl(1 + L_{n-1}\bigr) + \frac{2n-2}{2n-1}\,L_{n-1} = \frac{1}{2n-1} + L_{n-1}.

That self-similarity is the whole of the argument, and it is also why the answer is a plain sum of reciprocals rather than something more intricate. The state of the box is captured by a single number, the count of strings, and each tie reduces that count by one at a cost depending on nothing else.

With L0=0L_0 = 0 the recursion telescopes:

Ln=k=1n12k1.L_n = \sum_{k=1}^{n}\frac{1}{2k-1}.

For the niece’s box of fifty,

L50=1+13+15++199=k=15012k12.93777,L_{50} = 1 + \frac13 + \frac15 + \cdots + \frac{1}{99} = \sum_{k=1}^{50}\frac{1}{2k-1} \approx 2.93777,

a shade under three loops from fifty strings and fifty ties.

The same sum without induction

Linearity of expectation reaches the answer in one line, and the counting is worth seeing on its own. Number the ties by the state they act on: some tie takes the box from kk strings down to k1k-1 strings, for each kk from nn down to 11. At that tie the box holds 2k2k ends, the chosen end has 2k12k-1 possible partners, and exactly one of them closes a loop. Let XkX_k be the indicator of that event, so P(Xk=1)=1/(2k1)\mathbb{P}(X_k = 1) = 1/(2k-1).

Every loop is closed by exactly one tie, so the total number of loops is kXk\sum_k X_k. Expectation adds regardless of dependence:

E[k=1nXk]=k=1n12k1.\mathbb{E}\Bigl[\sum_{k=1}^{n} X_k\Bigr] = \sum_{k=1}^{n}\frac{1}{2k-1}.

The logarithmic crawl

Sums of odd reciprocals reduce to harmonic numbers. The even terms 12+14++12n\tfrac12 + \tfrac14 + \cdots + \tfrac{1}{2n} are 12Hn\tfrac12 H_n, so removing them from H2nH_{2n} leaves the odd ones:

Ln=k=1n12k1=H2n12Hn.L_n = \sum_{k=1}^{n}\frac{1}{2k-1} = H_{2n} - \tfrac12 H_n.

Substituting Hm=lnm+γ+O(1/m)H_m = \ln m + \gamma + O(1/m),

Ln=ln(2n)+γ12(lnn+γ)+O(1/n)=12lnn+ln2+γ2+O(1/n),L_n = \ln(2n) + \gamma - \tfrac12\bigl(\ln n + \gamma\bigr) + O(1/n) = \tfrac12\ln n + \ln 2 + \tfrac{\gamma}{2} + O(1/n),

with constant ln2+γ/2=0.693147+0.288608=0.981755\ln 2 + \gamma/2 = 0.693147 + 0.288608 = 0.981755. At fifty the approximation returns 2.9377672.937767 against the exact 2.9377752.937775, an error in the sixth decimal place.

Half a logarithm is very slow growth, and that is the part worth sitting with. Doubling the number of strings adds 12ln20.347\tfrac12\ln 2 \approx 0.347 to the expected count, so each additional loop costs roughly a sevenfold increase in yarn. A thousand strings average 4.444.44 loops. A box would need something like a hundred thousand strings before the expected count reached seven.

nn12510501001000
LnL_n1.00001.00001.33331.33331.78731.78732.13332.13332.93782.93783.28433.28434.43564.4356
Two panels on cream. Left: a histogram of the number of loops formed from fifty strings across 200,000 simulated trials, with bars at one through eight loops; three and two loops are the tallest at roughly 58,000 and 56,000 trials, four is next, and the counts fall away sharply beyond six. A dashed copper vertical line at 2.9378 marks the exact mean. Right: the expected number of loops L_n plotted against the number of strings n on a logarithmic horizontal axis running from 1 to 1000. The exact sum is a solid copper line and the asymptote one-half ln n plus ln 2 plus gamma over 2 is a dashed green line lying on top of it; the curve is almost a straight line on the log axis, rising from 1.0 at n = 1 to only 4.44 at n = 1000, with a black dot marking n = 50 at 2.938.
Left: the simulated number of loops from fifty strings, with the exact mean $2.9378$ dashed in copper; almost every box yields between one and six loops. Right: $L_n$ against $n$ on a logarithmic axis, with the asymptote $\tfrac12\ln n + \ln 2 + \gamma/2$ indistinguishable from it beyond the first few values.

The whole distribution, not just the mean

One further remark comes free. The indicators XkX_k are independent, because the conditional probability 1/(2k1)1/(2k-1) never depended on what the earlier ties did. So the number of loops is a sum of nn independent coin flips with success probabilities 1,13,15,,12n11, \tfrac13, \tfrac15, \ldots, \tfrac{1}{2n-1}, and convolving them gives the exact distribution.

loops123456
probability0.12560.12560.28140.28140.28960.28960.18440.18440.08230.08230.02760.0276

Six loops or fewer covers 99.799.7 per cent of boxes, and the standard deviation is 1.3071.307. The niece is very likely to hand back a small handful, and about one time in eight a single loop of yarn some fifty strings long.

Computational verification

The recursion is short enough to be suspicious of, so the check ignores it and plays the game instead. Shuffle the 2n2n ends into a random pairing, walk through the pairs, and keep a disjoint-set structure over the strings: if the two ends already belong to the same string then a loop has closed, otherwise the two strings merge into one. Nothing in the simulation knows about 1/(2k1)1/(2k-1).

import numpy as np

L = lambda n: sum(1.0/(2*k-1) for k in range(1, n+1))  # 1 + 1/3 + ... + 1/(2n-1)
G = 0.5772156649015329                                 # Euler-Mascheroni
asym = lambda n: 0.5*np.log(n) + np.log(2) + G/2

def simulate(n, trials, rng):       # shuffle 2n ends, tie in pairs, count loops
    total = 0
    for _ in range(trials):
        parent = list(range(n))     # disjoint set over the strings in the box
        def find(x):
            while parent[x] != x:
                parent[x] = parent[parent[x]]; x = parent[x]
            return x
        # ends 2i and 2i+1 are the two ends of string i
        for a, b in rng.permutation(2*n).reshape(-1, 2):
            ra, rb = find(a//2), find(b//2)
            if ra == rb: total += 1 # both ends of one string: a loop closes
            else: parent[ra] = rb   # two strings merge into one longer string
    return total/trials

rng = np.random.default_rng(20260516)
print(f"exact  L_50 = {L(50):.6f}")
print(f"sim    L_50 = {simulate(50, 40_000, rng):.6f}   (40,000 trials)")
print(f"asymp  L_50 = {asym(50):.6f}   ln2 + gamma/2 = {np.log(2)+G/2:.6f}")
for n in (1, 2, 5, 10, 50, 100, 1000):
    print(f"  n = {n:4d}   L_n = {L(n):.6f}   asymptotic = {asym(n):.6f}")

# exact  L_50 = 2.937775
# sim    L_50 = 2.934200   (40,000 trials)
# asymp  L_50 = 2.937767   ln2 + gamma/2 = 0.981755
#   n =    1   L_n = 1.000000   asymptotic = 0.981755
#   n =    2   L_n = 1.333333   asymptotic = 1.328329
#   n =    5   L_n = 1.787302   asymptotic = 1.786474
#   n =   10   L_n = 2.133256   asymptotic = 2.133048
#   n =   50   L_n = 2.937775   asymptotic = 2.937767
#   n =  100   L_n = 3.284342   asymptotic = 3.284340
#   n = 1000   L_n = 4.435633   asymptotic = 4.435633

Forty thousand simulated boxes give 2.93422.9342 against the exact 2.93782.9378, a discrepancy of 0.00360.0036 against a standard error of 1.307/40000=0.00651.307/\sqrt{40000} = 0.0065.

The puzzle is usually told with a specific number of strings, and the number invites you to guess. Fifty strings sounds like it should give a decent pile of loops. It gives about three, and ten times as much yarn would give about four and a half.