Computer science has 5 main sorting algorithms; Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, and Quick Sort. My friend Lindsay described how these sorts work in depth in her post and my friend Leon described the effiency in great detail in his post. So instead, I'll be breaking down the idea of sorting algorithms into simple English.
Note: A sorting algorithm is considered stable if it keeps the relative order.
Let's steal a highschooler's binder, any binder. You open it up and you'll probably notice a plethora of notes. Some pages will have notes that were taken in class, some pages will have small notes taken from the readings (
So, for the sake of his sanity during exam time, this student is going to organize his binder. This brings us to the main part of this point, which sorting method will work best for him?
(Going with the assumption that he's sorting by chronilogical order, i.e. Civil War first, then World War One, then silly doodles in far back.)
Bubble Sort:
Imagine if he used bubble sort through the whole thing. Going through the entire binder swapping pages, going through it over and over, not really knowing where pages are supposed to go. Of course this might seem okay if there's only a few pages but what if there were hundreds of pages? Would you really want to repeat this method like that? You know you're wasting time, the page you had just a few moment prior would have been perfect in this position but it's all the way back there. Would you really want to waste all that time? You could be studying, watching bad finales,
Now of course if this binder had been completely and perfectly sorted, you'd know it immediately. You go through it and you didn't have to make a swap you'll know perfectly well that everything is completely sorted.
Selection Sort:
So the student decides bubble sort is not the sort he wants to use. So he decides to change his methodology slightly. Instead of swaping pages everytime, he only swaps pages once. He keeps a tab of where the latest one is and siwtches tabs when he finds one bigger. When he gets to the part that he's already sorted, he'll swap the page before it was properly sorted with the one that he had tabbed.
Good job student. You've become slightly more efficent! But you're still not being your most efficient. You're swapping things. Swapping can be annoying. You'll have to keep a tab of where the page is supposed to go, put the page somewhere for safe keeping as you do all this flipping. Again, if you're looking at only maybe 3 sheets whatever, you're young, you're independent, you don't need no rules. But when you're looking at 500 + or even maybe 20+ yeah you might want to rethink your strategy...
Insertion Sort:
So the student has decided to scrap it all. Start fresh. So the smart student decides to sort it in parts. He pretends the first page is sorted, then he places the next page relative to the first page. Now these two make up the sorted pile and he continues this trend.
Yay he's learning! Though what if his notes were in backwards order? Then he'd have to go check every page to find the earliest. But on the plus side it's stable! So everything that has to do with the same time period will be in the proper order (i.e. If it wasn't stable his notes might look like: "World War Two was the Allies vs the Axis. Germany took over France. France was totally prepared for war!". When it is stable his notes would look like: "World War Two was the Allies vs the Axis. France was totally prepared for war! Germany took over France.")
Merge Sort:
Okay so the student was pretty smart thinking about insertion sort. But he could be more efficent. When the battle gets tough divide and conquer.
Take out all the pages, consistently split the pages in about half until there's no page left or only one page left.
The problem with this is that you'll need more space then the other two, since you'll need a place to keep all these sections. And this will get REALLY problematic when you have a LOT of papers and then you'll need a really big table. But it's going to be stable and it's worst case is actually pretty fast!
Quick Sort:
Isn't merge sort efficent? But this student's table isn't that big, if he tried to use merge all the papers would probablly fall off the table and everything gets ruined and breaks. So then he can settle for Quick Sort. It's a bit slower than merge but hey it takes half the space and not stable.
Take the first page and let that be your "pivot". Put the ones earlier than the pivot to the left and everything later than the pivot to the right.
This becomes as slow as bubble or insertion since there might be nothing smaller than your pivot so you'll consistently be sorting large lists. But this can be fixed by picking a random page as your pivot and hoping for the best!
And that's the end of the metaphor.
TLDR:
Bubble - Don't do it, unless you're list is almost sorted
Selection - It's all around better than bubble but not as good in the best case and just as bad in worst case
Insertion - Decently fast and stable, but only really ideal for small lists
Merge - Fast but takes up a lot of space
Quick - As a general faster than the first three, slower than merge and usually takes less space than merge