Data Structures & AlgorithmsVery hardProduct-company placement
A binary tree with distinct labels has INORDER G H B F C E A D I and LEVEL-ORDER I E G D F A H C B. What is its postorder traversal?
- A. I E G F H B C D A
- B. B H C F G A D E I
- C. A D C B H F G E I
- D. B C H A F D G E I
Correct answer: B. B H C F G A D E I
The first level-order label I is the root; its position in the inorder splits the left and right subtrees, and the earliest level-order label inside each part is that part's root. Rebuilding gives postorder B H C F G A D E I.
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
- Floyd–Warshall runs on vertices 1–4 with directed edges 1→2 (10), 1→4 (1), 2→1 (12), 2→3 (10), 3→1 (12), 4→1 (1), 4→3 (4). After the…
- A binary max-heap is stored in a 0-indexed array [57, 27, 49, 9, 19, 17, 40]. Perform, in order: insert 7, delete-max, insert 13, insert…
- Floyd–Warshall runs on vertices 1–4 with directed edges 1→3 (2), 2→1 (7), 2→3 (4), 3→1 (3), 3→4 (8), 4→1 (7), 4→2 (1). After the…
- A tree on vertices 1–8 has edges 2–1, 3–1, 4–2, 5–2, 6–4, 7–5, 8–3. What is the sum of the distances (in edges) over all unordered pairs…
- Keys 64, 95, 22, 60, 55, 18, 69, 31, 78, 65, 26 are inserted in that order into an empty BST. Then 64 is deleted and after that 22 is…
- A 4 × 4 grid has rows 1 5 2 1 / 1 1 5 4 / 7 4 6 2 / 1 6 3 8. Moving only right or down from the top-left to the bottom-right cell, what is…