Sort t smallest integers of an unsorted array of length n

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?

0
source share
2 answers

- quickselect, t- , , t . O (n) ( ).

Quickselect:

, quicksort, "" ( , ). , ( , ).

t, , , quicksort mergesort, O (t log t).

O (n + t log t) - , , .

+3

t n, t , t - , , BST.

min(O(n), O(t log(t)))

0

All Articles