Find $\max_{\sigma \in S_n}\sum_{i=1}^n|\sigma(i)-i|$, where $S_n$ is the symmetric group of permutations of $n$ symbols.
So, the story goes like this:
When I first saw the problem, I thought the problem might be a difficult one. After playing around with $S_3$ I thought that maybe the best way to attack the problem is to construct a permutation $\sigma$ such that for each $i\in\{1,2,\cdots,n\}$ the distance $|\sigma(i)-i|$ is maximized because if each $|\sigma(i)-i|$ is maximized then their sum is maximized as $|\sigma(i)-i|$ are positive.
So I started like this: Let's start from $|\sigma(1)-1|$. If I want to maximize this then $\sigma(1)$ must be $n$. If I want to maximize $|\sigma(2)-2|$ then $\sigma(2)$ must be $n-1$ and so forth..
After thinking about this for sometime, I realized that this isn't a good idea, because I found some counter-examples.
For example, if $n=7$, then following the algorithm I just said we find these permutations that all agree with the method I suggest, but $\sigma_1$ fails to maximize $\sum_{i=1}^n|\sigma(i)-i|$ (I'll write two of the permutations constructed in this way and ignore the rest):
$\sigma_1=\begin{pmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 \\ 7 & 6 & 1 & 2 & 3 & 4 & 5 \end{pmatrix}$, $\sigma_2 = \begin{pmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 \\ 7 & 6 & 5 & 1 & 2 & 3 & 4 \end{pmatrix}$
If we use $\sigma_1$ then $\sum_{i=1}^n |\sigma_1(i)-i| = 20$ while if we use $\sigma_2$ the sum is $\sum_{i=1}^n |\sigma_2(i)-i|=24$.
I guess for any $\sigma \in S_n$, the maximum sum is obtained when $$\sigma = \begin{pmatrix} 1 & 2 & 3 & \cdots & n-2 & n-1 & n \\ n & n-1 & n-2 & \cdots & 3 & 2 & 1 \end{pmatrix}$$
Based on this assumption, I have solved the problem and my answer is, by chance, correct. But there are some serious issues that I can't explain well and I hope that people on MSE can make them more clear for me:
- I'm not very surprised that my algorithm failed. In fact, I would've been surprised if it had worked because my proposed algorithm doesn't construct a unique permutation and is based on the assumption that we are free to go from $k$ to $k+1$ without any restrictions. But why this algorithm fails?
- I haven't had a course in discrete mathematics, but by searching on the internet, I read about the greedy algorithm. It seems like the greedy algorithm is the most naive approach that one can take to solve a problem like this. So, it's favorable for that reason. But are there any axioms or assumptions that when they're satisfied they guarantee that the greedy algorithm works?
- What is the correct method and mindset to solve a problem like this and in particular this one? This is my least important question of the three. In fact answering the first and second questions could be more teaching for me than this one, but I'd like to see a proof.
Thanks
I'll write a start of a proof. You'll have to fill in some details yourself.
Suppose $1\leq i< j\leq n$. Also, suppose that $\sigma(i)\geq j$ and $\sigma(j)\geq j$. Then, it doesn't matter if we exchange $\sigma(i)$ and $\sigma(j)$. When $\sigma(i),\sigma(j)\leq i$, it doesn't matter too. When $\sigma(i)\leq i$ and $\sigma(j)\geq j$, we can improve the permutation by exchanging $\sigma(i)$ and $\sigma(j)$. Thus, for any 'maximal' (in the sense of the given sum) permutation, we know that if $i<j$, $\sigma(i)$ and $\sigma(j)$ are both larger than $j$, both smaller than $i$ or $\sigma(j)\leq i<j\leq \sigma(i)$. Now, say that $k=\min_{1\leq i\leq \frac n2} \sigma(i)$. It should be possible to bound the sum from above for each $k$ and the maximum should occur at $k=\frac n2$. That means that the lower half is mapped to the upper half of $\{1,2,\dots,n-1,n\}$ and vice versa.