4 ms·
Turning compare into a coin flip is a fun way to illuminate the underlying algorithm. IE is said to use a heap/tree related sort[1]. The first thing a heapsort
by glymor 17y ago
Turning compare into a coin flip is a fun way to illuminate the underlying algorithm.
IE is said to use a heap/tree related sort[1]. The first thing a heapsort does is swap the last entry with the the front (where the front may have been swapped in the heapify step[2]). Thereafter it leaves the last entry alone.
Since the first entry in the unshuffled array is "Internet Explorer" if it survives the initial comparison it will always occupy the last (5th) place.
The other algorithms don't have a case with only one compare which is why they have more complicated distributions.
[1] - http://www.smallapple.net/rnd/art/how_does_your_browser_sort.html http://www.smallapple.net/rnd/art/how_does_your_browser_sort...
[2] - http://en.wikipedia.org/wiki/Heapsort http://en.wikipedia.org/wiki/Heapsort