in reply to Re: how sort works
in thread how sort works
It's a special version of mergesort that takes advantage of runs of already sorted (or reversed sorted) items. While at the same time making sure the sort is stable. This makes sorting of (almost) sorted lists faster than stock mergesort would give you.
The quicksort implemented by Perl has some defenses against poor performance as well. Traditional quicksort is behaves quite poorly on sorted lists (with naive textbook implementation even going quadratic). Perls quicksort does some smart pivot picking (middle-of-three, IIRC) - but it can still behave badly on pipe-organ shaped lists. As an extra defense, if quicksort is picked, and the list is larger than a certain size, the list will be shuffled first.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how sort works
by tilly (Archbishop) on Mar 08, 2011 at 07:35 UTC | |
by JavaFan (Canon) on Mar 08, 2011 at 10:19 UTC |