4 ms·
Why three random elements though? If you expect some structure in the array, then picking pivots based on that structure makes more sense (e.g. first, middle an
by Robin_Message 15y ago
Why three random elements though? If you expect some structure in the array, then picking pivots based on that structure makes more sense (e.g. first, middle and last for sorted, reverse sorted for partially sorted arrays).
On the other hand, if you are sorting unsanitised input, then random is good, but it should be secure pseudo-random numbers if it's important to your security/performance whilst under attack.