187k views
1 vote
Suppose that instead of swapping element A[i] with a random element from the subarray A[i..n], we swapped it with a random element from anywhere in the array: PERMUTE-WITH-ALL (A) 1, n = A.length 2, for i = 1 to n 3, swap A[i] with A Does this code produce a uniform random permutation? Why or why not?

User Leogps
by
4.7k points

1 Answer

3 votes

Answer:

The answer to this question can be defined as follows:

Step-by-step explanation:

Its Permute-with-all method, which doesn't result in a consistent randomized permutation. It takes into account this same permutation, which occurs while n=3. There's many 3 of each other, when the random calls, with each one of three different values returned and so, the value is= 27. Allow-with-all trying to call possible outcomes as of 3! = 6

Permutations, when a random initial permutation has been made, there will now be any possible combination 1/6 times, that is an integer number m times, where each permutation will have to occur m/27= 1/6. this condition is not fulfilled by the Integer m.

Yes, if you've got the permutation of < 1,2,3 > as well as how to find out design, in which often get the following with permute-with-all chances, which can be defined as follows:


\bold{PERMUTATION \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ PROBABILITY}


\bold{<1,2,3> \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 4/27= 0.14 }\\\bold{<1,3,2> \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 5/27=0.18}\\


\bold{<2,1,3> \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 5/27=0.18}\\\bold{<2,3,1>\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 5/27=0.18}


\bold{<3,2,1> \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 4/27=0.14}

Although these ADD to 1 none are equal to 1/6.

User JMW
by
5.3k points