MCQ Practice Single Best Answer Topic: Time Complexity

Q What is the time complexity of a delete operation in a binary heap in the worst case?

Question ID
#15265
Subchapter
Time Complexity
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A O(1)
  • B O(log n)
  • C O(n)
  • D O(n^2)
Correct 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).

Share This Question

Share this MCQ with your friends or study group.