Shuffle n distinct elements uniformly. Return the expected number of inversions, meaning pairs that appear in the wrong relative order.
n
Every one of the (n2)\binom{n}{2}(2n) pairs is inverted with probability exactly 1/21/21/2, by symmetry:
Input
10
Output
22.5
This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.
solve(...)