Data Structures & AlgorithmsHardGATE CS

A binary min-heap is stored in a 0-indexed array [13, 33, 15, 35, 42, 23, 32]. Perform, in order: insert 6, delete-min, insert 60, delete-min. (Insert appends and sifts up; delete-min moves the last element to the root and sifts it down, swapping with the smaller child.) What is the final array?

  1. A. [15, 33, 23, 35, 42, 60, 32]
  2. B. [33, 35, 15, 60, 42, 23, 32]
  3. C. [15, 35, 60, 33, 42, 23, 32]
  4. D. [15, 23, 32, 35, 60, 33, 42]

Correct answer: A. [15, 33, 23, 35, 42, 60, 32]

Sift-down must compare BOTH children and keep going until the heap property holds; doing that at every step gives [15, 33, 23, 35, 42, 60, 32]. Swapping with the left child whenever it beats the parent, or stopping after one swap, leaves a different (often invalid) array.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic