Question: Professor Armstrong suggests the following procedure for generating a uniform random permutation: PERMUTE-BY-CYCLIC (A) 1. n = A.length 2. let B[1. . n] be a
Professor Armstrong suggests the following procedure for generating a uniform random permutation:
PERMUTE-BY-CYCLIC (A)
1. n = A.length
2. let B[1. . n] be a new array
3. offset = RANDOM (1, n)
4. for i = 1 to n
5. dest = i + offset
6. if dest > n
7. dest = dest – n
8. B[dest] = A[i]
9. return B
Show that each element A[i] has a 1/n probability of winding up in any particular position in B. Then show that Professor Armstrong is mistaken by showing that the resulting permutation is not uniformly random.
Step by Step Solution
3.33 Rating (174 Votes )
There are 3 Steps involved in it
PERMUTEBYCYCLIC chooses offset as a random integer in the range 1 offset n and th... View full answer
Get step-by-step solutions from verified subject matter experts
