Given an array A, the task is to find the largest, 2nd largest, 4th largest, 8th largest, 16th largest, ... and so on up to
2^logn
largest element. Give anO(n)
algorithm to do this.
I do understand that elements need not to be sorted between the selected largest elements (for example between 4th and 8th largest). I also thought about using the kth largest
elements algorithm but that would only save me sorting a small (largest) fraction of the array that is between 2^logn
and max(n)
and it's not even O(n)
.
I also thought about bucket sorting by splinting exponentially (instead of evenly) but this would still not provide me with the complexity guarantees that are required.