In a priority queue implemented with a binary heap, what is the time complexity for extracting the maximum element?
17 views
- O(1)
- O(log n) (Correct Answer)
- O(n)
- O(n log n)
Explanation
In a binary max-heap, the maximum element is at the root. Extracting it requires replacing it with the last element and performing heapify, which takes O(log n) time due to the height of the heap.