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
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.
The Johnson-Trotter algorithm provides a Hamiltonian path of the permutohedron of S n , so that it is possible to obtain all n ! elements of S n by applying 0 , 1 , 2 , . . . , n ! − 1 transpositions successively. Thus the correct permutation can be achieved in at most n ! − 1 switches. In this case, the answer is 7 1 9 .
The Johnson-Trotter algorithm works by successively placing n in all the possible positions within all the possible permutations of 1 , 2 , . . . , n − 1 , and building up inductively. Thus we have 1 2 2 1 for n = 2 , then 1 2 3 1 3 2 3 1 2 3 2 1 2 3 1 2 1 3 for n = 3 , and then 1 2 3 4 1 2 4 3 1 4 2 3 4 1 2 3 4 1 3 2 1 4 3 2 1 3 4 2 1 3 2 4 3 1 2 4 ⋮ 2 1 3 4 and so on.