4 ms·
Well, even if they compare multiple times the order will still be 'random' as in not easily predictable
by jauco 17y ago
Well, even if they compare multiple times the order will still be 'random' as in not easily predictable
- pmjordan 17y agoOr it could derail the sort algorithm in some way (infinite loop?) - the point is, it makes some assumptions and it's not clear that these assumptions hold.
- fh 17y agoOn the contrary, I bet that depending on the exact search algorithm, it would be possible to make some very specific predictions. To pick a simple example, say you use this technique on quicksort of the "pivot on the first element" variety. Given the nature of the algorithm, the first source element will end up near the center of the "randomized" list with high probability, not at all what you'd expect from an unbiased random permutation. Granted, no real world sort is that simple, and it's even possible that the "clever technique" will produce an unbiased permutation for some sorting algorithms. But why waste time thinking about this when the Knuth shuffle, a proper way to randomly permute a list, only takes a few lines of code more and is so well-documented?