3 ms·
> I was nearly-always sorting <4 elements (and often just 1, or even 0). In my opinion, a bubble sort is a solid choice for that sort of use case.
by JohnFen 3y ago
> I was nearly-always sorting <4 elements (and often just 1, or even 0).
In my opinion, a bubble sort is a solid choice for that sort of use case.
- Trufa 3y agoAre you being cheeky? Cause I would think insertion sort would be a more than reasonable alternative
- JohnFen 3y agoNo, I'm serious. With datasets that small, there's very little performance difference between the two methods, so a bubble sort isn't unreasonable at all. Depending on the circumstances, a bubble sort can be the better choice due to other considerations becoming relatively more important.
- bastawhiz 3y agoIn what way?
- usefulcat 3y agoEspecially if there’s little or no performance difference, may as well minimize code size.
- financltravsty 3y agoIs everyone here feeling a bit... devilish? I would pick a standard library sort function at that point.
- grog454 3y agoFor <4 elements, a pure "if" / "else" implementation would probably be optimal.
- layer8 3y agoBut more tedious and somewhat more error-prone to write by hand.