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

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

Consider the following algorithm to generate a random permutation. PERMUTE n) 1 for 1 to n 2 3 fori 1 to n 4 repeat used(i) = FALSE r = RAND!NT(1,n) until used(r) = FALSE perm (i) T 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 E[T)? Consider the following algorithm to generate a random permutation. PERMUTE n) 1 for 1 to n 2 3 fori 1 to n 4 repeat used(i) = FALSE r = RAND!NT(1,n) until used(r) = FALSE perm (i) T 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 E[T)

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!