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) 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
Get step-by-step solutions from verified subject matter experts
