The time could be reduced to linear time:
-
Use the selection algorithm, which effectively find the k-th element in a un-sorted array in linear time. You can either use a variant of quick sort or more robust algorithms.
-
Get the top k using the pivot got in step 1.