June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,7 +1,11 @@
|
|||
{{Sorting Algorithm}}
|
||||
{{Wikipedia|Counting sort}}
|
||||
|
||||
|
||||
;Task:
|
||||
Implement the [[wp:Counting sort|Counting sort]]. This is a way of sorting integers when the minimum and maximum value are known.
|
||||
|
||||
|
||||
Pseudocode:
|
||||
'''function''' ''countingSort''(array, min, max):
|
||||
count: '''array of''' (max - min + 1) '''elements'''
|
||||
|
|
@ -21,3 +25,4 @@ Pseudocode:
|
|||
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 4 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)
|
||||
<br><br>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue