AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Mediumtreecounting

~75s

Leaves of a full binary tree

In a binary tree every node has either 0 or 2 children. If the tree contains 10 internal nodes, how many leaves does it have?

Show the answer and the worked solution

Correct answer: C.

11

Worked solution

  1. Begin with a single node: 0 internal nodes and 1 leaf.
  2. Giving a leaf two children turns it into an internal node and adds two leaves, so each step adds 1 internal node and a net 1 leaf.
  3. After 10 such steps the tree has 10 internal nodes and 1 + 10 = 11 leaves, matching the rule that leaves exceed internal nodes by exactly one.

Answer: 11.

The idea

In a tree where every node has 0 or 2 children, L = I + 1 always holds, and the total node count 2I + 1 is therefore always odd. Both facts are worth carrying into the exam hall.

Shortcut. Count edges: 10 internal nodes with 2 children each give 20 edges, so 21 nodes in all, and 21 − 10 = 11 are leaves.

Common trap. 20 counts two leaves per internal node, forgetting that most of those children are themselves internal nodes.

Leaves of a full binary tree — Aptitude Question

Leaves of a full binary tree: In a binary tree every node has either 0 or 2 children. If the tree contains 10… Answer and worked solution on CodeKairo.

Question

In a binary tree every node has either 0 or 2 children. If the tree contains 10 internal nodes, how many leaves does it have?

Options

  1. 9
  2. 10
  3. 11
  4. 20
Show the answer and the worked solution

Correct answer: C. 11

Worked solution

  1. Begin with a single node: 0 internal nodes and 1 leaf.
  2. Giving a leaf two children turns it into an internal node and adds two leaves, so each step adds 1 internal node and a net 1 leaf.
  3. After 10 such steps the tree has 10 internal nodes and 1 + 10 = 11 leaves, matching the rule that leaves exceed internal nodes by exactly one.

Answer: 11.

The idea

In a tree where every node has 0 or 2 children, L = I + 1 always holds, and the total node count 2I + 1 is therefore always odd. Both facts are worth carrying into the exam hall.

Shortcut. Count edges: 10 internal nodes with 2 children each give 20 edges, so 21 nodes in all, and 21 − 10 = 11 are leaves.

Common trap. 20 counts two leaves per internal node, forgetting that most of those children are themselves internal nodes.

All Data Structures & Algorithms questions · placement mock tests