I am trying to find the most efficient way to sort the t smallest integers of an unsorted array of length n.
I'm trying to use O (n), but, keep getting stuck.
The best I can think of is simply to sort the entire array and take the first t. In all other cases, I leave the chance that the smallest will be left behind, and if I check them all, it has the same complexity in sorting everything array.
Can someone give me some ideas?
source
share