Skip to content
Mad4Study

Engineering & Science

GATE Computer Science

  • GATE CS
  • 2026–27 pattern practice
  • Data Structures
  • Heaps
  • Easy

What is the worst-case time to delete the maximum element from a binary max-heap of nn elements?

Trees

Pick an option to check your answer.

Delete-max swaps the root with the last element, shrinks the heap by one, and sifts the new root down. Each sift-down step moves one level, and a heap of nn elements has height ⌊log⁡2n⌋\lfloor \log_2 n \rfloor, so the work is O(log⁡n)O(\log n).

Why not the others

  • O(1)O(1) is only the time to read the maximum at the root; removing it also needs the heap to be repaired.
  • O(n)O(n) would be needed only if we searched the whole array, which a heap avoids.
  • O(nlog⁡n)O(n \log n) is the cost of heapsort on all nn elements, not of one deletion.

Report an error

GATE CS · Data Structures · Trees