Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C
A binary tree has distinct node labels. Its inorder traversal (left subtree, root, right subtree) is 23 12 58 38 83 34 24, and its preorder traversal (root, left subtree, right subtree) is 83 23 38 58 12 24 34. Give its postorder traversal (left subtree, right subtree, root).
- A. 12 58 38 23 34 24 83
- B. 83 23 38 58 12 24 34
- C. 83 23 24 38 34 58 12
- D. 34 24 12 58 38 23 83
Correct answer: A. 12 58 38 23 34 24 83
The first preorder label is the root, and its position in the inorder sequence splits the left and right subtrees, which are then solved the same way. Postorder then lists left, right, root.
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 node labels. Its inorder traversal (left subtree, root, right subtree) is 85 99 66 94 92 37 80 33 34 69, and…
- A binary tree has distinct node labels. Its inorder traversal (left subtree, root, right subtree) is 36 16 34 61 27 77 3 90, and its…
- A binary tree has distinct node labels. Its inorder traversal (left subtree, root, right subtree) is 66 2 78 41 99 39 36 50, and its…
- A binary tree has distinct node labels. Its inorder traversal (left subtree, root, right subtree) is 26 67 5 63 45 86 28 52, and its…
- A binary tree has distinct node labels. Its inorder traversal (left subtree, root, right subtree) is 31 84 42 80 17 13 85 10, and its…
- A binary tree has distinct node labels. Its inorder traversal (left subtree, root, right subtree) is 35 26 31 41 56 27 53 4, and its…