Sorting is foundational. The right choice depends on data size, distribution, memory constraints, and stability requirements. This edition covers quicksort, mergesort, heapsort, and linear-time sorts: radix, counting, and bucket.
ā
Quick picks:
- Need stable sort with predictable O(n log n): use mergesort (or Timsort in practice).
- Tight memory, good average case: use quicksort (in-place, but watch pivot strategy).
- Worst-case guarantees without extra memory: use heapsort.
- Integers with small/known range or fixed-width keys: use counting/radix.