AA path formula for the sock sorting problem
Simon Korbel and Peter M¨orters
Institut f¨ur MathematikUniversit¨at zu K¨olnWeyertal 86-9050931 K¨olnGermany
Summary.
Suppose n different pairs of socks are put in a tumble dryer. Whenthe dryer is finished socks are taken out one by one, if a sock matches one of thesocks on the sorting table both are removed, otherwise it is put on the table untilits partner emerges from the dryer. We note the number of socks on the table aftereach of the 2 n socks is taken from the dryer and give an explicit formula for theprobability that this sequence equals a given sequence of length 2 n . Suppose that n different pairs of socks are put in a tumble dryer. After operating thedryer the socks are taken out one by one, if a sock matches one of the socks on the sortingtable both are removed, otherwise it is put on the table until its partner emerges fromthe dryer. Let X k , k = 1 , . . . , n be the number of socks on the table when the k th sockis taken from the dryer. How can we describe this process?This problem was known to Daniel Bernoulli [1] who calculated the expectation of X k .It is also not hard to calculate the variance of X k and derive a law of large numbersas n → ∞ , see [3]. Some more work allows the derivation of a functional central limittheorem [4], and to determine the asymptotic maximum of the process [6]. But the focushere is on combinatorial, and in particular limit free, results.An observation one can find in the literature [2, 5] is that the paths of our process( X , . . . , X n ) are Dyck paths and therefore can be enumerated by the Catalan numbers.This observation, however, is not really useful for the sock sorting problem, as differentpaths have different probabilities, see for example Table 1. We therefore go back to aLaplace experiment, by making all socks distinguishable, and use this to derive a formulafor the probability of each path. A path ( x , . . . , x n ) is a Dyck path if x = 1, | x i − x i +1 | = 1, x i (cid:62) (cid:54) i (cid:54) n − x n = 0. a r X i v : . [ m a t h . P R ] S e p o state our formula, we first reduce our path to length n by only noting the number K i , i = 1 , . . . , n of socks on the table when the i th pair is matched. Note that the path( X , . . . , X n ) has n upward and n downward steps. ( K , . . . , K n ) represent the heightsof the path from which each downward step is taken. The full path can be reconstructedfrom ( K , . . . , K n ), see Lemma 2 below. Our result is the following. Theorem.
If ( k , k , . . . , k n ) ∈ N n satisfies k i +1 (cid:62) k i − (cid:54) i < n and k n = 1 , (1)then P ( K = k , K = k , . . . , K n = k n ) = 2 n n ! (cid:81) ni =1 k i (2 n )! . Otherwise, if ( k , k , . . . , k n ) ∈ N n does not satisfy (1), the probability is zero.For illustration purposes, here is a table of the resulting probabilities of all paths of lengthten, characterised by the tuples ( k , k , k , k , k ) satisfying (1). n-tuple P ( ... ) number of n-tuples P P ( ... )(54321) ≈ . ≈ . ≈ . ≈ . , (34321) ≈ . ≈ . ≈ . ≈ . , (14321) ≈ . ≈ . ≈ . ≈ . , (32321) , (23321) ≈ . ≈ . , (13321) ≈ . ≈ . , (23221) , (22321) ≈ . ≈ . , (32121) , (23211)(21321) , (13221) , (12321) ≈ . ≈ . , (13211) , (11321) ≈ . ≈ . ≈ . ≈ . ≈ . ≈ . , (22121) , (21221)(12221) ≈ . ≈ . , (21211) , (21121)(12211) , (12121) , (11221) ≈ . ≈ . , (12111) , (11211)(11121) ≈ . ≈ , ≈ . ≈ . Figure 1: Probability of paths of length ten. The probability of a path depends on thetuple ( k , k , k , k , k ) but not on the order of the entries in a tuple.2 Derivation of the result
For a formal definition of ( K , . . . , K n ) we suppose x = ( x , . . . , x n ) is a given Dyck path.Then we define L ( x ) = 0 and for j = 1 , . . . , n inductively L j ( x ) = min { i > L j − ( x ) : x i +1 = x i − } and K j ( x ) = x L j ( x ) . See Figure 2 for an illustration. L ( x ) = 2 L ( x ) = 6 L ( x ) = 7 L ( x ) = 8 L ( x ) = 9 K ( x ) = 2 K ( x ) = 4 K ( x ) = 3 K ( x ) = 2 K ( x ) = 1 Figure 2: The path of length ten characterised by the tuple (2 , , , , Lemma 1
If ( x , . . . , x n ) is a Dyck path and K i ( x ) = k i , then ( k , k , . . . , k n ) satisfies (1). Proof.
Suppose ( x , . . . , x n ) is a given Dyck path. Then L ( x ) , . . . , L n ( x ) are the orderedelements of the set { i ∈ { , . . . , n − } : x i +1 = x i − } . In particular, as x n − = 1 and x n = 0, we have L n ( x ) = 2 n − K n ( x ) = 1.Further, by construction, if L i ( x ) < j < L i +1 ( x ), then x j +1 = x j + 1. Hence, K i +1 ( x ) = x L i +1 ( x ) = x L i ( x ) + L i +1 ( x ) − (cid:88) j = L i ( x ) ( x j +1 − x j )= K i ( x ) − L i +1 ( x ) − L i ( x ) − (cid:62) K i ( x ) − , for i ∈ { , . . . , n − } . This shows that ( k , k , . . . , k n ) satisfies (1).We now show how to reconstruct the Dyck path given ( k , k , . . . , k n ). Lemma 1 and theconstruction together establish a bijection between the Dyck paths of length 2 n and thetuples ( k , k , . . . , k n ) satisfying (1). In particular, the cardinality of the set of such tuplesis also given by the Catalan numbers. Lemma 2
If ( k , k , . . . , k n ) ∈ N n satisfies (1), then x = ( x , . . . , x n ) given by x i = i if i (cid:54) k , x k j +2 j − i = k j − i if k j − i (cid:54) k j +1 for j = 1 , . . . , n .is the unique Dyck path with K i ( x ) = k i . 3 roof. Suppose ( k , . . . , k n ) satisfies (1) and set k = 1. We first check that x asdefined in the lemma is a Dyck path. By definition we have x m +1 − x m = 1 except when m = k j + 2 j − i for j ∈ { , . . . , n } and i (cid:62) k j − i = k j +1 , in which case x m +1 = x k j +2 j + i = x k j +1 +2( j +1) − = k j +1 − k j − i = x m − . Hence x has only increments ± x m +1 = x m − x m +1 = x m − k j +1 − (cid:62) . Moreover, as 1 (cid:54) k we have x = 1 and, as 2 n = k n + 2 n − x n = k n − x is a Dyck path.We note from the above that L ( x ) , . . . , L n ( x ) are the ordered elements of the set (cid:8) m : m = k j + 2 j − i for i, j with k j − i = k j +1 (cid:9) . For every j ∈ { , . . . , n − } there is exactly one element in this set which, as k j + 2 j − i = k j +1 + 2 j < k j +1 + 2( j + 1) − , is then the ( j + 1)-smallest element. Hence L j +1 ( x ) = k j + 2 j − i and K j +1 ( x ) = x L j +1 ( x ) = x k j +2 j − i = k j − i = k j +1 . It remains to show uniqueness. Suppose x = ( x , . . . , x n ) and˜ x = ( x , . . . , x m − , ˜ x m , . . . , ˜ x n )are distinct Dyck paths and m ∈ { , . . . , n − } is the index of the first step at whichthey are different. Without loss of generality we may assume that x m = x m − − x m = x m − + 1. Then there exists j ∈ { , . . . , n } with L j ( x ) = m − L j (˜ x ) > L j ( x ).We infer that K j ( x ) = x L j ( x ) = x m − but K j (˜ x ) = x m − + ( L j (˜ x ) − L j ( x )) > x m − , showing that K j ( x ) (cid:54) = K j (˜ x ) and thereby implying uniqueness.We now look at the probability space Ω n consisting of all permutations of 2 n distinguish-able socks. In our model each of the (2 n )! elements is equally likely. If we write the setof socks as { , . . . , n } × { , } , with 0 , ω = ( ω , . . . , ω n ) ∈ Ω n are the socks in the order drawn from the dryer. Write ω m = ( s m , p m ) ∈ { , . . . , n }×{ , } where s m denotes the type of the sock found in the m th draw and p m indicates whetherit is the left or right partner. We set s = 0 and x = 0 and define x m = (cid:26) x m − + 1 if s m (cid:54)∈ { , . . . , s m − } ,x m − − s m ∈ { , . . . , s m − } , x ( ω ) = ( x , . . . , x n ) is the Dyck path associated with ω . Our theoremnow follows directly from the following lemma. Lemma 3
If ( k , k , . . . , k n ) ∈ N n satisfies (1), then there are exactly 2 n n ! (cid:81) ni =1 k i differentelements ω ∈ Ω n with K i ( x ( ω )) = k i . Proof.
Suppose ( k , k , . . . , k n ) is given and ( x , . . . , x n ) is the unique Dyck path with K i ( x ) = k i for all 1 (cid:54) i (cid:54) n . We partition the set of indices I := { , . . . , n } into the sets M := { L ( x ) + 1 , . . . , L n ( x ) + 1 } and N := I \ M. At the indices in N the first instance of a sock type is drawn. There are n ! ways toallocate the n types of socks to these n indices and 2 n choices whether the left or rightsock is the first. Once this choice is made we look at the indices in M in order. At eachof these indices a pair of socks is completed. As there there are k i socks of different typeon the table at time L i ( x ), there are exactly k i choices for ω L i ( x )+1 . Altogether, we findexactly 2 n n ! (cid:81) ni =1 k i different elements ω ∈ Ω n with K i ( x ( ω )) = k i . Acknowledgment:
This note originated from the first author’s bachelor thesis.
References [1] Daniel Bernoulli. De usu algorithmi infinitesimalis in arte coniectandi specimen.In:
Die Gesammelten Werke der Mathematiker und Physiker der Familie Bernoulli,vol. 2. (David Speiser, editor). Birkh¨auser (1982).[2] Sarah Gilliand, Charles Johnson, Sam Rush and Deborah Wood. The sock matchingproblem.
Involve
7, 691697 (2014).[3] Simon Korbel. Eine Pfadformel und ein Grenzwertsatz zum sock matching Problem.Bachelorarbeit, Universit¨at zu K¨oln (2020).[4] Wenbo V. Li and Geoffrey Pritchard. A central limit theorem for the sock-sortingproblem. In:
Prog. Probab. 43 , 245248. Birkh¨auser (1998).[5] Bojana Panti and Olga Bodroza-Panti. A brief overview of the sock matching prob-lem. arXiv:1609.08353 (2016).[6] David Steinsaltz. Fluctuation bounds for sock-sorting and other stochastic processes.