frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

When would you ever want bubblesort? (2023)

https://buttondown.com/hillelwayne/archive/when-would-you-ever-want-bubblesort/
40•atan2•2h ago

Comments

caycep•2h ago
I learned this from President Obama...
sdsd•48m ago
For the downvoters, he's referring to this instance when (then) Senator Obama jokingly referenced bubble sort during this Google event: https://www.youtube.com/watch?v=koMpGeZpu4Q

It was one of the many viral moments during Obama's original campaign where he seemed cool and in touch.

beeforpork•1h ago
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).
nick__m•1h ago

  if you apply quicksort to 2^20 random integers, at some point you're sorting 2^17 8-integer subpartitions
why not use an 8 wide optimal sort network for those 8 integers?
observationist•1h ago
Embarrassingly parallel sort, lol.
13415•1h ago
Well, I used Bubblesort to sort the results of lottery draws because it was very easy to implement.
zitterbewegung•1h ago
Related to this is Timsort which combines merge sort and insertion sort https://en.wikipedia.org/wiki/Timsort
aappleby•1h ago
Can confirm, have used bubble sort for incrementally sorting particles in a particle system and plants in a terrain renderer.
jandrewrogers•1h ago
The only use I've seen is incrementally sorting large arrays during brute-force search of said arrays, since that is approximately free and brute-force search is pretty efficient and fast on modern CPUs. Set a "sorted" flag if/when the array is eventually sorted.

The idea was that the vast majority of arrays in a large set are not searched often enough to justify the cost of sorting them and sorting is an expensive operation if you are computing on a deadline. You also don't always know which ones will be heavily searched ahead of time. Using bubblesort, only the heavily accessed arrays end up sorted but as a side-effect of search rather than having separate heuristics to decide when/what to sort.

pestatije•1h ago
to compare other sort algos against it
zeta0134•1h ago
I used bubblesort on purpose in a game project. Specifically, to sort sprites in an NES game back to front, lazily, spending as few CPU cycles as possible. Bubblesort on the very small list (a dozen objects max), and early exit after the first swap. It eventually completes, and that was just fine. It's tiny, incredibly simple, and somewhat resilient to the list changing from frame to frame as objects spawn and despawn. Each partial sort makes some progress no matter what.

A few other algorithms would have fit the bill just as well, but bubblesort is perfectly adequate, so that's what will likely ship. More complex algorithms end up losing out due to greater initial overhead or larger ROM size.

JSR_FDED•1h ago
I’ve used it when I didn’t want the hassle of another dependency
jhallenworld•13m ago
I've used it on a tiny microcontroller because libc's quicksort was huge.
mhandley•55m ago
I've used bubblesort when simulating LEO satellite constellations, calculating which satellite is closest to a location. I used one single backwards pass of bubblesort, so O(n) every k timesteps to bring the closest to the head of the array, then every timestep just do one backwards bubblesort pass over the first few in the array. Given satellites move smoothly, if you initialize right (a few full passes at the start to get the closest few at the front) and get the constants right so a satellite outside the front few in the array can't have moved far enough to become closest without being promoted to the front few by a periodic full pass, then you always maintain the closest at the front of the array very cheaply. And this has the advantage of also being very simple to code.
ErroneousBosh•42m 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?
dspillett•24m ago
For small sets, or small-ish sets when you are coding quick, don't have a convenient standard library sort to hand, and are prioritising correctness over absolute performance.

Though in reality almost never: you almost always have a convenient built-in sort that is as quick & easy to use (likely quicker & easier), and in circumstances where the set is small enough for bubblesort to be just fine, the speed, memory use, or other properties of what-ever other sort your standard library uses aren't going to be a problem either.

As others have pointed out, sometimes it is useful for partial sorts due to the “always no less sorted than before at any point in the process (assuming no changes due to external influence)” property.

wrt:

> If you make each frame of the animation one pass of bubblesort, the particles will all move smoothly into the right positions. I couldn't find any examples in the wild,

There are hundreds of sort demos out there, both live running and on publicly hosted videos, that show the final positions by hue, getting this effect. Seems odd that they couldn't find a single one.

EDIT: actually, I can't find any of the rainbow based sort demos I was thinking of, a lot of promising links seem dead. I take back my little moan!

Size of Life

https://neal.fun/size-of-life/
1247•eatonphil•8h ago•167 comments

Australia begins enforcing world-first teen social media ban

https://www.reuters.com/legal/litigation/australia-social-media-ban-takes-effect-world-first-2025...
495•chirau•1d ago•776 comments

Getting a Gemini API key is an exercise in frustration

