So my friend and I do not see the eye in this matter. Does it specify the time complexity of searching for the 7th largest element in the max heap of n elements?
I believe that it should be O (n), and she believes that it should be O (1). My logic is that let n be 7, then the 7th largest element will be the last element in the heap, so if we look at the worst case, then it should be O (n). She, however, says that since this is the maximum heap, so finding the 7th largest element should take constant time. But using its logic, even the 50th largest element or 100th largest element can be found O (1) times. Also in the book in which we came across this issue, it says that the solution is O (logn).
Can someone tell me which solution is right?
source
share