Thursday, 20 February 2014
Little mini rant:
Out of all the sorts, the quick sort is (obviously) the quickest, given its' name. But that's not the only reason (it would be cool if it was - just say QUICKSORT and it becomes the quickest). The REASON it's a quick sort is because it uses recursion which always quick (and really confusing). And then there are a bunch of other sorts that don't use recursion like insertion, selection, and bubble sort. The insertion sort, I have a feeling is the one of the slower sort seeing as though it compares every single value, and then checks to see whether it is greater or less than, and then moves them accordingly. For example, if you were searching fro something that is alphabetical, the insertion sort would look at a certain index, say '1', and check whether the current index or the one above it is greater. If it is greater, they are flipped; if not, they remain the same, and we test it on another value. One of the problems with this method is that even though something is at the top of the list and in the right space, the program still has to check it unlike in selection sort or bubble sort, where the minute something is moved, it's officially moved. The selection sort, makes this a lot more convenient, where instead of checking one next to the other, it finds the largest item in the list and exchanges that with the top (cause it would be on the top either way). And then, it switches every one that needs to be switched in the remaining list. The bubble sort, which, I think is the easiest to memorize does this in a different way. The bubble sort goes through the list exchanging the larger values to the right side and keeps going until the largest value is at the top. And it continues this until the entire list is sorted when nothing else has to be sorted, it's done.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment