TOPICS
Search

Random String Loop Problem


The random string loop problem asks for the discrete distribution of the number L_n of closed loops formed from n open strings by repeatedly choosing two distinct loose ends uniformly at random and tying them together (Blitzstein and Hwang 2014, p. 183). The sequence of ties gives a uniformly random perfect matching of the 2n original ends. There are (2n-1)!! such matchings, where (2n-1)!! is a double factorial.

When j open strings remain, exactly one of the 2j-1 possible partners of the first chosen end closes a loop. Each tie reduces the number of open strings by one, whether it closes a loop or joins two strings into a single open string. Since the conditional probability of closing a loop is 1/(2j-1) for every history of the preceding ties, the loop closure events are independent. The expectation value is

 E[L_n]=sum_(j=1)^n1/(2j-1)=H_(2n)-(H_n)/2,
(1)

where H_n is a harmonic number. For 50 strings, the expectation value is approximately 2.93777 (3Blue1Brown 2026).

The probability generating function of L_n is

 E[x^(L_n)]=product_(j=1)^n(x+2j-2)/(2j-1).
(2)

Expanding the numerator and using the unsigned Stirling numbers of the first kind |s(n,k)| gives the probability mass function

 P(L_n=k)=(2^(n-k)|s(n,k)|)/((2n-1)!!)
(3)

for 1<=k<=n, with probability zero otherwise. For n=0, the probability of L_0=0 is 1. The numerator counts the matchings that give k loops. For n=4, the counts for k=1, 2, 3, and 4 are 48, 44, 12, and 1 (OEIS A039683, absolute values of row 4).


See also

Harmonic Number, Perfect Matching, Stirling Number of the First Kind

Explore with Wolfram|Alpha

References

3Blue1Brown. "Tie Random Ends: How Many Loops?" YouTube. May 21, 2026. https://www.youtube.com/watch?v=ZHXt0-_gSj4.Blitzstein, J. K. and Hwang, J. Introduction to Probability. Boca Raton, FL: CRC Press, 2014. Selected solutions: https://stat110.hsites.harvard.edu/resource/selectedsolutionsblitzsteinhwangprobabilitypdf#page=33.Sloane, N. J. A. Sequence A039683 in "The On-Line Encyclopedia of Integer Sequences."

Cite this as:

Weisstein, Eric W. "Random String Loop Problem." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/RandomStringLoopProblem.html

Subject classifications