Sorting Flashcards
Describe how insertion sort works
start off from the left sort ONE element first, then sort TWO elements we'll have a SORTED list on the left Adv: - less swaps - works well on mostly sorted lists
Describe how selection sort works
Choose the largest number and swap it with the last element
Repeat for next largest number and the unsorted subset
Adv:
- less comparisons
Describe how bubble sort works
start from left
swap element if the element is larger than the adjacent right element
repeat until (no swaps in one traversal) or until the end
Describe how shell sort works
a.k.a diminishing increment sort
c.f insertion sort, except insertion sort for larger increments
Divide list into smaller sub-lists by choosing every nth element
sort smaller lists using insertion sort
Decrease the increment
worst case ==> O(n^2)
Describe how merge sort works
Split list into two, repeatedly
Merge and sort the small lists together
O(n log n)
Describe how quick sort works
Choose a pivot point Sort elements (smaller values to pivot to the left, larger values to pivot to the right)
Describe how Timsort works
Hybrid sort
Finds runs of sorted elements using insertion sort
Merges them together using merge sort