Rank sort
| Class | Sorting algorithm |
|---|---|
| Data structure | Array |
| Worst-case performance | comparisons |
| Best-case performance | comparisons |
| Average performance | comparisons |
| Worst-case space complexity | total, auxiliary |
In computer science, rank sort[1] (or enumeration sort [2]) is an algorithm for sorting a collection of objects by counting for each object the number of objects in the collection that are smaller than it, allowing one to deduce the rank of the object in the sorted array. [3]
Pseudocode
In pseudocode, the algorithm may be expressed as:
function RankSort(input) is
rank ← array of same length as input, initialized with zeroes
output ← array of same length as input
for i = 0 to length(input) - 1 do
for j = 0 to length(input) - 1 do
if input[j] < input[i] then
rank[i] = rank[i] + 1
for i = 0 to length(input) - 1 do
r = rank[i]
output[r] = input[i]
return output
Where input is the array to be sorted, rank is an auxiliary array used to store the rank of each items and output is the sorted output array.
As stated, the algorithm works only if all items are different. In case of an array with identical elements, the algorithm can be modified to accord for it, by counting also identical elements with an index smaller than it.
References
- ↑ Rank Sort - MobyLab
- ↑ Enumeration Sort (PDF)
- ↑ Knuth, D. E. (1998), The Art of Computer Programming, Volume 3: Sorting and Searching (2nd ed.), Addison-Wesley, ISBN 0-201-89685-0. Section 5.2, Sorting by counting, pp. 75–78.
This article "Rank sort" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Rank sort. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
