Data Structures & AlgorithmsVery hardProduct-company placement
A binary tree with distinct labels has INORDER G D C I F A B H E and LEVEL-ORDER E A D H G I B C F. What is its postorder traversal?
- A. G C F I D B H A E
- B. E A D G I C F H B
- C. B H F C I G D A E
- D. F C B I G H D A E
Correct answer: A. G C F I D B H A E
The first level-order label E 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 G C F I D B H A E.
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
- An undirected graph has edges A–D, B–D, B–F, C–D, C–E, D–G, E–F, E–H, F–G, G–H. BFS starts at A and always scans neighbours in…
- An undirected graph has edges A–C, A–E, B–D, B–E, C–D, C–F, D–G, E–F, E–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…
- An undirected graph has edges A–B, A–E, A–F, B–D, B–E, B–F, C–D, C–G, E–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…
- 0/1 knapsack with capacity 16: items (weight, value) = (9, 40), (3, 34), (2, 19), (7, 38), (7, 32). What is the maximum total value?
- Using parts 1, 5, 6 (each any number of times), in how many ways can 9 be written as an ORDERED sum (so 1 + 2 and 2 + 1 count separately)?
- In the DAG with edges A→B, A→G, B→D, D→G, E→A, E→B, E→C, E→D, E→F, E→G, G→C, how many distinct directed paths are there from E to C, and…