Data Structures & AlgorithmsHardGATE CS · ICPC regional
A binary tree with distinct letters has preorder FECBDGA and inorder CDGBEAF. What is its postorder traversal (left, right, root), written as a string of letters?
- A. GDBCAEF
- B. AGDBCEF
- C. FAEBGDC
- D. FECABDG
Correct answer: A. GDBCAEF
The root is the first preorder letter, and splitting the inorder sequence gives the subtrees; this yields postorder GDBCAEF. 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 weighted graph on vertices A, B, C, D with edges D→C (-4); A→B (-1); D→B (6); C→B (2); A→D (-2); D→A (5); C→A (-2); B→A (6)…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–E (1), A–F (1), A–G (1), B–D (1), B–G (1), C–D (1), D–E (1), D–F…
- Directed acyclic graph on vertices A, B, C, D, E, F, G, H (edges go from earlier to later letters) with weights A→C (4), A→E (3), A→F (2)…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–G (1), B–F (1), B–G (1), C–E (1), C–F (1), C–G (1), D–E (1)…
- Directed weighted graph on vertices E, C, A, B, D (source E, target D) with edges: E→C (2); E→A (3); A→C (-3); C→D (3); A→D (3); E→D (18)…
- A trie keeps a counter at each node, and every word of the list W = ['acb', 'c', 'bcb', 'c', 'bc', 'a', 'aac'] is inserted once per…