Timsort (2019)
skerritt.blog
skerritt.blog
https://news.ycombinator.com/item?id=21196555
tim gave me some really eye-opening tips, one that's really stuck with me is that you want to take the best of many short runs of the benchmark rather than running it a long time, because longer runs are going to guarantee interference from other parts of the OS (scheduling, etc).
tim is an insanely smart guy, kind, and funny.
One day for lunch we were ordering takeout from this little joint, I forget the name, it might have been Hamborgarabulla Tomasar, and I picked up the check for everyone (maybe 15 people). tim described it as "shockingly good", which was absolutely accurate. For how expensive Iceland was for food, it wasn't too terribly bad price-wise either.
I wrote up more here, though I guess my blogs are offline now. https://lwn.net/Articles/185399/
So, not too crazy of a story. Not like the story of how I first met tim.
Are you going to make us ask every time?
How did you meet Tim?
Beating TimSort at Merging - https://news.ycombinator.com/item?id=27823180 - July 2021 (69 comments - including https://news.ycombinator.com/threads?id=tim-peters - maybe luck will strike again...)
Timsort, the Python sorting algorithm - https://news.ycombinator.com/item?id=21196555 - Oct 2019 (131 comments)
On the Worst-Case Complexity of TimSort - https://news.ycombinator.com/item?id=17883461 - Aug 2018 (74 comments)
Timsort is a sorting algorithm that is efficient for real-world data - https://news.ycombinator.com/item?id=17436591 - July 2018 (77 comments)
Functional verification with mechanical proofs of TimSort [pdf] - https://news.ycombinator.com/item?id=9778243 - June 2015 (1 comment)
Timsort - https://news.ycombinator.com/item?id=3214527 - Nov 2011 (27 comments)
Visualising Sorting Algorithms: Python's timsort - https://news.ycombinator.com/item?id=2092594 - Jan 2011 (3 comments)
Java has switched from Mergesort to TimSort - https://news.ycombinator.com/item?id=752677 - Aug 2009 (13 comments)
Visualizing Sorting Algorithms - https://news.ycombinator.com/item?id=750858 - Aug 2009 (3 comments)
[1] http://www.envisage-project.eu/proving-android-java-and-pyth...
Not only that, but the cpython’s implementation’s misbehaviour effectively couldn’t be triggered because you couldn’t create an array large enough to reach it.
Basically: Timsort is to mergesort as pdqsort is to quicksort
It’s the other way around, since timsort is a decade older than pdqsort.
It iterates through the list, and deletes every item in the list that isn't ordered. The remaining list is therefore automatically ordered.
[1]: https://towardsdatascience.com/esoteric-sort-algorithms-and-...
I'm not big into algorithms but I believe that pdqsort and timsort were supposed to be the best two general sorts.
Stable. It’s a hybrid mergesort.
Some of the langages which adopted it after Python are Java, Rust, or Swift.
* <p>The implementation was adapted from Tim Peters's list sort for Python
* (<a href="http://svn.python.org/projects/python/trunk/Objects/listsort.txt">
* TimSort</a>). It uses techniques from Peter McIlroy's "Optimistic
* Sorting and Information Theoretic Complexity", in Proceedings of the
* Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,
* January 1993.[1] https://hal-upec-upem.archives-ouvertes.fr/hal-01212839/file...
So with benchmarking the challenge is coming up with a set of real world-like test data that feels representative but isn’t just excessively playing to Timsort’s strengths. Not everyone’s “real world” data is the same.
Each cell can have a color indicating if TimSort beats, say, some other hybrid of MergeSort; green shades suggest TimSort is winning, red shades suggest the contender is winning.
For each cell, do multiple runs with those sortedness/length parameters and pick the average.
A few years before Timsort there was someone randomly shuffling the input in order to avoid the reverse-order corner case that kills so many sort algorithms.
For truly random inputs, about half of the entries should be pairs that are partially ordered, and 25% runs of 3, no? And if memory serves Timsort also has a fast path for strictly decrementing runs as well, where it amortizes some of the comparisons done in the scan phase to do a blind reverse() call.
[1] https://github.com/python/cpython/blob/main/Objects/listsort...
Show me a sort algorithm that is still efficient with five pointer indirections in compare() and I'm satisfied. Show me primitive data types and I start to wonder what you're hiding (read: lying about).
In languages which try to be efficient, surely an expensive compare function is the outlier.
Why would lacking in evidence and rigor be considered a plus?
Does Timsort pride itself of being the homeopathy of sorting algorithms?
What a bizzare brag to make.
The point it’s making is about heuristics rather than theoretical complexity. Tim Peters provided plenty of evidence and rigorous work when he proposed it.
That you interpret it as “lack of evidence and rigor” is really about you.
Hence why I'm saying what a weird brag. It's not even true.
It's especially "dangerous" in this case because the people who would even care about sorting algorithms are going to contain a subset of people who knows a lot about sorting. Those people are likely to know about Timsort. It's like going to a heart surgery conference and having a presentation about "This one heart surgery method you never knew about." Good chance at least a few people in the audience would know and may have invented it.
http://www.envisage-project.eu/proving-android-java-and-pyth...
Nevertheless, the article was good.
If the author is reading this, consider dropping the "you've never heard of" from the title; you don't want to assume things about your reader.
Unfortunately I cannot downvote.
Please don't link plagiarized content. This guy also linked to his own "Big O Notation" in his page, where he says O(n) is polynomial
>>>In our shopping list example, in the worst-case of our algorithm it prints out every item in the list sequentially. Since there are n items in the list, it takes O(n) polynomial time to complete the algorithm.