GATE Computer ScienceEasyGATE CS (PYQ pattern)

A complete binary tree stored in an array has 1000 nodes. What is its height (a single node has height 0) and how many nodes are at the last level?

  1. A. 10, 489
  2. B. 9, 489
  3. C. 9, 488
  4. D. 8, 511

Correct answer: B. 9, 489

Height = floor(log2 1000) = 9. Levels 0 to 8 hold 2^9 - 1 = 511 nodes, so the last level has 1000 - 511 = 489 nodes.

More Programming and Data Structures (GATE) questions

Exams that ask this topic