The inorder and preorder Traversal of binary Tree are dbeafcg and abdecfg…
2015
The inorder and preorder Traversal of binary Tree are dbeafcg and abdecfg respectively. The post-order Traversal is ___________ .
- A.
dbefacg
- B.
debfagc
- C.
dbefcga
- D.
debfgca
Attempted by 422 students.
Show answer & explanation
Correct answer: D
Given traversals:
Preorder: abdecfg
Inorder: dbeafcg
Step 1: Identify the root from preorder. The first preorder element is 'a', so 'a' is the root.
Step 2: Split the inorder sequence around the root 'a' to find left and right subtrees.
Left inorder (nodes left of 'a'): d b e
Right inorder (nodes right of 'a'): f c g
Step 3: Use preorder to get subtree roots and orders.
After removing root 'a' from preorder, the next elements for the left subtree are 'b d e'. So left subtree root is 'b', with left child 'd' and right child 'e'. Postorder of left subtree is 'd e b'.
The remaining preorder elements 'c f g' correspond to the right subtree with root 'c', left child 'f' and right child 'g'. Postorder of right subtree is 'f g c'.
Step 4: Combine left subtree postorder, right subtree postorder, and then the root to get the full postorder.
Left subtree postorder: deb
Right subtree postorder: fgc
Full postorder: debfgca