GATE / CS ARCHIVE

GATE CSE 1991 / QUESTION 1(ix)

Inorder traversal of the displayed tree

Data Structures · Tree Properties & Traversals · Full GATE CSE 1991 paper

GATE 1991, Q1(ix) 2 marks · Other
Report issue

Tree Properties & Traversals

Question 1(ix), GATE 1991: Root 7 has left child 1 with children 4, 6 and right child 3 with right child 5; node 5 has children 2, 8. Give inorder traversal.
Question 1(ix), GATE 1991: Root 7 has left child 1 with children 4, 6 and right child 3 with right child 5; node 5 has children 2, 8. Give inorder traversal.
Tap to enlarge
Answer & solution

Answer: 4, 1, 6, 7, 3, 2, 5, 8 (no official key was published)

Inorder recursively visits left subtree, node, then right subtree. The subtree rooted at 1 therefore gives 4, 1, 6. Next visit root 7. Node 3 has no left child, so visit 3 immediately, then traverse its right child 5 as 2, 5, 8. Concatenating gives 4, 1, 6, 7, 3, 2, 5, 8. The numeric labels are merely node names; this is not a binary search tree, and sorting the labels would not be a traversal. Every node appears exactly once.

Original paper, page 1