Data Structures & AlgorithmsHardGATE CS · Product-company placement
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 (left, root, right) is G D E B C A F. What is its postorder traversal (left, right, root)?
- A. C A F G D E B
- B. B E F D A G C
- C. F A C B E D G
- D. G D E C A F B
Correct answer: D. G D E C A F 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 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…
- A binary tree has distinct letters as node labels. Its preorder traversal (root, left, right) is E B F A D C and its inorder traversal…
- For the array [14, 10, 15, 11, 15, 18, 12, 2, 5], consider all windows of exactly 5 consecutive elements. What is the sum of the maximum…
- For the array [19, 15, 11, 1, 9, 17, 11, 8, 9, 18], consider all windows of exactly 4 consecutive elements. What is the sum of the maximum…