Top
Best
New

Posted by atan2 1 day ago

When would you ever want bubblesort? (2023)(buttondown.com)
106 points | 86 commentspage 3
lucraft 22 hours ago|
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.

pilord314 1 day ago||
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.

opensourcemaxi 1 day ago||
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.
LorenPechtel 1 day ago||
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.

whateveracct 1 day ago||
it's great if you need to sort in the face of unreliable memory iirc
ErroneousBosh 1 day ago||
If you need a stable sort, can't be bothered finding a massive oversize library to link to, and only need to sort a relatively small number of objects on a system that's resource-constrained, I'm guessing?
thomasmg 1 day ago|
I'm surprised that the simple, ~80 lines version of stable-in-place merge sort (see link in the above comments) is not more widely known. It is O(n log n log n) and not all that hard to implement.
13415 1 day ago||
Well, I used Bubblesort to sort the results of lottery draws because it was very easy to implement.
AnimalMuppet 1 day ago||
In all your big-O analyses, remember: n = 3 more often than you think. n = 12 a lot more often than you think. If that's your case, there's nothing wrong with bubble sort unless you have very tight performance constraints.

Worse, big-O always hides a constant factor. What's bubblesort's constant? What's quicksort's? It wouldn't surprise me if, for small enough n (2 or 3, and maybe a bit higher), bubblesort is actually faster.

Note well: I have not actually benchmarked this.

Also note well: Determine what your n is; don't assume that it's either large or small.

pestatije 1 day ago|
to compare other sort algos against it
More comments...