Problem

The following algorithm will generate a random permutation of the elements 1, 2, …,n. It i...

The following algorithm will generate a random permutation of the elements 1, 2, …,n. It is somewhat faster than the one presented in Example la but is such that no position is fixed until the algorithm ends. In this algorithm, P(i) can be interpreted as the element in position i.

Step 1. Set k = 1.

Step 2. Set P(l) = 1.

Step 3. If k = n, stop. Otherwise, let k = k + 1.

Step 4. Generate a random number U and let

P(k) = P([kU] + 1)

P([kU] + 1) = k

Go to step 3.

(a) Explain in words what the algorithm is doing.


(b) Show that at iteration k –that is, when the value of

P(k) is initially set–P(1),P(2),..., P(k) is a random permutation of 1,2,..., k.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 10