Counting sort

How do you order number cards when many carry the same number? First count how often each number appears.

Give every integer from the minimum to the maximum a counter. If the minimum is −2, then −2 uses slot 0 and 1 uses slot 3.

Visit the counters from left to right. If the counter for 2 shows ×3, write three twos into the row.

For n cards and k possible values this takes O(n + k) time and O(k) extra space. Even two widely separated numbers need a large table.