Data Structures & AlgorithmsHardGATE CS · Product-company placement
A binary search tree holds exactly the keys 27, 34, 63, 64, 72, 73, 95, 99. Which ONE of the following can be its POSTORDER traversal?
- A. 34, 27, 73, 95, 64, 99, 72, 63
- B. 34, 27, 73, 72, 64, 99, 95, 63
- C. 34, 27, 73, 72, 99, 64, 95, 63
- D. 34, 95, 73, 72, 64, 99, 27, 63
Correct answer: B. 34, 27, 73, 72, 64, 99, 95, 63
The last key is the root; the keys before it must split into a block of smaller keys followed by a block of larger keys, recursively. Only 34, 27, 73, 72, 64, 99, 95, 63 splits correctly at every level.
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
- Five matrices have dimensions 5×5 , 5×5 , 5×15 , 15×4 , 4×3. What is the minimum number of scalar multiplications needed to compute their…
- The directed graph A→B (4), A→C (5), A→E (3), B→D (6), B→E (-3), C→E (7), D→C (1), E→D (2) has one negative edge but no negative cycle…
- Dijkstra's algorithm runs from A on the directed graph A→C (15), A→D (3), B→E (4), B→F (12), C→B (12), C→E (1), D→B (2), D→C (9), E→A…
- Heap sort (ascending) is run on [44, 9, 47, 27, 1, 46, 30, 10]: build a max-heap bottom-up, then repeatedly swap the root with the last…
- A binary search tree holds exactly the keys 17, 22, 27, 39, 40, 92, 97, 98. Which ONE of the following can be its POSTORDER traversal?
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 58?