If an array contains duplicated elements, what data structure is better for sorting?
Could B tree work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For a fixed and small range of element values you can use counting sort algorithm, as described here. Its complexity is
O(n + k), wherenis the size of your array, andkis, 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.