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

A max-heap is built by inserting 73, 97, 96, 27, 78, 89, 18 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. [78, 27, 96, 18, 73, 89]
  2. B. [96, 78, 89, 27, 73, 18]
  3. C. [97, 78, 96, 27, 73, 89, 18]
  4. D. [18, 78, 96, 27, 73, 89]

Correct answer: B. [96, 78, 89, 27, 73, 18]

Heap after all inserts: [97, 78, 96, 27, 73, 89, 18]. Remove the root (97), move the last element (18) to the root and sift it down to restore the max-heap property, giving [96, 78, 89, 27, 73, 18].

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic