Problem 5.3-6
Explain how to implement the algorithm PERMUTE-BY-SORTING to handle the
case in which two or more priorities are identical. That is, your algorithm shouldproduce a uniform random permutation, even if two or more priorities are identical
Solution 1
1. Redo the procedure until no conlision occurs.
Solution 2:
1. Get all items with the same priority
2. Assign priority again randomly.
3. sort.
4. If there are still two or more priorities are the same, go to step 1.
4. Put back to the origin position.
Analyse:
Randomly permute the parts with colision only, to save the time for sort.