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
Bead sort bead sort is unusual in that in worst case it can perform faster than "O"("n" log "n"), the fastest performance possible for a comparison sort in worst case. This is possible because the key for a bead sort is always a positive integer and bead sort exploits its structure. This example is written in Python. The strategy for "dropping" the beads may be slightly different, but it does the same job. def Gravity(obj): """how it does it: it counts the "beads" in each column, then uses those numbers to make a new set of rows. Adding up the beads in