ITPEC FE Morning April 2021 Question 8
ITPEC FE Morning April 2021 — Question 8 of 80
In-Order Traversal — visit nodes in Left → Root → Right order.
Given tree rooted at 1:
- •Left subtree of
1→ recurse into2 - •Left of
2→ recurse into4 - •Left of
4→7(leaf) → visit 7 - •Visit 4
- •Right of
4→8(leaf) → visit 8 - •Visit 2
- •Right of
2→5(leaf) → visit 5 - •Visit 1
- •Right subtree of
1→ recurse into3 - •Left of
3→ none - •Visit 3
- •Right of
3→ recurse into6 - •Left of
6→9(leaf) → visit 9 - •Visit 6
Result: 7, 4, 8, 2, 5, 1, 3, 9, 6
Why not others:
- (a) 1, 2, 4, 7, 8, 5, 3, 6, 9 — this is pre-order (Root → Left → Right)
- (b) 6, 9, 3, 1, 5, 2, 8, 4, 7 — this is reverse pre-order
- (d) 7, 8, 4, 5, 2, 9, 6, 3, 1 — this is post-order (Left → Right → Root)
Key rule: In-order on a BST yields sorted output; on a general binary tree, apply Left → Root → Right recursively.
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.