So, we have a list of N integers, from which we want to get K largest integers (unsorted). The problem is, this needs to be able to run in O(N + K). That's what stated in the assignment.
I've checked various algorithms and even made my own, but the best I can get is O((n-k)*k) which I don't think is close to O(N + K), unless I'm wrong.
Are there any algorithms out there that can do this in O(N + K) assuming the values in the list are pretty much random, and all positive? (We don't know the max value they can acheive)
Note that I need to find the K largest integers as in not the K-th largest but from N, K integers.
Example: N = 5, K = 2 Input: 5 6 8 9 3 Output: 9 8