## Counting sort:

- Assumption: input is in the range 1..k
- Basic idea:
- Count number of elements k ? each element i
- Use that number to place i in position k of sorted array

- No comparisons! Runs in time O(n + k)
- Stable sort
- Does not sort in place:
- O(n) array to hold sorted output
- O(k) array for scratch storage

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