## Counting sort

- No comparisons between elements!
- But…depends on assumption about the numbers being sorted
- We assume numbers are in the range 1.. k

- The algorithm:
- Input: A[1..n], where A[j] ? {1, 2, 3, …, k}
- Output: B[1..n], sorted (notice: not sorting in place)
- Also: Array C[1..k] for auxiliary storage

Previous slide | Next slide | Back to first slide | View graphic version |