GATE Computer ScienceVery hardNIELIT Scientist B

The keys 5, 3, 8, 1, 9, 2, 7, 10, 6, 4 are inserted one at a time into an initially empty max-heap (array-based, sift-up after each insertion). How many element exchanges happen in total?

  1. A. 9
  2. B. 7
  3. C. 10
  4. D. 8

Correct answer: D. 8

Simulating each sift-up gives 8 exchanges; the final array is [10, 9, 7, 8, 4, 2, 5, 1, 6, 3].

More Algorithms questions

Exams that ask this topic