If an array contains duplicated elements, what data structure is better for sorting?
Could B tree work?
If an array contains duplicated elements, what data structure is better for sorting?
Could B tree work?
For a fixed and small range of element values you can use counting sort algorithm, as described here. Its complexity is O(n + k), where n is the size of your array, and k is, basically, the amount of different possible elements.
The point is to calculate the number of same elements, and then insert them in the right order.
O(TotalNumberOfElements) complexity.