Question: Consider the following algorithm to generate a random permutation. PERMUTE(n) 1 fori 1 to n 2 3 for i 1 to n 4 used(i) =

 Consider the following algorithm to generate a random permutation. PERMUTE(n) 1

Consider the following algorithm to generate a random permutation. PERMUTE(n) 1 fori 1 to n 2 3 for i 1 to n 4 used(i) = FALSE repeat rRANDINT(1,n) until used(r) = FALSE perm(i) = r used(r) = TRUE 9 return perm (a) Prove that the algorithm is correct in the sense that all permutations are equally likely to be chosen. (Hint: what should be the probability for each permutation?) (b) let X denote the number of times that RANDINT is called in line 5. What is ET]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!