Counting sort initialization of the output array, each take time. Therefore, the time for the whole algorithm is the sum of the times for these steps, . Because it uses arrays of length and , the total space usage of the algorithm is also . For problem instances in which the maximum key value is significantly smaller than the number of items, counting sort can be highly space-efficient, as the only storage it uses other than its input and output arrays is the Count array which uses space . If each item to be sorted is itself an integer, and used as
Integer complexity every prime number is one plus the complexity of . Integer complexity In number theory, the integer complexity of an integer is the smallest number of ones that can be used to represent it using ones and any number of additions, multiplications, and parentheses. It is always within a constant factor of the logarithm of the given integer. For instance, the number 11 may be represented using eight ones: However, it has no representation using seven or fewer ones. Therefore, its complexity is eight. The complexities of the numbers 1, 2, 3, ... are The smallest numbers with complexity 1,