A comparison of different sorting algorithms (bubble, merge, heap, timsort). You can run them one at a time or race all seven.
This site is made possible by member support. 💞
Big thanks to Arcustech for hosting the site and offering amazing tech support.
When you buy through links on kottke.org, I may earn an affiliate commission. Thanks for supporting the site!
kottke.org. home of fine hypertext products since 1998.
Beloved by 86.47% of the web.
A comparison of different sorting algorithms (bubble, merge, heap, timsort). You can run them one at a time or race all seven.
Comments 4
Years ago I discovered this video version of the same basic concept. The audio adds an interesting dimension.
I was about to post the same thing! I vividly remember it totally demystified sorting algorithms for me.
Bubble sort + the Amen break.
The merge sort is recursive, which is different from how I learned it. It completely sorts the first half before it moves on to the second half. In the classic merge sort, all the pairs in the array are sorted, then those pairs are merged into groups of 4, then 8, and so on.
When done that way, it's slightly more memory efficient and has excellent memory locality. It can even be used efficiently with reel-to-reel tapes, should you need to sort anything on Adam West's Bat Computer.
Also worth noting is that on this small demo timsort isn't much more than a few insertion sorts merged together. Variants of timsort are the fastest known stable sorting algorithms. Timsort is a bucket of tricks to get the fastest result. For small chunks of data, it generally uses insertion sort (which is super fast on modern processors because of memory locality—though the animation messes that up) and once those small chunks are sorted it uses a variation of insertion sort.
Hello! In order to comment or fave, you need to be a current kottke.org member. If you'd like to sign up for a membership to support the site and join the conversation, you can explore your options here.
Existing members can sign in here. If you're a former member, you can renew your membership.
Note: If you are a member and tried to log in, it didn't work, and now you're stuck in a neverending login loop of death, try disabling any ad blockers or extensions. Or try logging out and then back in. Still having trouble? Email me!
In order to comment or fave, you need to be a current kottke.org member. Check out your options for renewal.
If you feel like this comment goes against the grain of the community guidelines or is otherwise inappropriate, please let me know and I will take a look at it.
Hello! In order to leave a comment, you need to be a current kottke.org member. If you'd like to sign up for a membership to support the site and join the conversation, you can explore your options here.
Existing members can sign in here. If you're a former member, you can renew your membership.
Note: If you are a member and tried to log in, it didn't work, and now you're stuck in a neverending login loop of death, try disabling any ad blockers or extensions. Or try logging out and then back in. Still having trouble? Email me!