Skip to content
Official PYQ · 2009

GATE CS 2009 Q60 — Binary Heaps

Explain with AI

Consider a binary max-heap implemented using an array.
What is the content of the array after two delete operations on {25,14,16,13,10,8,12}\left\{25,14,16,13,10,8,12\right\}

Choose one option
View worked solution

Answer: D

A binary max-heap deletion is performed by replacing the root element with the last element of the heap, reducing the heap size by 1, and then performing a max-heapify operation from the root downwards.

Initial Max-Heap:
Array={25,14,16,13,10,8,12}\text{Array} = \{25, 14, 16, 13, 10, 8, 12\}

First Delete Operation:

  1. Remove the root element 2525 and replace it with the last element 1212.
    Array→{12,14,16,13,10,8}\text{Array} \rightarrow \{12, 14, 16, 13, 10, 8\}
  2. Heapify down from the root (1212):
    • Compare 1212 with its children 1414 and 1616. Since 1616 is the larger child, swap 1212 with 1616.
    • Array→{16,14,12,13,10,8}\text{Array} \rightarrow \{16, 14, 12, 13, 10, 8\}
    • Now, 1212 is at index 2. Its only child is 88. Since 12>812 > 8, the heap property holds.

Second Delete Operation:

  1. Remove the root element 1616 and replace it with the last element 88.
    Array→{8,14,12,13,10}\text{Array} \rightarrow \{8, 14, 12, 13, 10\}
  2. Heapify down from the root (88):
    • Compare 88 with its children 1414 and 1212. Since 1414 is the larger child, swap 88 with 1414.
    • Array→{14,8,12,13,10}\text{Array} \rightarrow \{14, 8, 12, 13, 10\}
    • Now, 88 is at index 1. Its children are 1313 and 1010. Since 1313 is the larger child, swap 88 with 1313.
    • Array→{14,13,12,8,10}\text{Array} \rightarrow \{14, 13, 12, 8, 10\}

Thus, the final content of the array is {14,13,12,8,10}\{14, 13, 12, 8, 10\}.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Binary Heaps questions