3 ms·
>> There are too many non-trivial algorithms that you are just likely to not rediscover. > I agree, but would also (respectfully) ask, "So what?" Well, if you
by cabalamat 16y ago
>> There are too many non-trivial algorithms that you are just likely to not rediscover.
> I agree, but would also (respectfully) ask, "So what?"
Well, if you're trying to sort big arrays with bubblesort, you may have to wait a long time...
- Jach 16y agohttp://warp.povusers.org/grrr/bubblesort_eng.html http://warp.povusers.org/grrr/bubblesort_eng.html >Teaching bubble sort as some kind of "basic sorting algorithm" has real-life negative consequences. This is a real-life example: this is a piece of code in the gnu flex program: /* We sort the states in sns so we * can compare it to oldsns quickly. * We use bubble because there probably * aren't very many states. */ bubble (sns, numstates); >There's absolutely no rational reason why bubble sort was used here instead of insertion sort. Bubble sort can only be slower, and it's not in any way easier to implement.
- cgoddard 16y agoActually for small values of n, an n^2 sort can be quicker than an nlogn sort, depending on how it is implemented.
- Jach 16y agoYeah, hence insertion sort (the best n^2 sorter) is used to speed up quick-sort. It's insane to think of using bubble sort for the same task. (And for n=2, you don't need a sorting algorithm.)