5 ms·
Why bubble sort? I never understood its popularity. Selection sort feels a lot more intuitive to me and it's the same complexity.
by aflag 7y ago
Why bubble sort? I never understood its popularity. Selection sort feels a lot more intuitive to me and it's the same complexity.
- mark-r 7y agoBubble sort is the first one I learned, so I remember it the best. I never spent any time comparing any of the O(n^2) sorts so it never occurred to me to try a different one.
- deleted 7y ago[deleted]
- carlhjerpe 7y agoAnd here am I, just using what's in the standard library. of the language I'm writing. Never occured to me to try a different one.
- mark-r 7y agoThis was quite a while ago, and the library sort was QSort which had a lot of overhead due to its calling convention. Today I'd have no problem using std::sort instead.
- ynik 7y agoBubble sort is popular because it's provably optimal... under extremely restrictive circumstances: https://stackoverflow.com/a/3274203 https://stackoverflow.com/a/3274203 Those circumstances stopped being semi-relevant when even the cheapest computers started using (floppy) disk drives instead of tape drives, but somehow bubble sort is still being taught.
- NeoBasilisk 7y agoIt's probably because the implementation of the algorithm is the simplest, because you don't need to modify the existing data structure. You don't need to merge or create new arrays. You just repeatedly loop and swap two elements when needed. Super easy by all metrics.
- vengefulduck 7y agoYou don’t need to modify the data structure for most quadratic sorts though. Or even for quick sort.
- BubRoss 7y agoMost people get the partition algorithm wrong on their first try if they write it themselves.