Professor Kelp decides to write a procedure that produces at random any permutation besides the identity permutation.

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. 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?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Introduction to Algorithms

ISBN: 978-0262033848

3rd edition

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

Question Posted: