Suppose that instead of swapping element A i with
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 ← length [A]
2 for i ← 1 to n
3 do swap A[i] ↔ A [RANDOM (1, n)]
Does this code produce a uniform random permutation? Why or why not?
Membership TRY NOW
  • Access to 800,000+ Textbook Solutions
  • Ask any question from 24/7 available
    Tutors
  • Live Video Consultation with Tutors
  • 50,000+ Answers by Tutors
OR
Relevant Tutors available to help