Many programmers consider the quicksort to be the fastest sorting algorithm available.
Technically its not.
There is a sort called the Merge Sort which takes a recursive means of sorting.
Let me give you a comparison. I hope you understand Big O notation, its pretty easy.
Bubble Sort:
- Data are in completely random order: O(n^2)
- Data are ordereed from lowest to highest: O(n)
- Data are ordered from highest to lowest: O(n^2)
Insertion Sort:
- Data are in completely random order: O(n log(n))
- Data are ordereed from lowest to highest: O(n)
- Data are ordered from highest to lowest: O(n log(n))
-I'm not 100% sure that these are the correct Big O runtimes for the Insertion sort.
Quick Sort:
- Data are in completely random order: O(n log(n) )
- Data are ordereed from lowest to highest: O(n^2)
- Data are ordered from highest to lowest: O(n^2)
Merge Sort:
- Data are in completely random order: O(n log(n) )
- Data are ordereed from lowest to highest: O(n log(n) )
- Data are ordered from highest to lowest: O(n log(n) )
As you can see, the Bubble sort is only good, when the list is already sorted. However your not going to sort an already sorted list.
The Quick sort is awesome when the list is random. However, if the list isn't completely random, and is only off by a few elements, it takes longer.
The Merge sort is consistent, providing O(n log(n) )
If you don't know, "n" is the number of elements in the list you are sorting.
People say the Quick Sort and Binary Search are related, because Binary Search uses the same technique and a Binary Search also has O(n log(n) ).
I have no code on the merge sort in any language I just know its there. One of the reasons that the Merge Sort proves to be more effective then the Quick Sort is that the Quick Sort is implemented in such a way to save Memory. The Merge Sort uses a recursive method and therefore, uses a ton of memory.
The Insertion sort looks better then the Merge sort, but I'm not 100% sure that I have the correct Big O runtimes for the insertion sort.
Anyways, I just posted this because I wanted to share information that I had.
Comment/Reply (w/o sign-up)