• 2 Posts
  • 1 Comment
Joined 1 year ago
cake
Cake day: July 2nd, 2025

help-circle
  • As the addendum to the paper points out, this is more like insertion sort (with i and j in a confusing order) than bubble sort. The actual “important” part of the algorithm happens when j < i. (In fact, I’m quite certain there aren’t even any swaps when j >= i after the first outer iteration.) (I think the page about people misremembering bubble sort is also worth looking at.)

    Honestly, I think this might actually be “better” than bubble sort, in the sense that at least it’s incredibly easy to remember and not that hard to get correct. The only place where you could realistically mess up is confusing the relative order of i and j – and any amount of nontrivial testing will immediately show the error, since it reverses the sort order. I’d probably reach for this if I, for whatever insane reason, had to code up a sorting algorithm by hand for some task where O(n^2) sorting was acceptable performance-wise. “Sort a list of 10 items in a very primitive programming language”-type deal.

    (Now that I say that, I’m kind of tempted to use it in some example program for my own in-development programming language, which currently doesn’t have a builtin sort function…)