Consider the traversal of a tree Preorder → ABCEIFJDGHKL Inorder →…

2022

Consider the traversal of a tree

Preorder → ABCEIFJDGHKL
Inorder → EICFJBGDKHLA

Which of the following is correct post order traversal ?

  1. A.

    EIFJCKGLHDBA

  2. B.

    FCGKLHDBUAE

  3. C.

    FCGKLHDBAEIJ

  4. D.

    IEJFCGKLHDBA

Attempted by 241 students.

Show answer & explanation

Correct answer: D

Postorder traversal: IEJFCGKLHDBA

  1. Start with preorder to get the root: preorder begins with A, so A is the root. In the inorder sequence, all nodes left of A form the left subtree.

  2. For the left subtree, the next preorder root is B. Inorder splits around B into left part (E I C F J) and right part (G D K H L).

  3. Build B's left subtree: root C with inorder left E I and right F J. E has a right child I, so its postorder is I E. F has a right child J, so its postorder is J F. Combining gives the C-subtree postorder: I E J F C.

  4. Build B's right subtree: root D with left G and right H (where H has left K and right L). The postorder of D-subtree is G K L H D.

  5. Combine for B: left-subtree postorder + right-subtree postorder + B = IEJFC + GKLHD + B = IEJFCGKLHDB. Finally append the root A to get the full postorder: IEJFCGKLHDBA.

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

Explore the full course: Coding For Placement