Data Structures & AlgorithmsModerateWipro · Accenture pattern

The bottom-up build-heap procedure (sift down from the last internal node back to the root) turns [3, 1, 6, 5, 2, 4] into a max-heap. What is the result?

  1. A. 6 5 4 3 2 1
  2. B. 6 3 5 1 2 4
  3. C. 6 5 4 1 2 3
  4. D. 6 5 3 1 2 4

Correct answer: C. 6 5 4 1 2 3

Index 2 (6) already beats its child 4; index 1 (1) swaps with 5 → 3 5 6 1 2 4; the root 3 swaps with 6 and then with 4 → 6 5 4 1 2 3. Inserting one by one would give a different heap, and 6 5 4 3 2 1 is just sorted order.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic