Q: What is the time complexity of a binary heap's worst-case insertion operation?
-
A
O(1)
-
B
O(log n)
-
C
O(n)
-
D
O(n log n)
B
Answer:
B
Explanation:
Binary heaps are a type of complete binary tree used to implement priority queues. In the worst case, when inserting an element into a binary heap, it needs to compare the element with the parent node and potentially swap them to maintain the heap property. As the height of a binary heap is logarithmic to the number of elements (n), the worst-case insertion operation has a time complexity of O(log n).
Related Topic:
Share Above MCQ