Consider the following rooted tree with the vertex labeled P as the root: The…

2014

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

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

Answer: A. SQPTRWUVKey insight: in-order traversal visits the left subtree, then the node itself, then the right subtree (apply recursively). Traverse the left subtree of P…

  1. A.

    SQPTRWUV

  2. B.

    SQPTUWRV

  3. C.

    SQPTWUVR

  4. D.

    SQPTRUWV

Attempted by 239 students.

Show answer & explanation

Correct answer: A

Key insight: in-order traversal visits the left subtree, then the node itself, then the right subtree (apply recursively).

  • Traverse the left subtree of P (rooted at Q):

    • Q's left subtree is S, so visit S first.

    • Then visit Q.

  • Visit the root P.

  • Traverse the right subtree of P (rooted at R):

    • Visit R's left subtree: T (visit T).

    • Visit R.

    • Traverse R's right subtree (rooted at U):

      • Visit U's left subtree: W (visit W).

      • Visit U.

      • Visit U's right subtree: V (visit V).

Combine the visited nodes in order to get: S Q P T R W U V, which corresponds to the sequence SQPTRWUV.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…