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
Although PERMUTEWITHOUTIDENTITY will not produce the ... View full answer
Get step-by-step solutions from verified subject matter experts
