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

A max-heap is built by inserting 87, 88, 19, 50, 39, 89 one by one (sift-up on each insert). After one extract-max (move the last element to the root, then sift down), what is the array?

  1. A. [88, 87, 19, 50, 39]
  2. B. [19, 87, 88, 50, 39]
  3. C. [87, 50, 88, 19, 39]
  4. D. [89, 87, 88, 50, 39, 19]

Correct answer: A. [88, 87, 19, 50, 39]

Heap after all inserts: [89, 87, 88, 50, 39, 19]. Remove the root (89), move the last element (19) to the root and sift it down to restore the max-heap property, giving [88, 87, 19, 50, 39].

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic