Help Reorder the alphabet

Probability Level pending

Line up the 26 26 letters in the English alphabet randomly in a line. The alphabet letters are not necessarily in sorted order. To bring the letters back into sorted order, you are only allowed to swap two letters. For example, you can swap the two letters a , b a,b by sending a a to b b , and b b to a a .

What is the maximum number of swaps you need to bring the letters back to sorted order. If you may never be able to bring the letters back into sorted order, submit 1 -1 .


The answer is 25.

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.

1 solution

Arjen Vreugdenhil
Dec 21, 2017

Go through the list from left to right.

Swap the first letter (whatever it is) with a \mathbf a .

Swap the second letter (whatever it is) with b \mathbf b .

Keep going: swap the n n th letter (whatever it is) with the letter that belongs in that position.

Finally, swap the 25th letter (whatever it is) with y \mathbf y .


After the n n th stage of this process, the first n n letters will be placed correctly, and the remaining 26 n 26 - n letters will be in the remaining part of the list. After step 25, the remaining letter z \mathbf z is automatically in the right place!

Therefore it takes 25 \boxed{25} steps at most.

How can you be sure you can't do it in, say, 24 steps?

Ivo Zerkov - 3 years, 4 months ago

Log in to reply

If all letters have been moved one position out of place b c d y z a \mathbb{bcd}\dots\mathbb{yza} , it cannot be done in less than 25 steps.

Arjen Vreugdenhil - 3 years, 4 months ago

Log in to reply

Sure, that's an example I thought of as well, but how would you go about proving that it can't work in 24 steps?

For instance, you can't say each step can at most cover "fixing" one letter's position - consider dcba \text{dcba} , which can be done in 2 steps.

Ivo Zerkov - 3 years, 4 months ago

Log in to reply

@Ivo Zerkov Your example corresponds to the cycle decomposition ( 1 4 ) ( 2 3 ) (1\ 4)(2\ 3) . To order it into the identity permutation ( 1 ) ( 2 ) ( 3 ) ( 4 ) (1)(2)(3)(4) , only two cycles need to be added; therefore two steps are sufficient. However, the case b c d a \mathbf{bcda} , corresponding to a single cycle ( 1 2 3 4 ) (1\ 2\ 3\ 4) , requires addition of three cycles, i.e. three steps.

Arjen Vreugdenhil - 3 years, 4 months ago

Correct. It is a familiar result in the theory of permutation groups that an n n -cycle can be written as the composition of n 1 n-1 transpositions, but no fewer.

The outline of the proof is as follows. First, each permutation of the alphabet can be viewed (uniquely) as the composition of c c disjoint cycles. The ordered alphabet corresponds to the identity permutation, which consists of 26 1-cycles: ( 1 ) ( 2 ) ( 3 ) ( 26 ) (1)(2)(3)\cdots (26) .

Next, when composing a transposition τ = ( a b ) \tau = (a\ b) to a permutation σ \sigma , there are two possibilities. If the elements a , b a,b belong to different cycles, the cycles are joined together into one, thus reducing the number of cycles from c c to c 1 c - 1 : ( a b ) ( a x 1 x 2 x m ) ( b y 1 y 2 y n ) = ( a x 1 x m b y 1 y n ) . (a\ b)\circ(a\ x_1\ x_2\ \dots\ x_m)(b\ y_1\ y_2\ \dots\ y_n) = (a\ x_1\ \dots\ x_m\ b\ y_1\ \dots\ y_n). But if a , b a, b belong to the same cycle, it is now split into two, thus increasing the number of cycles from c c to c + 1 c+1 : ( a b ) ( a x 1 x m b y 1 y n ) = ( a x 1 x 2 x m ) ( b y 1 y 2 y n ) . (a\ b)\circ(a\ x_1\ \dots\ x_m\ b\ y_1\ \dots\ y_n) = (a\ x_1\ x_2\ \dots\ x_m)(b\ y_1\ y_2\ \dots\ y_n). Therefore each transposition changes the number of cycles by ± 1 \pm 1 ; and to increase the number of cycles, transpose two elements that belong to the same cycle in the disjoint-cycle decomposition.

The shifted alphabet b c d y z a \mathbf{bcd\cdots yza} corresponds to the 26-cycle ( 1 2 26 ) (1\ 2\ \dots\ 26) ; the ordered alphabet a b c x y z \mathbf{abc\cdots xyz} corresponds to 26 1-cycles ( 1 ) ( 2 ) ( 26 ) (1)(2)\dots(26) ; to increase the number of cycles from 1 to 26, we need therefore at least 25 steps, and this minimum is accomplished if and only if every transposition exchanges two elements that belonged to the same cycle.

Arjen Vreugdenhil - 3 years, 4 months ago

Log in to reply

@Arjen Vreugdenhil Thanks for the explanation!

Ivo Zerkov - 3 years, 4 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...