|
|
|
|
|
by deathanatos
667 days ago
|
|
The author covers this pretty much exactly as you describe it. From Part 2 of TFA, > Let’s look at the sort step, which is the bottleneck of the algorithm according to the analysis. > You can see that most of the time, the sort does nothing at all! The list is almost always already sorted from the previous frame. > Even when it becomes unsorted, it usually just takes a couple of swaps to be sorted again. > Here’s insertion sort in action: |
|
Rust's old sorts, both of them, get this right. There's a fair chance the current version of your C++ stdlib even gets this right in its unstable sort. In 1965 it's understandable that you reach for an insertion sort for this case, in 2024 it's embarrassing if your language doesn't provide a built-in sort where this just works.