Data Structures & AlgorithmsHardGATE CS · Advanced

Floyd's bottom-up build-heap (sift-down from the last internal node back to the root) is applied to the array [55, 25, 49, 27, 3, 17, 33, 32, 26] to make a min-heap (array indices start at 1). Which array results?

  1. A. [25, 3, 17, 26, 55, 49, 33, 32, 27]
  2. B. [25, 3, 49, 27, 55, 17, 33, 32, 26]
  3. C. [3, 25, 17, 26, 27, 49, 33, 55, 32]
  4. D. [3, 25, 17, 26, 55, 49, 33, 32, 27]

Correct answer: D. [3, 25, 17, 26, 55, 49, 33, 32, 27]

Run sift-down for the nodes at positions 4, 3, 2, 1 in that order. Repeated insertion gives a different heap, and sifting down the nodes top-down (1, 2, 3, 4) or only the root does not produce a heap.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic