Nah, you're right. That's why I said "equal or better algorithm". To my understanding, insertion overall would be better still, because as soon as you mess with that optimal scenario (un-sort the data a bit) bubble becomes slower.
If you had a data set that you could be assured would always come pre-sorted, then there'd be no difference between bubble and insertion. (You also wouldn't need a sort algo in the first place, but that's beside the point)
If bubble is the best algo, it's only because it's equal with another algo. It'll never be a lone upgrade.
Yes. Though the space savings are very small (Insertion Sort is also very simple), and the performance losses are very large on some lists, so in most cases even if code size important Insertion Sort should be preferred.
21
u/Gangsir Dec 03 '19
Nah, you're right. That's why I said "equal or better algorithm". To my understanding, insertion overall would be better still, because as soon as you mess with that optimal scenario (un-sort the data a bit) bubble becomes slower.
If you had a data set that you could be assured would always come pre-sorted, then there'd be no difference between bubble and insertion. (You also wouldn't need a sort algo in the first place, but that's beside the point)
If bubble is the best algo, it's only because it's equal with another algo. It'll never be a lone upgrade.