Data Structures & AlgorithmsHardGATE CS · Product-company placement
A binary tree has distinct letters as node labels. Its preorder traversal (root, left, right) is B A F E C D and its inorder traversal (left, root, right) is B F E C A D. What is its postorder traversal (left, right, root)?
- A. C E F D A B
- B. D C E F A B
- C. D A C E F B
- D. B A F D E C
Correct answer: A. C E F D A B
The root is the first preorder letter; the inorder list splits the rest into left and right subtrees, and the same splitting applied recursively gives the postorder. Reversing one of the traversals is a common wrong guess.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A binary tree has distinct letters as node labels. Its preorder traversal (root, left, right) is G C A H F D B E and its inorder traversal…
- A binary tree has distinct letters as node labels. Its preorder traversal (root, left, right) is D E F B C A and its inorder traversal…
- A binary tree has distinct letters as node labels. Its preorder traversal (root, left, right) is B E D G F A C and its inorder traversal…
- A binary tree has distinct letters as node labels. Its preorder traversal (root, left, right) is F G C E A D B and its inorder traversal…
- A binary tree has distinct letters as node labels. Its preorder traversal (root, left, right) is A F E C G D B and its inorder traversal…
- A binary tree has distinct letters as node labels. Its preorder traversal (root, left, right) is C A B F G E D and its inorder traversal…