Data Structures & AlgorithmsModerateGATE CS

A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 131 nodes. How many leaves does it have, and how many nodes have exactly one child?

  1. A. 65 leaves, 0 with one child
  2. B. 4 leaves, 0 with one child
  3. C. 66 leaves, 1 with one child
  4. D. 66 leaves, 0 with one child

Correct answer: D. 66 leaves, 0 with one child

In array form (1-based), nodes 1..⌊n/2⌋ = 1..65 are internal, so leaves = 131 − 65 = 66; the last internal node has only a left child exactly when n is even. The 4 nodes on the last level are not all the leaves.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic