2000Questions per year2026
Questions 1–4 of 4
Consider the following rooted tree with the vertex labelled P as the root
The order in which the nodes are visited during an in-order traversal of the tree is
The order in which the nodes are visited during an in-order traversal of the tree is
Answer: (A)
For a general tree, the in-order rule is: visit the first child's subtree, then the node, then the remaining children's subtrees.
- P: (Q-subtree) P (R-subtree)
- Q-subtree: S Q
- R-subtree: T R (U-subtree) V, where the U-subtree is W U
Putting these together, the order is: S Q P T R W U V
Answer: SQPTRWUV
- P: (Q-subtree) P (R-subtree)
- Q-subtree: S Q
- R-subtree: T R (U-subtree) V, where the U-subtree is W U
Putting these together, the order is: S Q P T R W U V
Answer: SQPTRWUV
A complete n-ary tree is a tree in which each node has n children or no children. Let I be the number of internal nodes and L be the number of leaves in a complete n-ary tree. If L = 41, and I = 10, what is the value of n?
Answer: (C)
Every node except the root is a child of exactly one internal node, and each internal node has children. So the total number of nodes is .
The total is also . So , which gives .
Put in and :
Answer: (C)
The total is also . So , which gives .
Put in and :
Answer: (C)
In a complete k-ary tree, every internal node has exactly k children. The number of leaves in such a tree with n internal nodes is:
Answer: (C)
Start with only the root: internal nodes and leaf (the root itself).
Make one leaf an internal node by giving it children. That leaf is lost and new leaves appear, so the number of leaves goes up by . The number of internal nodes goes up by .
Every complete -ary tree with internal nodes is built by such steps, so
leaves .
Check with : one root with children has leaves, and the formula gives . Option (B) gives here and option (D) gives , so both are wrong.
Answer: (C)
Make one leaf an internal node by giving it children. That leaf is lost and new leaves appear, so the number of leaves goes up by . The number of internal nodes goes up by .
Every complete -ary tree with internal nodes is built by such steps, so
leaves .
Check with : one root with children has leaves, and the formula gives . Option (B) gives here and option (D) gives , so both are wrong.
Answer: (C)
The number of leaf nodes in a rooted tree of n nodes, with each node having 0 or 3 children is
Answer: (D)
Let be the number of leaves and the number of internal nodes. Each internal node has children, and each leaf has none.
Total nodes:
A tree with nodes has edges. Only internal nodes produce edges, each, so
From (2), . Put this in (1):
Answer: (D)
Total nodes:
A tree with nodes has edges. Only internal nodes produce edges, each, so
From (2), . Put this in (1):
Answer: (D)
Keep practising