Top
Best
New

Posted by atan2 12/10/2025

When would you ever want bubblesort? (2023)(buttondown.com)
108 points | 86 commentspage 3
beeforpork 12/10/2025|
A: For small arrays. I would add: particularly if you need a stable sort algorithm, which is either complex (Block Sort) or uses O(n) space (Merge Sort).
thomasmg 12/11/2025|
There is stable in-place merge sort [1], which is O(n*log(n)^2) and not that complex or hard to implement (about 80 lines, and that includes the ~15 lines of binarySearch, which you might need anyway).

[1] https://github.com/thomasmueller/bau-lang/blob/main/src/test...

kazinator 12/11/2025||
Doesn't Shell sort also have the property of the exchanges leaving the array more ordered than before?

https://en.wikipedia.org/wiki/Shellsort

Shellsort can be regarded as an improvement over either Bubble Sort or Insertion Sort.

13415 12/10/2025||
Well, I used Bubblesort to sort the results of lottery draws because it was very easy to implement.
opensourcemaxi 12/11/2025||
bubble sort is sometimes used in information retrieval use cases for reranking top k based on some signals, especially specific to a user profile. I feel heap sort comes up as well, yet neither are necessarily the most efficient.
pilord314 12/11/2025||
When you get into C code sometimes you know the most thinngs that will be in the priority queue is like 3. So bubble sort is fine.

You can also do something like a calendar queue with bubble sort for each bin.

LorenPechtel 12/11/2025||
Used it a couple of times when n was inherently very low.

And while I've never hit a case I would think it would have merit with data known to be pretty close to properly sorted.

lucraft 12/11/2025||
It's way easier to remember and program

When I was playing The Farmer Was Replaced and needed to implement sorting, I just wrote a bubble sort. Worked first time.

pestatije 12/10/2025||
to compare other sort algos against it
whateveracct 12/11/2025|
it's great if you need to sort in the face of unreliable memory iirc
More comments...