https://ankursethi.com/blog/gemini-api-key-frustration/
148•speckx•3h ago•66 comments

Auto-grading decade-old Hacker News discussions with hindsight

https://karpathy.bearblog.dev/auto-grade-hn/
257•__rito__•6h ago•129 comments

Super Mario 64 for the PS1

https://github.com/malucard/sm64-psx
138•LaserDiscMan•5h ago•44 comments

Rubio stages font coup: Times New Roman ousts Calibri

https://www.reuters.com/world/us/rubio-stages-font-coup-times-new-roman-ousts-calibri-2025-12-09/
108•italophil•1d ago•218 comments

When would you ever want bubblesort? (2023)

https://buttondown.com/hillelwayne/archive/when-would-you-ever-want-bubblesort/
41•atan2•2h ago•16 comments

How Google Maps allocates survival across London's restaurants

https://laurenleek.substack.com/p/how-google-maps-quietly-allocates
87•justincormack•1d ago•42 comments

Common Lisp, ASDF, and Quicklisp: packaging explained

https://cdegroot.com/programming/commonlisp/2025/11/26/cl-ql-asdf.html
26•todsacerdoti•13h ago•4 comments

Terrain Diffusion: A Diffusion-Based Successor to Perlin Noise

https://arxiv.org/abs/2512.08309
90•kelseyfrog•5h ago•11 comments

Qwen3-Omni-Flash-2025-12-01:a next-generation native multimodal large model

https://qwen.ai/blog?id=qwen3-omni-flash-20251201
180•pretext•7h ago•79 comments

Scientists create ultra fast memory using light

https://www.isi.edu/news/81186/scientists-create-ultra-fast-memory-using-light/
56•giuliomagnifico•6d ago•12 comments

The future of Terraform CDK

https://github.com/hashicorp/terraform-cdk
74•mfornasa•4h ago•76 comments

Show HN: Automated license plate reader coverage in the USA

https://alpranalysis.com
91•sodality2•6h ago•56 comments

Gundam is just the same as Jane Austen but happens to include giant mech suits

https://eli.li/gundam-is-just-the-same-as-jane-austen-but-happens-to-include-giant-mech-suits
134•surprisetalk•1w ago•99 comments

Valve: HDMI Forum Continues to Block HDMI 2.1 for Linux

https://www.heise.de/en/news/Valve-HDMI-Forum-Continues-to-Block-HDMI-2-1-for-Linux-11107440.html
472•OsrsNeedsf2P•6h ago•266 comments

Is it a bubble?

https://www.oaktreecapital.com/insights/memo/is-it-a-bubble
119•saigrandhi•6h ago•138 comments

Launch HN: InspectMind (YC W24) – AI agent for reviewing construction drawings

36•aakashprasad91•8h ago•42 comments

Largest EV manufacturer is coming to the Western market

https://newatlas.com/motorcycles/yadea-comes-to-europe/
34•breve•4d ago•34 comments

9 Mothers (YC X26) Is Hiring

https://app.dover.com/jobs/9mothers
1•ukd1•7h ago

Show HN: A 2-row, 16-key keyboard designed for smartphones

https://k-keyboard.com/Why-QWERTY-mini
46•QWERTYmini•6h ago•38 comments

Show HN: VoxCSS – A DOM based voxel engine

https://github.com/LayoutitStudio/voxcss
17•rofko•1w ago•0 comments

DeepSeek uses banned Nvidia chips for AI model, report says

https://finance.yahoo.com/news/china-deepseek-uses-banned-nvidia-131207746.html
276•goodway•7h ago•250 comments

Typewriter Plotters (2022)

https://biosrhythm.com/?p=2143
90•LaSombra•5d ago•6 comments

Golang's big miss on memory arenas

https://avittig.medium.com/golangs-big-miss-on-memory-arenas-f1375524cc90
84•andr3wV•6d ago•63 comments

Factor 0.101 now available

https://re.factorcode.org/2025/12/factor-0-101-now-available.html
99•birdculture•12h ago•11 comments

RoboCrop: Teaching robots how to pick tomatoes

https://phys.org/news/2025-12-robocrop-robots-tomatoes.html
61•smurda•8h ago•33 comments

Why no one talks about React2Shell?

https://elenacross7.medium.com/react2shell-my-droplet-joined-a-botnet-c4850b079515
6•skilldeliver•12m ago•1 comments

Apple Services Experiencing Outage

https://www.apple.com/support/systemstatus/
105•rock_artist•3h ago•51 comments

I got an Nvidia GH200 server for €7.5k on Reddit and converted it to a desktop

https://dnhkng.github.io/posts/hopper/
162•dnhkng•4h ago•36 comments