Skip to content
Official PYQ · 2014

GATE CS 2014 Set 3 Q12 — Trees

Explain with AI

Consider the following rooted tree with the vertex labeled PP as the root:

The order in which the nodes are visited during an in-order traversal of the tree is

Choose one option
View worked solution

Answer: A

An in-order traversal of a binary tree recursively visits the nodes in the following order:

  1. Traverse the left subtree.
  2. Visit the root node.
  3. Traverse the right subtree.

From the given tree structure, we can trace the traversal step-by-step:

  • Left subtree of PP (rooted at QQ):
    • Left child of QQ is SS, and right child is TT.
    • In-order(Q)=S→Q→T\text{In-order}(Q) = S \to Q \to T
  • Root node: PP
  • Right subtree of PP (rooted at RR):
    • RR has no left child, and its right child is UU.
    • UU has left child WW and right child VV.
    • In-order(U)=W→U→V\text{In-order}(U) = W \to U \to V
    • In-order(R)=R→In-order(U)=R→W→U→V\text{In-order}(R) = R \to \text{In-order}(U) = R \to W \to U \to V

Combining these parts, the complete in-order traversal sequence is:

S→Q→T→P→R→W→U→V\text{S} \to \text{Q} \to \text{T} \to \text{P} \to \text{R} \to \text{W} \to \text{U} \to \text{V}

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Trees questions