Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

A max-heap is built by inserting 55, 85, 57, 63, 32, 19, 91, 12 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. [63, 55, 85, 12, 32, 19, 57]
  2. B. [85, 63, 57, 55, 32, 19, 12]
  3. C. [91, 63, 85, 55, 32, 19, 57, 12]
  4. D. [12, 63, 85, 55, 32, 19, 57]

Correct answer: B. [85, 63, 57, 55, 32, 19, 12]

Heap after all inserts: [91, 63, 85, 55, 32, 19, 57, 12]. Remove the root (91), move the last element (12) to the root and sift it down to restore the max-heap property, giving [85, 63, 57, 55, 32, 19, 12].

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic