I was asked in an interview:
What is the best time complexity in getting the min element(s) from a max-heap?
I replied as O(1) a
Best complexity is O(n). Sketch proof:
n/2 lowest-level nodes.Omega(n) examinations required.The bound is tight, since clearly we can do it in O(n) by ignoring the fact that our array happens to be a heap.
Moral: it's probably called a heap because (as with the heap of clothes on your bedroom floor) it's easy to get at the top and difficult to get at the rest.