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
Adaptive sort sorted items. In pseudo-code form, the "Straight Insertion Sort" algorithm could look something like this (array X is zero-based): The performance of this algorithm can be described in terms of the number of inversions in the input, and then will be roughly equal to , where is the number of Inversions. Using this measure of presortedness – being relative to the number of inversions – "Straight Insertion Sort" takes less time to sort the closer it is to being sorted. Other examples of adaptive sorting algorithms are adaptive heap sort, adaptive merge sort, patience sort, Shellsort, smoothsort, splaysort and Timsort.