You have a list of n integers and you want the x smallest. For example,
x_smallest([1, 2, 5, 4, 3], 3) should return [1, 2, 3].
x_smallest([1, 2, 5, 4, 3], 3)
[1, 2, 3]
I\'ll v
Add all n numbers to a heap and delete x of them. Complexity is O((n + x) log n). Since x is obviously less than n, it's O(n log n).
O((n + x) log n)
O(n log n)