Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 C
A binary tree has distinct node labels. Its inorder traversal (left subtree, root, right subtree) is 70 54 74 49 13 57 76 83 45 44 8, and its preorder traversal (root, left subtree, right subtree) is 70 44 74 54 57 13 49 45 76 83 8. Give its postorder traversal (left subtree, right subtree, root).
- A. 70 44 74 54 57 13 49 45 76 83 8
- B. 70 44 74 8 54 57 13 45 49 76 83
- C. 8 83 76 45 49 13 57 54 74 44 70
- D. 54 49 13 83 76 45 57 74 8 44 70
Correct answer: D. 54 49 13 83 76 45 57 74 8 44 70
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 rooted tree has these parent→child edges: 24→10, 89→82, 17→89, 17→93, 89→66, 82→24, 93→25. The root is at depth 0. How many nodes lie at…
- A rooted tree has these parent→child edges: 17→9, 19→88, 90→17, 19→40, 40→25, 19→90. The root is at depth 0. What is the height of the…
- A rooted tree has these parent→child edges: 46→68, 40→41, 76→83, 83→95, 83→49, 40→22, 95→46, 68→40. The root is at depth 0. How many nodes…
- A rooted tree has these parent→child edges: 49→3, 95→70, 70→63, 93→64, 49→81, 19→25, 49→95, 95→19, 49→93, 64→37. The root is at depth 0…
- A rooted tree has these parent→child edges: 63→96, 16→83, 53→7, 48→51, 26→53, 16→84, 96→48, 7→16, 51→98, 26→63. The root is at depth 0…
- A rooted tree has these parent→child edges: 24→82, 24→60, 22→26, 82→59, 65→24, 71→23, 26→71, 65→22, 26→47, 75→65. The root is at depth 0…