GATE DA 2024 | Question 28
Consider the following tree traversals on a full binary tree:
(i) Preorder
(ii) Inorder
(iii) Postorder
Which of the following traversal options is/are sufficient to uniquely reconstruct the full binary tree?
Explanation
Answer: (A), (B), (C)
Take the node labels to be distinct. In a full binary tree every node has 0 or 2 children.
- With inorder (A, B): the root is the first node in preorder or the last in postorder, and its position in inorder splits the other nodes into the left and right subtrees. Repeating this rebuilds any binary tree.
- Preorder and postorder (C): for general trees a lone child could be left or right, but here an internal node always has two children. The node after the root in preorder is the left child, and its place in postorder marks where the left subtree ends, so the split is again unique.
- Inorder only (D): the full trees with root 2 (children 1 and 4, where 4 has children 3 and 5) and root 4 (children 2 and 5, where 2 has children 1 and 3) both give 1 2 3 4 5.
Answer: A, B, C