Order them balls

Six balls are arranged in a row, and you need to put them in the right order.

The problem is, you don't know what the correct order is.

If you are able to switch only two at a time, given the optimal strategy, what is the maximum number of switches you'd need to make before you are guaranteed to be able to get them in the correct order?


Image credit :. dreamstime.com


The answer is 719.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Mark Hennings
Jan 16, 2019

The Johnson-Trotter algorithm provides a Hamiltonian path of the permutohedron of S n S_n , so that it is possible to obtain all n ! n! elements of S n S_n by applying 0 , 1 , 2 , . . . , n ! 1 0,1,2,...,n!-1 transpositions successively. Thus the correct permutation can be achieved in at most n ! 1 n!-1 switches. In this case, the answer is 719 \boxed{719} .

The Johnson-Trotter algorithm works by successively placing n n in all the possible positions within all the possible permutations of 1 , 2 , . . . , n 1 1,2,...,n-1 , and building up inductively. Thus we have 12 21 \begin{aligned} 1\mathbf{2} \\ \mathbf{2}1 \end{aligned} for n = 2 n=2 , then 123 132 312 321 231 213 \begin{aligned} 12\mathbf{3} \\ 1\mathbf{3}2 \\ \mathbf{3}12 \\ \mathbf{3}21 \\ 2\mathbf{3}1 \\ 21\mathbf{3} \end{aligned} for n = 3 n=3 , and then 1234 1243 1423 4123 4132 1432 1342 1324 3124 2134 \begin{aligned} 123\mathbf{4} \\ 12\mathbf{4}3 \\ 1\mathbf{4}23 \\ \mathbf{4}123 \\ \mathbf{4}132 \\ 1\mathbf{4}32 \\ 13\mathbf{4}2 \\ 132\mathbf{4} \\ 312\mathbf{4} \\ \vdots \\ 213\mathbf{4} \end{aligned} and so on.

So in this solution, it seems that not only are there 719 switches but all switches are adjacent?

Geoff Pilling - 2 years, 4 months ago

Log in to reply

Absolutely!

Mark Hennings - 2 years, 4 months ago

Log in to reply

That's a pretty cool solution!

Makes me wonder if there is a general solution to the number of switches needed to guarantee that at least m m balls are correct (where m < n m < n )... :-/

Geoff Pilling - 2 years, 4 months ago

Log in to reply

@Geoff Pilling Talk to church bell-ringers. - adjacent bells are swapped during a peal.

Mark Hennings - 2 years, 4 months ago
Geoff Pilling
Jan 16, 2019

There are 6! = 720 ways of sorting the balls, so the best we can achieve is 719 switches, since each switch produces one new possibility.

And this can be achieved recursively for N balls by switching out each of the N colors to be in the first position and sorting the remaining N-1 similarly.

If I have 3 balls, I always have to alternate switching the first two and then the last two. Is there a similarly simple rule for these 6 balls?

Henry U - 2 years, 4 months ago

Log in to reply

Ibrahim momud

ibrahim momud - 1 year, 3 months ago

2 pending reports

Vote up reports you agree with

×

Problem Loading...

Note Loading...

Set Loading...