logoalt Hacker News

AnimalMuppettoday at 2:24 AM0 repliesview on HN

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.