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

A max-heap is built by inserting 23, 96, 77, 61, 84, 26, 70, 72 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. [96, 84, 77, 72, 61, 26, 70, 23]
  2. B. [84, 72, 77, 23, 61, 26, 70]
  3. C. [84, 77, 72, 70, 61, 26, 23]
  4. D. [23, 84, 77, 72, 61, 26, 70]

Correct answer: B. [84, 72, 77, 23, 61, 26, 70]

Heap after all inserts: [96, 84, 77, 72, 61, 26, 70, 23]. Remove the root (96), move the last element (23) to the root and sift it down to restore the max-heap property, giving [84, 72, 77, 23, 61, 26, 70].

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic