GATE Computer ScienceVery hardGATE CSE

A max-heap is built from the array [3, 9, 2, 1, 4, 5, 8, 7, 6, 10] using the bottom-up procedure (sift-down from index ⌊n/2⌋−1 to 0, children of i at 2i+1 and 2i+2, 0-indexed). How many element swaps are performed in total?

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

Correct answer: B. 7

Sifting down from nodes 4,3,2,1,0 in turn; the resulting heap is [10, 9, 8, 7, 4, 5, 2, 1, 6, 3] after 7 swaps.

More Algorithms questions

Exams that ask this topic