Q: What is the time complexity of a delete operation in a binary heap in the worst case?
-
A
O(1)
-
B
O(log n)
-
C
O(n)
-
D
O(n^2)
B
Answer:
B
Explanation:
In a binary heap, the delete operation removes the root element, which is typically the minimum or maximum element depending on the heap's type. After removing the root, the heap needs to restore the heap property by percolating down or up, which involves swapping elements and comparing them with their children or parent. As the height of a binary heap is logarithmic to the number of elements (n), the worst-case time complexity of a delete operation is O(log n).
Related Topic:
Share Above MCQ