Skip to content

Instantly share code, notes, and snippets.

@Foredoomed
Created October 27, 2012 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Foredoomed/3963342 to your computer and use it in GitHub Desktop.
Save Foredoomed/3963342 to your computer and use it in GitHub Desktop.
Markdown Table
| Sort | Average | Best | Worst | Space | Stability | Remarks |
|----
| Bubble sort | O(n^2) | O(n^2) | O(n^2) | Constant | Stable | Always use a modified bubble sort |
| Modified Bubble sort | O(n^2) | O(n) | O(n^2) | Constant | Stable | Stops after reaching a sorted array |
| Selection Sort | O(n^2) | O(n^2) | O(n^2) | Constant | Stable | Even a perfectly sorted input requires scanning the entire array |
| Insertion Sort | O(n^2) | O(n) | O(n^2) | Constant | Stable | In the best case (already sorted), every insert requires constant time |
| Heap Sort | O(nlog(n)) | O(nlog(n)) | O(nlog(n)) | Constant | Instable | By using input array as storage for the heap, it is possible to achieve constant space |
| Merge Sort | O(nlog(n)) | O(nlog(n)) | O(nlog(n)) | Depends | Stable | On arrays, merge sort requires O(n) space; on linked lists, merge sort requires constant space |
| Quicksort | O(nlog(n)) | O(nlog(n)) | O(n^2) | Constant | Stable | Randomly picking a pivot value (or shuffling the array prior to sorting) can help avoid worst case scenarios such as a perfectly sorted array |
{: class="datalist" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment