News for hackers. Stuff that matters.
Re:Is this the simplest (and most surprising) sorting algori... by thaumasiotes on Tuesday February 25, 2025 @12:12PM (#43174590)
> Following that it follows normal insertion sort pattern with one change. Insertion sort normally sorts the new element "downward". This sort sorts the new element "upward" from the smallest item. It still uses the same inline temporary slot that insertion sort uses, it's just more notable now because it's inserting the new item "bottom-up".

Well, the reason that's more notable is that doing it upward requires you to use swaps instead of an assignment chain. Going downward, you can remember the value you're going to insert all the way down the chain. Going upward, you're always placing the value you remember and then remembering a new value, which is much worse.

There are no comments on this comment yet.