GATE / CS ARCHIVE

GATE CSE 2009 / QUESTION 60

Two delete-max operations

Data Structures · Heaps & Priority Queues · Full GATE CSE 2009 paper

GATE 2009, Q60 2 marks · MCQ
Report issue

Heaps & Priority Queues

Question 60, GATE 2009: Perform two delete-max operations on the valid heap from Q59. Result? A[14, 13, 12, 10, 8]; B[14, 12, 13, 8, 10]; C[14, 13, 8, 12, 10]; D[14, 13, 12, 8, 10].
Question 60, GATE 2009: Perform two delete-max operations on the valid heap from Q59. Result? A[14, 13, 12, 10, 8]; B[14, 12, 13, 8, 10]; C[14, 13, 8, 12, 10]; D[14, 13, 12, 8, 10].
Question 60, GATE 2009: Perform two delete-max operations on the valid heap from Q59. Result? A[14, 13, 12, 10, 8]; B[14, 12, 13, 8, 10]; C[14, 13, 8, 12, 10]; D[14, 13, 12, 8, 10].
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step through it (9 steps)

Start from Q59’s heap [25, 14, 16, 13, 10, 8, 12]. Delete 25, move final element 12 to the root, and sift down by swapping with the larger child 16. The six-element heap is [16, 14, 12, 13, 10, 8]. Delete 16 and move final element 8 to the root: [8, 14, 12, 13, 10]. Swap 8 with larger child 14, then with larger child 13, giving [14, 13, 12, 8, 10]. This is option D. Each deletion removes the maximum and reduces the active heap length by one.

Delete-max replaces the root by the last active element, shrinks the heap and repeatedly swaps downward with the larger child. First deletion moves 12 to the root and swaps it with 16, yielding[16, 14, 12, 13, 10, 8]. Second deletion moves 8 to the root, then swaps with 14 and 13, yielding[14, 13, 12, 8, 10]. Choosing the smaller child would not restore heap order, which explains several plausible-looking alternatives.

Original paper, page 14