Data Structures & AlgorithmsHardGATE CS · ICPC regional
A binary tree with distinct letters has preorder FBGCHAED and inorder GHACBDEF. What is its postorder traversal (left, right, root), written as a string of letters?
- A. DEAHCGBF
- B. FEDBCAHG
- C. FBGECDHA
- D. AHCGDEBF
Correct answer: D. AHCGDEBF
The root is the first preorder letter, and splitting the inorder sequence gives the subtrees; this yields postorder AHCGDEBF. 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
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (15), A–C (13), A–D (20), B–D (20), B–E (17), C–D (4), C–E…
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): B→D (1); C→D (7); B→A (4); B→C (1); D→E (7); A→D (7); D→C (3). Let…
- Directed graph on vertices A, B, C, D, E, F with edges D→F, F→B, E→F, D→E, D→B, E→D. How many strongly connected components does it have?…
- Bipartite graph with left side {A, B, C, D}, right side {E, F, G, H} and edges A–E, A–F, A–H, B–G, C–F, C–H, D–E, D–H. What is the size of…
- Array A = [30, 14, 22, 26, 8, 7] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 6?
- Words ['abd', 'bd', 'dac', 'cac', 'dcb', 'dab', 'dcc'] (each may be used at most once). A chain is a sequence of these words in which the…