Jump to content

Sorting algorithms/Counting sort: Difference between revisions

m
2^32 = 4Gbytes, not 16.
m (2^32 = 4Gbytes, not 16.)
Line 22:
The ''min'' and ''max'' can be computed apart, or be known ''a priori''.
 
'''Note''': we know that, given an array of integers, its maximum and minimum values can be always found; but if we imagine the worst case for an array of 32 bit integers, we see that in order to hold the counts, we need an array of 2<sup>32</sup> elements, i.e., we need, to hold a count value up to 2<sup>32</sup>-1, more or less 164 Gbytes. So the counting sort is more practical when the range is (very) limited and minimum and maximum values are known ''a priori''. (Anyway sparse arrays may limit the impact of the memory usage)
 
=={{header|Ada}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.