Sorting in Linear Time

Counting sort never compares two elements: it counts how many times each key 0..k occurs in A, turns the counts into positions in C, and copies each element straight to its place in B. Radix sort runs a stable counting sort once per digit, starting with the least significant.

Algorithm:
Speed:
Sample input:
Input array
Counts and positions
Output array