Q. In a binary tree, what is the in-order traversal of the tree with nodes 1, 2, 3?
A.
[1, 2, 3]
B.
[2, 1, 3]
C.
[1, 3, 2]
D.
[3, 2, 1]
Solution
In-order traversal visits the left subtree, then the root, and then the right subtree. For a tree with nodes 1, 2, 3, the in-order traversal is [2, 1, 3].
Q. In a binary tree, what is the in-order traversal of the tree with nodes A, B, C?
A.
A, B, C
B.
B, A, C
C.
B, C, A
D.
C, B, A
Solution
In in-order traversal, the left subtree is visited first, then the root, and finally the right subtree. For a tree with nodes A (root), B (left), and C (right), the traversal is B, A, C.
Q. What is the post-order traversal of a binary tree with nodes A, B, C?
A.
A, B, C
B.
B, C, A
C.
C, B, A
D.
A, C, B
Solution
In post-order traversal, the left subtree is visited first, then the right subtree, and finally the root. For a tree with nodes A (root), B (left), and C (right), the traversal is B, C, A.