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

1 Expert Approved Answer
Step: 1 Unlock

PERMUTEBYCYCLIC chooses offset as a random integer in the range 1 offset n and th... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Algorithms Questions!