Data Structures & AlgorithmsVery hardProduct-company placement

Build a binary min-heap in place from the array [73, 61, 88, 9, 29, 24, 58, 42] using bottom-up heapify (sift-down from the last internal node to the root). What is the resulting array?

  1. A. 88, 61, 73, 42, 29, 24, 58, 9
  2. B. 42, 58, 24, 29, 9, 88, 61, 73
  3. C. 9, 24, 29, 42, 58, 61, 73, 88
  4. D. 9, 29, 24, 42, 73, 88, 58, 61

Correct answer: D. 9, 29, 24, 42, 73, 88, 58, 61

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 [9, 29, 24, 42, 73, 88, 58, 61]. Simply sorting the array, [9, 24, 29, 42, 58, 61, 73, 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