What is the worst-case time complexity for search in a set backed by a max heap? If you look for the smallest item in the set, that could take order of O(n) time, right? Is there a faster way?
Asked
Active
Viewed 27 times
1 Answers
1
Finding the smallest item in a max-heap is an O(n) operation. You could implement a Min-max heap, which will give you O(1) access to the smallest and largest items, while keeping the O(log n) insertion and removal. Note, however, that overall a min-max heap will be a bit slower than a max-heap, due to constant factors.
You could replace the max-heap with a skip list, which would give you O(log n) access to the smallest item. But implementing a skip list is a bit more involved than implementing a binary heap, and likely will consume more memory.

Jim Mischel
- 131,090
- 20
- 188
- 351