Data Structures & AlgorithmsModerateGATE CSE · Heaps

Keys 14, 8, 11, 5, 9, 3, 12 are inserted one at a time into an initially empty binary min-heap kept in an array. What does the array hold afterwards (index 0 first)?

  1. A. 3 5 11 8 9 14 12
  2. B. 3 5 8 9 11 12 14
  3. C. 3 8 5 14 9 11 12
  4. D. 3 8 5 9 14 11 12

Correct answer: C. 3 8 5 14 9 11 12

After 14, 8, 11 -> [8,14,11]; 5 climbs to the root -> [5,8,11,14]; 9 stays; 3 climbs two levels -> [3,8,5,14,9,11]; 12 stays.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic