Data Structures & AlgorithmsHardGATE CS

A binary min-heap is stored in a 0-indexed array [4, 15, 11, 32, 56, 47, 48]. Perform, in order: insert 28, insert 38, insert 19, 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. [11, 15, 47, 28, 19, 56, 48, 32, 38]
  2. B. [15, 28, 11, 32, 19, 47, 48, 56, 38]
  3. C. [11, 15, 56, 28, 19, 47, 48, 32, 38]
  4. D. [11, 15, 28, 32, 19, 48, 47, 38, 56]

Correct answer: A. [11, 15, 47, 28, 19, 56, 48, 32, 38]

Sift-down must compare BOTH children and keep going until the heap property holds; doing that at every step gives [11, 15, 47, 28, 19, 56, 48, 32, 38]. 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