Skip to content

Comment on Basic Data Structures and Algorithms in the Linux Kernelparent

Comments

Bubble sort is good for sorting particles in a particle system. Particles need to be drawn from the furthest from the camera to the closest to the camera.

Each frame the particles move a little bit, and the camera moves a little bit.

That means that in a given frame most, if not all, of the particles are probably already sorted. In addition, if the sort order has changed, it's probably only requires swaps of adjacent particles.

Because of this, bubble sort is often best sort to use for this operation.

Wouldn't insertion sort be even better then? As far as I recall insertion sort is always better than bubble sort, easier to understand too so I do not see why bubble sort is so popular in CS courses.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.