For each $\pi$ permutation of numbers 1 to n, $f(\pi) = \sum_{i=1}^n |\pi_i - i|$. What is the average of $f(\pi)$ on all of the $n=7$ permutations?
-
Often, looking at smaller examples can help you uncover patterns that help you solve larger examples. Have you tried calculating the average for, say, $n = 2, 3$ or $4$? – Arthur Apr 11 '19 at 14:09
-
@Arthur You right but in fact i couldn't even understand the question well – Developer Apr 11 '19 at 14:46
-
@Developer The question is asking: What is $\frac{1}{7!}\sum_\pi f(\pi)$, where $\pi$ in the sum runs through all permutations of $\left{1,\ldots,7\right}$? – Luiz Cordeiro Apr 11 '19 at 15:03
-
Say $\pi$ is the cyclic permutation that sends $k\mapsto k+1$, except $7\mapsto 1$. Then $$f(\pi)=1+1+1+1+1+1+6=12$$ You are asked to calculate this value for all different $\pi$, sum them up, and divide by $7!$. – Arthur Apr 11 '19 at 15:10
-
Please add context to your question. A short question body will trigger an alarm. – GNUSupporter 8964民主女神 地下教會 Apr 11 '19 at 15:20
-
@GNUSupporter8964民主女神地下教會 Thanks for your suggestion, can you please tell me what kind of details can I add to my question body when there are no details? – Developer Apr 13 '19 at 17:01
-
Welcome to Math.SE! Please read this post and the others there for information on writing a good question for this site. In particular, people will be more willing to help if you [edit] your question to include some motivation, and an explanation of your own attempts. – GNUSupporter 8964民主女神 地下教會 Apr 13 '19 at 18:17
-
not sure which guideline is not met – FirstName LastName Oct 30 '21 at 00:25
1 Answers
Let's do this for a general $n$, instead of $7$.
We have $$E(f(\pi)) = E \left( \sum_{i=1}^n |\pi_i - i| \right).$$ By linearity of expectation, we get
$$ E(f(\pi)) = \sum_{i=1}^n E(|\pi_i - i|). $$
Now $E(|\pi_i - i|)$ of course depends on $i$ and $n$. In particular, we have
$$ E(|\pi_i - i|) = {(i-1) + (i-2) + \cdots + 1 + 0 + 1 + \cdots + (n-i) \over n}. $$
Then we have $(i-1) + (i-2) + \cdots + 1 = i(i-1)/2$ and $1 + 2 + \cdots + (n-i) = (n-i)(n-i+1)/2$. This gives
$$ E(|\pi_i - i|) = {i(i-1)/2 + (n-i)(n-i+1)/2 \over n} $$
Therefore, going back to the initial sum, $$E(f(\pi)) = \sum_{i=1}^n {i(i-1) \over 2n} + \sum_{i=1}^n {(n-i)(n-i+1) \over 2n}.$$
These tw sums are the same since they have the same terms in reverse order, so we get
$$ E(f(\pi)) = 2 \sum_{i=1}^n {i(i-1) \over 2n} = {1 \over n} \sum_{i=1}^n i^2-i$$
Finally we can work out that sum:
$$ {1 \over n} \sum_{i=1}^n (i^2-i) = {1 \over n} (\sum_{i=1}^n i^2 - \sum_{i-1}^n i) = {1 \over n} \left( {n(n+1)(2n+1) \over 6} - {n(n+1) \over 2} \right) = (n+1) \left( {2n+1 \over 6} - {1 \over 2} \right) = {(n+1)(2n-2) \over 6} = {n^2 - 1 \over 3}.$$
The references at https://oeis.org/A062869 appear to be relevant; the statistic computed here is called the "total displacement" of a permutation or "Spearman's disarray".
- 22,354
-
1see also https://puzzling.stackexchange.com/questions/112210 – FirstName LastName Oct 30 '21 at 00:30