Data Structures & AlgorithmsModerateProduct-company MCQ pattern
The preorder traversal of a BST is 8, 5, 1, 7, 10, 12. What is its postorder traversal?
- A. 1 7 5 10 12 8
- B. 12 10 7 1 5 8
- C. 1 5 7 8 10 12
- D. 1 7 5 12 10 8
Correct answer: D. 1 7 5 12 10 8
8 is the root; 5, 1, 7 (smaller) form the left subtree with root 5 and children 1, 7; 10, 12 form the right subtree with 12 as 10's right child. Postorder: 1 7 5, then 12 10, then 8. 1 7 5 10 12 8 puts 10 before its own child.
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
- A binary tree has inorder 4 8 2 5 1 6 3 7 and preorder 1 2 4 8 5 3 6 7. What is its postorder?
- 10, 4, 7, 1, 3 are inserted in that order into an empty binary min-heap (array form, sift-up after each insert). What is the array at the…
- The bottom-up build-heap procedure (sift down from the last internal node back to the root) turns [3, 1, 6, 5, 2, 4] into a max-heap. What…
- The maximum is deleted from the max-heap [50, 30, 40, 10, 20, 35]: the last element replaces the root and is sifted down. What is the heap…
- An undirected graph has edges A–B, A–C, B–D, C–D, C–E, D–F, E–F, and neighbours are always taken in alphabetical order. What is the DFS…
- An undirected graph has edges S–A, S–B, A–C, B–C, B–D, C–E, D–E, E–F. After BFS from S, which vertices are at level 2, and what is the…