Sorting algorithms that don’t hate you
medium.com
Sorting algorithms that don’t hate you
1–10 of 84 posts
Re: Sorting algorithms that don’t hate you
#2Re: Sorting algorithms that don’t hate you
#3Like it probably doesn't matter if you're sorting 10k entries, but when you're sorting several gigabytes it really does.
Re: Sorting algorithms that don’t hate you
#4I had way too much fun making these animations.
Re: Sorting algorithms that don’t hate you
#5An understated benefit of merge sort is that all of its access patterns have excellent locality. Regardless of big-O, this is a huge advantage because it reduces cache thrashing. Like it probably doesn't matter if you're sorting 10k entries, but when you're sorting several gigabytes it really does.
The actual implementation in Toit does depth first, so eg. the leftmost 8,8->16 merge is done as soon as the 8-element ranges are ready.
Re: Sorting algorithms that don’t hate you
#6I vaguely recall JSC actually having a literal tree sort at one point to deal with this.
Re: Sorting algorithms that don’t hate you
#7Timsort is from 2002. Not sure where this comes from. Perhaps it wasn't as popular or widely known in 2008 as it is now, but I actually learned about it at about that time. See also:
https://mail.python.org/pipermail/python-dev/2002-July/02683...
(edit: timsort was introduced to Java in 2009, per https://bugs.openjdk.org/browse/JDK-6804124, and knowledge of it would probably have spread much further from that point, so maybe that's the source of confusion?)
Re: Sorting algorithms that don’t hate you
#8(With that said, Timsort must be faster in practice than this kind of retrofitted unstable sort. I’m curious how large the difference is.)
Re: Sorting algorithms that don’t hate you
#9Re: Sorting algorithms that don’t hate you
#10An understated benefit of merge sort is that all of its access patterns have excellent locality. Regardless of big-O, this is a huge advantage because it reduces cache thrashing. Like it probably doesn't matter if you're sorting 10k entries, but when you're sorting several gigabytes it really does.