Non-comparison sorts beat but only under specific conditions.
Use counting sort when:
- Values are integers in a small range where .
- Example: Sorting exam scores from to for students.
Use radix sort when:
- Values are integers or strings with bounded length.
- The number of digits is small compared to .
- Example: Sorting integers up to . Radix sort takes because in base .
Avoid them when:
- Range is huge (counting sort needs space).
- Values are floats or arbitrary objects.
- You need in-place sorting with extra space.