GATE Computer ScienceModerateGATE CSE · UGC NET

A max-heap is built from [3, 9, 2, 1, 4, 5, 8, 7] by the bottom-up method (Max-Heapify from the last internal node down to the root, 0-based positions). How many element exchanges occur in total?

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

Correct answer: B. 4

Sifting down positions 3, 2, 1, 0 in turn performs 4 exchanges; the final array is [9, 7, 8, 3, 4, 5, 2, 1].

More Algorithms questions

Exams that ask this topic