Let , and represent height, number of internal nodes, number of leaf nodes, and the total number of nodes respectively in a rooted binary tree.
Which of the following statements is/are always TRUE?
- (A)
- (B)
- (C)
- (D)
Let , and represent height, number of internal nodes, number of leaf nodes, and the total number of nodes respectively in a rooted binary tree.
Which of the following statements is/are always TRUE?
ANSWER
Options A, B and C are always true; D is not.
Official answer: A, B, CSource: Official answer key, GATE 2024 DA (IISc Bengaluru)
Take the height as the number of edges on the longest root-to-leaf path. This is the convention under which the key holds. A single node has . A binary tree means every node has at most 2 children. Let , , be the numbers of nodes with 0, 1 and 2 children. Then and .
Count the edges two ways. Every node except the root has exactly one parent edge, so there are edges. Each node with children contributes edges, so there are also edges. Hence . Substituting gives .
(A) because . Always true.
(B) The longest path alone contains nodes, so , with equality for a chain. Level holds at most nodes and levels run from to , so , with equality for a full tree. Always true.
(C) Every node on the longest path except its last node (a leaf) has a child, so it is internal. That gives internal nodes, so . Internal nodes cannot lie on level , because a node at level has no children. So they lie on levels to , and . Always true, including , where .
(D) Take a chain of height : it has , so fails. Also a full tree of height has , so fails too. Not always true.
So the statements that are always true are A, B and C.
KEY IDEA
In a binary tree, (leaves = degree-2 nodes + 1). Bound the node counts by the longest path, which gives the minimum, and by full levels, which gives the maximum.
WATCH OUT FOR
Counting height in nodes instead of edges, which breaks the lower bounds in B and C. Another slip is assuming a tree of height has at least leaves. A chain has only one leaf.
From the GATE 2024 DA paper. Every question of this paper · Download the full paper · All 26 Trees & heaps questions, with notes