You are given an array of n real numbers and asked to sort t

You are given an array of n real numbers and asked to sort the numbers. The twist here is that many elements have duplicates and there are only k

Solution

Hash sort is best option...
It iterates array once using hash table and then counts number of occurences of each value element.
This takes O(n) running time. Then take all unique elements and again sort them. It takese O(k logk) time.
K is unique elements. Then again expand list back. It takes O(n) steps. So if k << n it saves time.

Remaining algorithms takes more running complexity time than using hashing sort.

 You are given an array of n real numbers and asked to sort the numbers. The twist here is that many elements have duplicates and there are only k SolutionHash

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site