Data Structures & AlgorithmsHardProduct-company placement

Build a binary min-heap in place from the array [4, 37, 81, 88, 64, 1, 84, 86] using bottom-up heapify (sift-down from the last internal node to the root). What is the resulting array?

  1. A. 88, 86, 84, 37, 64, 1, 81, 4
  2. B. 86, 84, 1, 64, 88, 81, 37, 4
  3. C. 1, 4, 37, 64, 81, 84, 86, 88
  4. D. 1, 37, 4, 86, 64, 81, 84, 88

Correct answer: D. 1, 37, 4, 86, 64, 81, 84, 88

Bottom-up heapify sifts down every internal node starting from index ⌊n/2⌋ − 1 up to the root, swapping a node with its smaller child until the min-heap property holds; this gives [1, 37, 4, 86, 64, 81, 84, 88]. Simply sorting the array, [1, 4, 37, 64, 81, 84, 86, 88], is not what heapify produces — a heap is only partially ordered.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic