Why Random Swaps Do Not Uniformly Shuffle

Coding
Randomized Algorithms
Medium
Why is repeatedly swapping each array element with a uniformly random element from the entire array generally not a correct uniform shuffle?
Hint 1

Count the total number of distinct sequences of swap choices versus the number of permutations.

Hint 2

Compare this to the Fisher-Yates shuffle, which restricts the range of the random index at each step.

Show worked solution
  1. 1. Count the outcome space

    This procedure makes independent choices each from options, producing equally likely sequences of choices, mapped onto only permutations.

  2. 2. Show the mapping is uneven

    Since is generally not a multiple of , the equally likely sequences cannot map onto the permutations with equal counts, so some permutations occur more often than others; correct uniform shuffling (Fisher-Yates) instead restricts the th swap to the remaining unplaced elements.

Answer: It does not give all permutations equal probability.

Related roles: Browse quant jobs

Related problems