GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Floyd's Build-Heap performs at most height(v) exchanges while sifting down node v, so its exchanges are bounded by H = Σ height(v) over all nodes (height of a leaf = 0). For a heap of 1000 nodes stored in an array, what is H?

  1. A. 990
  2. B. 1013
  3. C. 994
  4. D. 992

Correct answer: C. 994

For a heap of n nodes, Σ height(v) = n − (number of 1 bits in n). 1000 = 1111101000₂ has six 1 bits, so H = 994 (confirmed by summing heights directly). 1013 is the value for n = 1023 (n − log₂(n+1)); 990 applies n − ⌈log₂ n⌉.

More Algorithms questions

Exams that ask this topic