The GATE Grind

GATE 2014 CS (CS2) – Question 22

Programming and Data Structures · Binary Heaps · 1 mark · Multiple choice

A max-heap priority queue initially has level order 10,8,5,3,2. Insert 1 then 7. Find the resulting level order.

  1. 10,8,7,3,2,1,5
  2. 10,8,7,2,3,1,5
  3. 10,8,7,1,2,3,5
  4. 10,8,7,5,3,2,1

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (A) 10,8,7,3,2,1,5

Explanation

Append1 at index6; it stays under5. Append7 at index7; it exceeds parent5 and swaps, but remains below10. The level order becomes **10,8,7,3,2,1,5,A**. Heap insertion changes only the ancestor path of the new leaf.