Consider this problem:
Let's define a list of numbers {1, 2, ..., n} in the right order. Let's make a random permutation by swapping numbers randomly. Take k random pairs of different elements and swap them.
For example with k = 1 I might get the following list {2, 1, ..., n} or {1, n, ..., 2}, etc ...
Compute the expected number of numbers that are at the right place (in the two examples above, only n-2 numbers are at the right place).
The edge cases are:
- If $ k \rightarrow \infty $, then we expect 1 number at the right place (the shuffling will be perfect so we have 1/n chance per position, so n/n chance in total). I am not sure this proof is good because I assume everything is independent by summing right? and it's definitely not independent (if n-1 first numbers are at the right place, the last one doesn't have 1/n probability to be at the right place, it has 1 probability to be at the right place). This has been proven as false (with the counter example n = 2 it's easy to see why). Thank you Calvin Lin.
- If $k = 0$, we expect n.
- If $k = 1$, we expect n-2.
I tried simulating some stuff with k = 30000 and k = 70001 for n = 10000 in Python:
import numpy as np
def count_fixed_points(perm):
return sum(1 for i, x in enumerate(perm, 1) if i == x)
def random_permutation(n, num_swaps):
perm = list(range(1, n+1))
for _ in range(num_swaps):
i, j = np.random.choice(n, 2, replace=False)
perm[i], perm[j] = perm[j], perm[i]
return perm
n = 10000
perm30000 = random_permutation(n, 30000)
fixed_points_30000 = count_fixed_points(perm30000)
perm70000 = random_permutation(n, 70000)
fixed_points_70000 = count_fixed_points(perm70000)
fixed_points_30000, fixed_points_70000
I get (23, 1), (31, 2), and (23, 0) on three runs which are consistent with intuition (the more with swaps, the smaller the amount of fixed points we will get).
Can we easily compute the expected value? Is it possible with not-too-advanced stuff (undergrad level proof let's say).