Skip to content

Instantly share code, notes, and snippets.

@thejoycekung
Last active August 3, 2017 23:35
Show Gist options
  • Save thejoycekung/7b7070483c40d1fa23482c010a7ca0e6 to your computer and use it in GitHub Desktop.
Save thejoycekung/7b7070483c40d1fa23482c010a7ca0e6 to your computer and use it in GitHub Desktop.

Insertion: Empty sequence. Insert each item into right spot in sequence.

Selection: Select first element. If any > 1st, switch the two. Then select the second. etc etc etc

Merge: Split the list in two until you're left with two-element lists. Sort and merge with another two-element list. Keep going until you're done.

Quick: Pick a pivot (normally the first item). Move all > pivot items to the back and all < pivot itmes to the front. Recursively sort "small" array and "large" array using the same method.

Sort Method Best Case Worst Case
Insertion O(n) O(n^2)
Selection O(n^2) O(n^2)
Merge O(nlogn) O(nlogn)
Quick O(nlogn) O(n^2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment