Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE

A min-heap is built by inserting 69, 20, 19, 35, 32, 87, 52, 58 one by one (sift-up on each insert). After one extract-min (move the last element to the root, then sift down), what is the array?

  1. A. [19, 32, 20, 58, 35, 87, 52, 69]
  2. B. [20, 32, 52, 58, 35, 87, 69]
  3. C. [32, 58, 20, 69, 35, 87, 52]
  4. D. [69, 32, 20, 58, 35, 87, 52]

Correct answer: B. [20, 32, 52, 58, 35, 87, 69]

Heap after all inserts: [19, 32, 20, 58, 35, 87, 52, 69]. Remove the root (19), move the last element (69) to the root and sift it down to restore the min-heap property, giving [20, 32, 52, 58, 35, 87, 69].

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic