Summarizing my answer: the minimum number of operations required to sort a permutation $\pi$ is $\lceil \log_2 (d(\pi^{-1})+1) \rceil$, where $d(\cdot)$ is the number of descents.
–
Yuval FilmusFeb 5 '13 at 16:52

I like to think of it in terms of removing inversions. With each operation, you can remove inversions between any set $X$ and $S-X$ (where $S$ is the whole set of balls). So, you just have to choose your sets $X$ carefully.
–
JoeFeb 6 '13 at 5:43

1 Answer
1

Define the run-partition number of a permutation $\pi$, denoted $r(\pi)$, using the following process. Let $k$ be the maximal integer such that the numbers $\min(\pi),\ldots,k$ appear in increasing order in $\pi$. Remove them from $\pi$, and repeat the process. The number of rounds it takes to consume the entire permutation is $r(\pi)$.

For example, let's compute $r(62735814)$. We first set aside $1$, to get $6273584$. Then we set aside $234$, to get $6758$. Then we set aside $5$, to get $678$. Finally, we set aside $678$ to get the empty permutation. This takes four rounds, so $r(62735814) = 4$.

How is this representation useful for sorting $62735814$? Take every second run, i.e. $234,678$, and move these numbers to the right to get $51627384$ (edit: in the order they appear in the permutation, i.e. $627384$). Now there are only two runs, namely $1234,5678$, and we can sort the list by moving $5678$ to the right.

Now let me make the following conjecture: For a permutation $\pi$, let $\Pi$ be the set of all permutations that are reachable from $\pi$ within one move. Then $\min_{\alpha \in \Pi} r(\alpha) = \lceil r(\pi)/2 \rceil$.

Given this conjecture, it is easy to show that the minimal number of moves needed to sort a permutation $\pi$ is $\lceil \log_2 r(\pi) \rceil$, and I have verified this formula for all permutations in $S_n$ for $n \leq 8$.

Edit: Here is a different interpretation of the run-partition number which gives a linear time algorithm for computing it, and allows me to sketch a proof of my conjecture, thus verifying the formula $\lceil \log_2 r(\pi) \rceil$.

Consider the permutation $62735814$ again. The reason that the first run ends in $1$ is that $2$ appears before $1$. Similarly, the second run ends in $4$ since $5$ appears before $4$, and so on. Therefore the run-partition number of a permutation is the number of $i$s such that $i+1$ appears before $i$.

We can state this more succinctly if we look at the inverse of the permutation. Consider again $\pi = 62735814$. Take $\pi^{-1} = 72485136$. This permutation has three descents: $7\mathbf{2}48\mathbf{5}\mathbf{1}36$ (a descent is a position smaller than the preceding one). Each of the descents corresponds to the start of a new run. So $r(\pi)$ is equal to one plus the number of descents in $\pi^{-1}$.

What does the operation look like in terms of $\pi^{-1}$? let $B$ be the set of numbers that we move to the right, and $A$ be the set of numbers that stay to the left. We replace the numbers in $A$ with a permutation on $\{1,\ldots,|A|\}$ representing their relative order, and replace the numbers in $B$ with a permutation on $\{|A|+1,\ldots,|A|+|B|\}$. For example, consider the move $\mathbf{6273}5\mathbf{8}1\mathbf{4} \mapsto 51\mathbf{627384}$. In terms of the inverse permutations, it's $7\mathbf{248}5\mathbf{136} \mapsto 2\mathbf{468}1\mathbf{357}$. So $75$ was mapped to $21$ and $248136$ was mapped to $468357$.

A descent $\ldots xy \ldots$ in $\pi^{-1}$ is lost after the operation only if $x \in A$ and $y \in B$. Conversely, in terms of $\pi^{-1}$, the partition into $A$ and $B$ corresponds to $A$-runs and $B$-runs; every time a $B$-run ends and an $A$-run begins, there is a descent. In order to "kill" a descent, we have to switch from an $A$-run to a $B$-run. If we kill two descents, we will have switched in the middle from a $B$-run to an $A$-run, incurring a descent.

This argument can be formalized to show that if $\alpha$ arises from $\pi$ via an operation, then $d(\alpha^{-1}) \geq \lfloor d(\pi^{-1})/2 \rfloor$, where $d(\cdot)$ is the number of descents. This is equivalent to $r(\alpha) \geq \lceil r(\pi)/2 \rceil$, thus proving one direction of my conjecture. The other direction is easier, and was already outlined above: we simply take every second run and push these runs to the right to get a permutation $\alpha$ satisfying $r(\alpha) = \lceil r(\pi/2) \rceil$.

You are taking out several rounds of balls at once, I understand that isn't allowed.
–
vonbrandFeb 4 '13 at 23:20

1

I'm taking them in the order they appear in the permutation. That is legal.
–
Yuval FilmusFeb 5 '13 at 0:14

i am bit confused. can you please explain min number of operations required to sort [6 5 4 3 2 1] and also you mentioned like "Take every second run, i.e. 234,678, and move these numbers to the right to get 51627384" can you please explian this with detail and also how to calculate r(π) efficently?
–
user6709Feb 5 '13 at 5:17

2) You take all the numbers belonging to these runs (in the order they appear in the permutation), and move them to the right. In this case, you take $627384$ and move them to the right, leaving $51$ to the left.
–
Yuval FilmusFeb 5 '13 at 6:32