Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE
Keys 75, 97, 65, 30, 69, 78, 44, 25, 18 are inserted one by one into an empty binary search tree. What is the pre-order traversal?
- A. [18, 25, 44, 30, 69, 65, 78, 97, 75]
- B. [75, 65, 30, 25, 18, 44, 69, 97, 78]
- C. [75, 65, 97, 30, 69, 78, 25, 44, 18]
- D. [18, 25, 30, 44, 65, 69, 75, 78, 97]
Correct answer: B. [75, 65, 30, 25, 18, 44, 69, 97, 78]
Build the BST by inserting in order (root 75). pre-order gives [75, 65, 30, 25, 18, 44, 69, 97, 78]. The other traversals of the same tree are the distractors.
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
- Keys 56, 66, 31, 58, 79, 72, 35, 77 are inserted in this order into an empty BST. How many leaf nodes does the tree have?
- Keys 17, 90, 39, 58, 63, 18, 37, 95 are inserted one at a time into an initially empty max-heap (array representation, sift-up). What is…
- An undirected graph has edges (u–v: weight) A–B:10, A–C:12, A–D:4, D–E:29, D–F:26, D–B:13. What is the weight of its minimum spanning tree?
- In the undirected graph with edges A–B:8, B–C:6, A–D:3, D–E:1, C–F:2, E–F:1, F–A:4, what is the shortest-path distance from A to D?
- Keys 63, 44, 55, 66, 68, 84, 93, 50, 52, 76 are inserted in this order into an empty BST. What is the height of the tree (edges on the…
- An undirected graph has edges (u–v: weight) A–B:13, A–C:16, A–D:20, C–E:2, B–F:18, D–F:10, D–B:23. What is the weight of its minimum…