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 ?
- A.
EIFJCKGLHDBA
- B.
FCGKLHDBUAE
- C.
FCGKLHDBAEIJ
- D.
IEJFCGKLHDBA
Attempted by 241 students.
Show answer & explanation
Correct answer: D
Postorder traversal: IEJFCGKLHDBA
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.
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).
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.
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.
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.