Sorting
- Input: Unordered collection of size n
- Output: Ordered collection of size n
- Properties
- Stable sort: the order between equal elements remains after sorting
Basic Sorts
| Case | Selection | Bubble | Insertion |
|---|---|---|---|
| Worst | (reversed) | (reversed) | |
| Average | |||
| Best | (already sorted) | (already sorted) | |
| Space |
Advanced Sorts
| Case | Shell | Merge | Quick |
|---|---|---|---|
| Worst | (bad pivots chosen) | ||
| Average | |||
| Best | |||
| Space | (from recursion stack) |
- Shell Sort
- Merge Sort
- Quick Sort
- Heap Sort
- Tim Sort
- Radix Sort
- Bucket Sort
Funny Sorts
- Sleep Sort
- Counting Sort
- BOGO Sort
Lower Bound
Theorem
Any deterministic compare-based sorting algorithm must make compares in the worst case
Proof:
- Assume array consists distinct values through .
- Worst-case number of compares = height of comparison tree.
- Binary tree of height has leaves.
- different orderings reachable leaves.
- So (using sterling’s formula):