Data Structures & AlgorithmsModerateGATE CS · Product-company placement
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 (left, root, right) is B F D A E C. What is its postorder traversal (left, right, root)?
- A. C E A D F B
- B. E B C F A D
- C. C D A F B E
- D. D A F B C E
Correct answer: D. D A F B C E
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
- 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…
- For the array [12, 2, 20, 18, 17, 2, 20, 6], consider all windows of exactly 3 consecutive elements. What is the sum of the maximum of…
- For the array [3, 5, 5, 7, 20, 12, 13, 11, 19], consider all windows of exactly 3 consecutive elements. What is the sum of the maximum of…
- For the array [19, 2, 19, 13, 13, 7, 16, 11, 5, 1], consider all windows of exactly 3 consecutive elements. What is the sum of the maximum…
- For the array [12, 17, 3, 10, 18, 3, 16, 6, 10], consider all windows of exactly 3 consecutive elements. What is the sum of the maximum of…