Definition: A 2-pass sort algorithm that is efficient when the range of keys is small and there many duplicate keys. The first pass counts the occurrences of each key in an auxiliary array, and then makes a running total so each auxiliary entry is the number of preceding keys. The second pass puts each item in its final place according to the auxiliary entry for that key.
Generalization (I am a kind of ...)
See also American flag sort, bingo sort, pigeonhole sort.
Note: A bucket sort uses fixed-size buckets. A histogram sort sets up buckets of exactly the right size in a first pass. A counting sort is a histogram sort with one bucket per possible key value. A pigeonhole sort is a counting sort that moves items to the auxiliary array instead of counting them.
If you have suggestions, corrections, or comments, please get in touch with Paul Black.
Entry modified 2 June 2006.
HTML page formatted Mon Nov 18 10:44:09 2013.
Cite this as:
Art S. Kagel, "counting sort", in Dictionary of Algorithms and Data Structures [online], Vreda Pieterse and Paul E. Black, eds. 2 June 2006. (accessed TODAY) Available from: http://www.nist.gov/dads/HTML/countingsort.html