GATE Computer ScienceVery hardGATE CSE

A binary max-heap is built from 15 elements by Floyd's bottom-up method (sift-down from the last internal node to the root). Each level of a sift-down costs 2 key comparisons (child vs child, then larger child vs parent). What is the maximum total number of comparisons?

  1. A. 20
  2. B. 22
  3. C. 24
  4. D. 26

Correct answer: B. 22

Sum of node heights = 3 + 2·2 + 4·1 = 11, and at 2 comparisons per level the worst case is 22.

More Programming and Data Structures (GATE) questions

Exams that ask this topic