Data Structures & AlgorithmsHardAmazon OA · Heaps

Keys 9, 4, 7, 1, 8, 2, 6 are inserted one at a time into an empty min-heap (array representation). Two delete-min operations are then done, each moving the last element to the root and sifting it down. What does the array hold afterwards?

  1. A. 4 7 6 9 8
  2. B. 4 6 7 8 9
  3. C. 4 7 6 8 9
  4. D. 4 8 6 9 7

Correct answer: A. 4 7 6 9 8

The heap after inserts is [1,4,2,9,8,7,6]. Deleting 1 gives [2,4,6,9,8,7]; deleting 2 moves 7 to the root and sifts it below 4, giving [4,7,6,9,8].

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic