2021年3月2日星期二

Most efficient way to sort a unique, bounded array?

I assume this is a duplicate but I couldn't find one.

Let's say we have an array where we know every single value will be unique, and every value will be between a range. For example, let's say we know the array consists of unique values between 0 and 100. Example:

[ 5, 46, 15, 83, 55, 28 ]  

I would like to then sort this array into the following:

[ 5, 15, 28, 46, 55, 83 ]  

Obviously I could just use Quicksort or any other comparative sort, but that would be O(log n). Non-comparative sorts exist as well, such as Radix Sort, Bucket Sort, Counting Sort, etc. but none of those also maintain the constraint that values must be unique, as far as I know.

Generally it is the case that the more constraints you allow, the more efficient your algorithm can become. Are there any algorithms which are even more efficient for unique, bounded arrays? If not, which of the non-comparative sorting algorithms would be most efficient for this type of dataset?

https://stackoverflow.com/questions/66451071/most-efficient-way-to-sort-a-unique-bounded-array March 03, 2021 at 01:03PM

没有评论:

发表评论