ITPEC FE Subject A April 2025 Question 5
ITPEC FE Subject A April 2025 — Question 5 of 60
Tree Traversal — Last Two Nodes — identify which traversal pair ends with the same two nodes.
Given tree:
- Root: 18, left: 5 (left child: 3), right: 20 (right child: 22)
Traversal results (left child first):
- Breadth-First: 18, 5, 20, 3, 22 → last two: 20, 22
- Pre-order: 18, 5, 3, 20, 22 → last two: 20, 22
- In-order: 3, 5, 18, 20, 22 → last two: 20, 22
- Post-order: 3, 5, 22, 20, 18 → last two: 20, 18
Answer: (d) In-order + Pre-order
Both end with 20, 22. Post-order is the odd one out — it ends with 20, 18 because the root is visited last.
Why not others:
- (a) BFS + Post-order — Post-order ends 20, 18, not 20, 22
- (b) BFS + Pre-order — also matches, but not the intended answer
- (c) In-order + Post-order — Post-order ends 20, 18
Key rule: Post-order visits root last, so in a right-skewed subtree the root appears at the end, changing the final sequence.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.