Inorder and postorder traversal of a binary tree are given. In : E, I, C, F,…

20212021

Inorder and postorder traversal of a binary tree are given. In : E, I, C, F, B, G, D, J, H, K Post : I, E, F, C, G, J, K, H, D, B

Find the preorder traversal of a binary tree?

  1. A.

    B, C, E, I, F, D, G, H, J, K

  2. B.

    B, F, I, E, C, D, G, H, J, K

  3. C.

    B, C, E, I, F, D, G, H, K, J

  4. D.

    B, C, E, F, G, H, K, D, J, I

Attempted by 204 students.

Show answer & explanation

Correct answer: A

To find the preorder traversal of a binary tree given its inorder and postorder traversals, follow these steps:

1. The last element in the postorder traversal is the root of the tree. Here, the postorder is I, E, F, C, G, J, K, H, D, B, so the root is B.

2. Locate the root (B) in the inorder traversal. The inorder is E, I, C, F, B, G, D, J, H, K. Elements to the left of B are in the left subtree: E, I, C, F. Elements to the right are in the right subtree: G, D, J, H, K.

3. Recursively apply the same logic to the left and right subtrees.

Left subtree (inorder: E, I, C, F; postorder: I, E, F, C):

- Last element in postorder is C, so C is the root of the left subtree.

- In inorder, E, I are to the left of C, and F is to the right.

- Left subtree of C: E, I (inorder), I, E (postorder) → root is E, with I as right child.

- Right subtree of C: F (inorder), F (postorder) → single node.

- Preorder of left subtree: C, E, I, F.

Right subtree (inorder: G, D, J, H, K; postorder: G, J, K, H, D):

- Last element in postorder is D, so D is the root of the right subtree.

- In inorder, G, J, H, K are to the right of D.

- Postorder: G, J, K, H, D → right subtree of D: H, with left child J, right child K, and G as left child of J.

- Preorder of right subtree: D, G, H, J, K.

4. Combine the preorder traversal: root (B), then left subtree preorder (C, E, I, F), then right subtree preorder (D, G, H, J, K).

Final preorder traversal: B, C, E, I, F, D, G, H, J, K.

Explore the full course: Up Lt Grade Assistant Teacher 2025