GATE CS 2023 | Question 46

Programming & Data Structures › Heaps · MCQ · 2 marks · Answer: B

  1. Question 46Programming & Data Structuresmcq2 marks
    A priority queue is a max-heap. Extract-Max deletes the max; Insert adds a key; both preserve the heap. With elements, the worst-case running times are
    • A.
      Both O(1).
    • B.
      Both O(log n).
      ✓
    • C.
      Extract-Max O(1), Insert O(n).
    • D.
      Extract-Max O(1), Insert O(log n).

    Answer: B

    Solution

    Answer: (B) Both O(log n) Insert appends at the end and sifts up — . Extract-Max removes the root, moves the last element to the root, and sifts down — . Both are in the worst case.

More GATE PYQ on Heaps

All GATE CS Programming & Data Structures PYQ →

Attempt GATE CS 2023 in real GATE exam mode

Full paper with a timer, the GATE interface and a topic-wise analysis — free.

Create free account →