Data Structures & AlgorithmsModerateInfosys · Wipro pattern

The minimum is deleted from the min-heap [2, 5, 3, 9, 6, 4, 8] (0-indexed): the last element moves to the root and sifts down, swapping with its smaller child. What is the array afterwards?

  1. A. [3, 5, 8, 9, 6, 4]
  2. B. [5, 3, 4, 9, 6, 8]
  3. C. [3, 5, 4, 9, 6, 8]
  4. D. [3, 4, 5, 9, 6, 8]

Correct answer: C. [3, 5, 4, 9, 6, 8]

8 moves to the root: [8, 5, 3, 9, 6, 4]. Its smaller child is 3 → swap: [3, 5, 8, 9, 6, 4]. At index 2, 8's only child is 4 → swap: [3, 5, 4, 9, 6, 8]. Stopping after the first swap gives [3, 5, 8, 9, 6, 4]; swapping with the LARGER child would put 5 on top.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic