Counting Sort
A non-comparison sort that counts occurrences of each value and reconstructs the array in order.
Interactive Visualization
Loading visualization…
Usage
import { countingSort } from 'athro';
const arr = [4, 2, 2, 8, 3, 3, 1];
countingSort(arr);
Note
Works best when the range of input values is small relative to array length.
Time Complexity
| Case | Time Complexity | Description |
|---|---|---|
| Best | O(n + k) | k is the value range |
| Average | O(n + k) | Linear scan of counts |
| Worst | O(n + k) | Same regardless of input order |