Reputation: 19
I need to find the ten minimum elements in an array which has 1000 unordered numbers. I firstly think like: sort it and select first ten element but my duty is doing the same thing without sorting. By the way I am using C programming. Can you help me?
Upvotes: 1
Views: 631
Reputation: 6788
Using a max heap of size 10 you can achieve this in O(n * log(10)) = O(n)
time complexity as follows:
hp
.Upvotes: 5