GateAI
Binary Heaps

GATE CSE 2016 Set 1 · Q37

MCQ2 marksMedium

Time

An operator delete(i) for a binary heap data structure is to be designed to delete the item in the ii-th node. Assume that the heap is implemented in an array and ii refers to the ii-th index of the array. If the heap tree has depth dd (number of edges on the path from the root to the farthest leaf), then what is the time complexity to re-fix the heap efficiently after the removal of the element?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) O(d) but not O(1)

Binary Heaps

To delete an element at index ii in a binary heap of depth dd:

  1. Replace the element at index ii with the last element in the heap array (heap size decreases by 1).

  2. The replacement element may violate the heap property in one of two directions:

    • It may be greater than its parent (for a max-heap) or smaller than its parent (for a min-heap), requiring a heapify-up (shift-up) operation towards the root.

    • Or it may violate the property with respect to its children, requiring a heapify-down (shift-down) operation towards the leaves.

  3. The height/depth of the binary heap tree is dd.

  4. In the worst case, heapify-up travels at most dd levels up to the root, and heapify-down travels at most dd levels down to a leaf.

Thus, re-fixing the heap takes time proportional to the depth of the tree, which is O(d)O(d), but not O(1)O(1) in the worst case.

Hence, the correct option is (B).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Binary Heaps previous year question is Q37 of the GATE CSE 2016 Set 1 paper. Find more GATE CSE PYQs on Binary Heaps in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Binary Heaps PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Binary Heaps in GATE CSE

Binary Heaps has 15 GATE CSE PYQs across 13 papers from 2011 to 2026. 5 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2016 Set 1.

How GATE tests Binary Heaps

More from GATE CSE 2016 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2016 Set 1 · Q37 · MCQ

An operator delete(i) for a binary heap data structure is to be designed to delete the item in the i-th node. Assume that the heap is implemented in an array and i refers to the i-th index of the array. If the heap tree has depth d (number of edges on the path from the root to the farthest leaf), then what is the time complexity to re-fix the heap efficiently after the removal of the element?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.