Data Structures & AlgorithmsHardGATE CS · ICPC regional
A binary tree with distinct letters has preorder ACDEBF and inorder DEBCAF. What is its postorder traversal (left, right, root), written as a string of letters?
- A. ACFDEB
- B. FACBED
- C. BEDCFA
- D. FBEDCA
Correct answer: C. BEDCFA
The root is the first preorder letter, and splitting the inorder sequence gives the subtrees; this yields postorder BEDCFA. 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 B, F, A, C, D (source B, target D) with edges: B→F (2); B→A (5); A→F (-4); F→D (1); A→D (3); B→D (12)…
- Distinct words ['cc', 'aab', 'a', 'cbc', 'bbb', 'bc'] are inserted into an empty trie (one node per character, shared prefixes share…
- Directed weighted graph on vertices F, E, D, B, C (source F, target C) with edges: F→E (5); F→D (8); D→E (-5); E→C (1); D→C (6); F→C (8)…
- A trie keeps a counter at each node, and every word of the list W = ['c', 'b', 'baba', 'a', 'b', 'cc', 'ccb', 'cb'] is inserted once per…
- Strings a = "accca" and b = "bcbb". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Directed graph on vertices A, B, C, D, E, F, G with edges D→A, A→E, E→F, B→F, B→A, F→G, C→D, D→G, E→B, A→F, A→B (no weights). What is the…