2

On a strange railway line, there is just one infinitely long track, so overtaking is impossible. Any time a train catches up to the one in front of it, they link up to form a single train moving at the speed of the slower train. At first, there are three equally spaced trains, each moving at a different speed. You watch, and eventually (after all the linking that will happen has happened), you count the trains. You wonder what would have happened if the trains had started in a different order (but each of the original three trains had kept its same starting speed). On average (averaging over all possible orderings), how many trains will there be after a long time has elapsed? What if at the start there are 4 trains (all moving at different speeds)? Or $5$? Or $n$?

YCor
  • 60,149

2 Answers2

4

This nice puzzle ends up being related to unsigned Stirling numbers of the first kind, A130534.

Here's the $n=3$ case worked out. Think of the trains moving left to right with higher numbers indicating greater speed. In the following, I've underlined the trains that end up leading a collection, i.e., any faster trains get stuck behind them.

$$\begin{array}{cc} \text{permutation} & \text{# trains} \\ \underline{1} \; \underline{2} \; \underline{3} & 3 \\ \underline{1} \; 3 \; \underline{2} & 2 \\ 2 \; \underline{1} \; \underline{3} & 2 \\ 2 \; 3 \; \underline{1} & 1 \\ 3 \; \underline{1} \; \underline{2} & 2 \\ 3 \; 2 \; \underline{1} & 1 \end{array}$$

Then the average length is then $(2\cdot1 + 3\cdot2 + 1\cdot3)/6 = 11/6$.

Think what happens when a 4th train is added to the initial configuration. If it is on the far right, then nothing catches it and the final number of joined trains is one more than the results for 3 trains. If the new fastest train #4 is added anywhere else inside a permutation of 1, 2, 3, then it will get stuck behind a slower train and the count for the underlying 1, 2, 3 pattern will stay the same. That is, the counts for 4 trains are (4,3,3,2,3,2) and 3 copies of (3,2,2,1,2,1).

Here is a table of the first 5 rows of the resulting triangle where $T(n,k)$ counts the number of $n$ train configurations that eventually have $k$ collections.

$$\begin{array}{ccccc} 1 \\ 1 & 1 \\ 2 & 3 & 1 \\ 6 & 11 & 6 & 1 \\ 24 & 50 & 35 & 10 & 1 \end{array}$$

The description about adding the 4th train to the patterns for 1, 2, 3 is a combinatorial description of the recurrence $T(n+1,k) = nT(n,k) + T(n,k-1)$, e.g., $T(4,2) = 3T(3,2) + T(3,1) = 9 + 2 = 11$.

The average number of trains come from weighted sums of the triangle's rows: 1, 3/2, 11/6, 50/24, 274/120. The numerators are from the related sequence A000254.

Edit: Since the original question was about asymptotic behavior, let me point out that the ratio diverges. Some milestones along the slow road to infinity include an average of 3 groups of trains by $n = 11$, 5 groups by $n = 83$, and 10 groups by $n = 12367$.

2

When the average number of groups for $n$ trains is $a(n)$, one can find a recursion in the following way. For $n$ trains all left from the position $k$ of the slowest train will eventually join its group. All $n-k$ trains right from the slowest will on average form $a(n-k)$ groups. Because the position of the slowest train is equidistributed this gives $$a(0)=0,~~~~ a(n)~=~ 1+ \frac1{n}\sum \limits_{k=1}^{n-1} a(k) $$ Solving this recursion yields with the Stirling numbers of first kind $$a(n) ~=~ \frac{(-1)^n}{n!}\,S_n^{(2)}.$$

Karl Fabian
  • 1,546