Counting sort is applicable when each input is known to belong to a particular set, "S", of possibilities. The algorithm runs in O(|"S"| + "n") time and O(|"S"|) memory where "n" is the length of the input. It works by creating an integer array of size |"S"| and using the "i"th bin to count the occurrences of the "i"th member of "S" in the input. Each input is then counted by incrementing the value of its corresponding bin. Afterward, the counting array is looped through to arrange all of the inputs in order. This sorting algorithm often cannot be used because "S" needs to be reasonably small for the algorithm to be efficient, but it is extremely fast and demonstrates great asymptotic behavior as "n" increases. It also can be modified to provide stable behavior.