Question 137Asked in DSSSB PGT Computer Science (Technical), 11 Jul 2021

Consider a max heap, represented by the array: 23, 17, 14, 6, 13, 10, 1, 5

Consider a max heap, represented by the array: 23, 17, 14, 6, 13, 10, 1, 5 If a value 20 is inserted into this heap, then what will be the new max heap
  1. A23, 17, 4, 6, 13, 10, 1, 5, 20
  2. B23, 20, 14, 17, 13, 10, 1, 5, 6
  3. C23, 20, 17, 14, 13, 10, 6, 5, 1
  4. D23, 17, 20, 14, 13, 10, 6, 51
Show answerHide answer

Correct answer: (B) 23, 20, 14, 17, 13, 10, 1, 5, 6

Explanation

Add 20 at position 9 as the child of 6, then swap it with 6. Its parent is now 17, so swap again. The parent 23 is larger, so it stops: 23, 20, 14, 17, 13, 10, 1, 5, 6.

From DSSSB PGT Computer Science PYQ (Technical), 11 Jul 2021

This is question 137 of DSSSB PGT Computer Science PYQ (Technical), 11 Jul 2021. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.