Data Structures & AlgorithmsHardGATE CS · ICPC regional
A binary tree with distinct letters has preorder CHEGDBFA and inorder HECFBADG. What is its postorder traversal (left, right, root), written as a string of letters?
- A. EHFABDGC
- B. AFBDGEHC
- C. CHGEDBFA
- D. GDABFCEH
Correct answer: A. EHFABDGC
The root is the first preorder letter, and splitting the inorder sequence gives the subtrees; this yields postorder EHFABDGC. Reversing the preorder or taking a level-order walk gives a different string.
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
- Directed graph on vertices A, B, C, D, E, F, G with edges G→E, A→D, F→A, G→F, C→E, B→E, A→B, B→G, E→G, A→C (no weights). What is the…
- Coins of denominations [12, 11, 5, 3] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 34?…
- Array A = [7, 13, 13, 9, 9, 3, 1, 11]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in…
- Array A = [17, 22, 23, 7, 20, 4] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 6?
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–E, A–G, A–H, B–E, B–H, C–E, D–E, D–F, D–G. What is the…
- Strings a = "abbacc" and b = "caaca". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…