GATE Computer ScienceModerateGATE CSE

A binary heap stored in A[1..200] has the usual shape (complete binary tree, children of i at 2i and 2i+1). Taking the height of a leaf as 0, how many nodes have height exactly 2?

  1. A. 28
  2. B. 26
  3. C. 50
  4. D. 25

Correct answer: D. 25

Heights follow the leftmost path from each node; counting indices whose leftmost descendant chain has length 2 gives 25 (≈ n/2³ = 25).

More Programming and Data Structures (GATE) questions

Exams that ask this topic