Distance between element and its position in permutation

114 Views Asked by At

Consider a permutation $\pi$ that is chosen uniformly at random among all permutations of $\{1, \dotsc, n \}$. Let $a_i$ be the position of $i$.

We want to find $$E[\sum_{i=1}^n |a_i -i |]= \sum_{i=1}^n E[|a_i - i |].$$

How can one compute this? I tried to use the following approach for calculating $|a_i-i|$.

We have that $a_i -i \in \{1-i, \dotsc, n-i\}$, each with equal probability.

Then $$ E[|a_i - i| ] = \sum_{d=1}^n \frac{1}{n} |d-i| = \frac{1}{n}\left(\sum_{d=1}^{i} (i-d) + \sum_{d=i+1}^{n} (d-i)\right) =\frac{1}{n}\left(2 - \frac{i(i+1)}{2}-(n-i)i + \frac{(n-i) (n+i+1)}{2} \right)$$

Is this correct? Clearly one could simplify that, but if I have made an obvious mistake then I prefer not to simplify it before realizing that I made an error! Thank you.