for (i=0..n-1) swap(A[i], A[random(n)]);
Specifically, since at each of $n$ iterations, one of $n$ choices is made (with uniform probability), there are $n^n$ possible ‘paths’ through the computation; because the number of possible permutations $n!$ doesn’t divide evenly into the number of paths $n^n$, it’s impossible for this algorithm to produce each of the $n!$ permutations with equal probability. (Instead, one should use the so-called Fischer-Yates shuffle, which essentially changes out the call to choose a random number from [0..n) with a call to choose a random number from [i..n); that’s moot to my question, though.) What I’m wondering is, how ‘bad’ can the naive shuffle be? More specifically, letting $P(n)$ be the set of all permutations and $C(rho)$ be the number of paths through the naive algorithm that produce the resulting permutation $rhoin P(n)$, what is the asymptotic behavior of the functions $qquad displaystyle M(n) = frac{n!}{n^n}max_{rhoin P(n)} C(rho)$ and $qquad displaystyle m(n) = frac{n!}{n^n}min_{rhoin P(n)} C(rho)$? The leading factor is to ‘normalize’ these values: if the naive shuffle is ‘asymptotically good’ then $qquad displaystyle lim_{ntoinfty}M(n) = lim_{ntoinfty}m(n) = 1$. I suspect (based on some computer simulations I’ve seen) that the actual values are bounded away from 1, but is it even known if $lim M(n)$ is finite, or if $lim m(n)$ is bounded away from 0? What’s known about the behavior of these quantities?
Asked By : Steven Stadnicki
Answered By : Peter Shor
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/6519