| T | S |
|---|---|
| I: Inorder | L: left subtree, node, right subtree |
| II: Preorder | M: node, left subtree, right subtree |
| III: Postorder | N: left subtree, right subtree, node |
Which one of the following is the correct match from T to S ?
A
Step-by-Step Solution
Insight: The names of the traversals (pre, in, post) directly indicate the position of the current node relative to its subtrees.
Exam route: Preorder = Node first (pre). Inorder = Node in the middle (in). Postorder = Node last (post). Match these to the given descriptions: I (Inorder) is L (left, node, right). II (Preorder) is M (node, left, right). III (Postorder) is N (left, right, node). This matches option A.
Learning route:
- Depth-first traversals are defined by when the current node is processed relative to its left and right subtrees.
- Preorder: The prefix "pre" means the node is visited before its subtrees. Order: Node, Left, Right (M).
- Inorder: The prefix "in" means the node is visited in between its left and right subtrees. Order: Left, Node, Right (L).
- Postorder: The prefix "post" means the node is visited after both subtrees. Order: Left, Right, Node (N).
- Matching these definitions to the given set S yields I-L, II-M, III-N.
Verification: Consider a tree with root A, left B, right C. Preorder visits A, then B, then C (Node, Left, Right). Inorder visits B, then A, then C (Left, Node, Right). Postorder visits B, then C, then A (Left, Right, Node). This perfectly matches M, L, N respectively.