Loading [MathJax]/jax/output/HTML-CSS/jax.js

Wednesday, April 16, 2014

clrs Exercise 5.3-3


Suppose that instead of swapping element A[i]A[i] with a random element from the subarray A[in]A[in], we swapped it with a random element from anywhere in the array:
PERMUTE-WITH-ALL(A)
n = A.length
for i = 1 to n
    swap A[i] with A[RANDOM(1,n)]
Does this code produce a uniform random permutation? Why or why not?
Of course, this is a popular problem and there are tons of posts and papers written on it. Here's one from Coding Horror

No comments:

Post a Comment