Professor Armstrong suggests the following procedure for generating a uniform random permutation: PERMUTE-BY-CYCLIC (A) 1 n length

Question:

Professor Armstrong suggests the following procedure for generating a uniform random permutation:
PERMUTE-BY-CYCLIC (A)
1 n ← length [A]
2 offset ← RANDOM (1, n)
3 for i ← 1 to n
4 do dest ← i + offset
5 if dest > n
6 then dest ← dest -n
7 B[dest] ← A[i]
8 return B
Show that each element A[i] has a 1/n probability of winding up in any particular position in B. Then show that Professor Armstrong is mistaken by showing that the resulting permutation is not uniformly random.
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: