GATE Computer ScienceVery hardGATE CSE

A min-heap is built from the array [19, 4, 17, 8, 2, 15, 9, 1, 12, 6, 3, 18, 11, 7, 14] by Floyd's bottom-up method: for i = ⌊n/2⌋−1 down to 0, sift A[i] down, at each step exchanging with the smaller child while that child is smaller than it. How many exchanges (swaps) take place in total?

  1. A. 9
  2. B. 11
  3. C. 7
  4. D. 14

Correct answer: A. 9

Simulating sift-down from index 6 to index 0 and counting each exchange gives 9.

More Programming and Data Structures (GATE) questions

Exams that ask this topic