Maths Olympiad Prep

Library / NZMO Round One /36 of 39

NZMO Round One

Combinatorics Difficulty 7.1 National Olympiad, round 2 Prove it New Zealand

Problem:

Alice plays a game with the Mad Hatter. The Mad Hatter will write two rows of numbers on a blackboard, each a distinct permutation of {1,2,…,n}\{1,2,\ldots ,n\}.
On each move, Alice is allowed to swap the positions of the numbers aa and a+1a + 1 in the first row, for some 1≤a<n1 \leq a < n.
What is the minimum number of moves Alice needs in order to guarantee that she can turn the first row of numbers into the second, regardless of the permutations the Mad Hatter writes?

Solution

Solution:

We will show that the answer is (n2)=n(n−1)2\binom{n}{2} = \frac{n(n - 1)}{2}.
To show that this is sufficient, we will use induction.

- Base Case: Note that when n=1n = 1, the two rows of numbers must be the same since there is only one permutation of {1}\{1\}. Hence this case takes 0=(12)0 = \binom{1}{2} turns.

- Inductive Step: Suppose that we know that it takes (n−12)\binom{n-1}{2} moves for two permutations of {1,2,…,n−1}\{1,2,\ldots,n-1\}. Now consider two permutations of {1,2,…,n}\{1,2,\ldots,n\}. We will show that it takes at most n−1n-1 moves to put the number nn into the correct position.

Suppose that nn is in the ii-th position in the first row, and that the ii-th number in the second row is occupied by kk. We first swap the positions of kk and k+1k + 1, meaning that the ii-th number in the second row is now k+1k + 1. By repeating this argument with k+1k + 1 and k+2k + 2, k+2k + 2 and k+3k + 3, ..., n−1n - 1 and nn, we will have nn in the correct position. This takes n−kn - k moves, and since 1≤k≤n1 \leq k \leq n, the whole process takes at most n−1n - 1 moves.

Once we have put nn into the correct position, we can effectively remove the nn from both rows, since we are able to arrange the rest of the numbers without touching nn again, showing that the problem has now been reduced to the n−1n - 1 case. By the inductive hypothesis, the rest of the problem takes at most (n−12)\binom{n-1}{2} moves.

Hence, the maximum number of moves required is (n−12)+n−1=(n2)\binom{n-1}{2}+n-1=\binom{n}{2}.

To show that (n2)\binom{n}{2} moves are necessary, we note that the Mad Hatter can write to force Alice to use (n−22)\binom{n-2}{2} moves. To show this, we define the warp of a permutation as follows: for each number in the permutation, its distance is the number of numbers to right of it which are smaller than itself. Then the warp is the sum of the distances over all the numbers in the permutation.

Note that on each move, the warp of a permutation either increases by 1 or decreases by one. This is because, if we swap the positions of aa and a+1a + 1, then the only distance that can change is the distance of a+1a + 1, and this may only increase by 1 (if a+1a + 1 started on the right) or decrease by 1 (if a+1a + 1 started on the left).

Now, since the warp of the first row at the start is (n−1)+(n−2)+⋯+1=(n2)(n - 1) + (n - 2) + \dots +1 = \binom{n}{2}, and the warp of the second row at the start is 0, the minimum number of moves required to turn the permutation n,n−1,…,1n, n - 1, \ldots, 1 into the permutation 1,2,…,n1, 2, \ldots, n is (n2)\binom{n}{2}.

We have thus proven that the answer is (n2)\binom{n}{2}.

Want a route through all this instead of an archive? The track puts 2,604 problems in a working order, from Junior Challenge level to the IMO shortlist.

Source: MathNet, licensed CC-BY-4.0. Statement reproduced verbatim; metadata (topic, difficulty) added by this project.