Question: Professor Kelp decides to write a procedure that produces at random any permutation besides the identity permutation. He proposes the following procedure: PERMUTE-WITHOUT-IDENTITY (A) 1.

Professor Kelp decides to write a procedure that produces at random any permutation besides the identity permutation. He proposes the following procedure:
PERMUTE-WITHOUT-IDENTITY (A)
1. N = A.length
2. For i = 1 to n – 1
3. Swap A[i] with A[RANDOM (i + 1, n)]

Does this code do what Professor Kelp intends?

Step by Step Solution

3.37 Rating (172 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Although PERMUTEWITHOUTIDENTITY will not produce the ... View full answer

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 Introduction to Algorithms Questions!