Data Structures & AlgorithmsHardProduct-company placement
A binary search tree holds exactly the keys 20, 26, 28, 45, 49, 87, 91, 92. Which ONE of the following sequences can be its PREORDER traversal?
- A. 91, 26, 20, 49, 45, 28, 92, 87
- B. 91, 26, 20, 49, 45, 28, 87, 92
- C. 91, 26, 20, 45, 49, 28, 87, 92
- D. 91, 26, 92, 49, 45, 28, 87, 20
Correct answer: B. 91, 26, 20, 49, 45, 28, 87, 92
In a valid BST preorder, once a key larger than some node appears (we have moved into that node's right subtree), no later key may be smaller than that node. 91, 26, 20, 49, 45, 28, 87, 92 never breaks this; each other option does at some point.
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 tree on vertices 1–10 has edges 2–1, 3–1, 4–2, 5–2, 6–3, 7–5, 8–7, 9–8, 10–6. What is the size of a minimum DOMINATING set (every vertex…
- Keys 90, 39, 48, 71, 49, 22, 33, 44, 15 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- A binary search tree holds exactly the keys 13, 21, 40, 64, 69, 85, 92, 98. Which ONE of the following can be its POSTORDER traversal?
- The connected undirected graph with edges A–E, A–F, A–G, B–C, B–D, B–G, B–H, C–D, E–F, E–G, F–G, G–H must be walked so that every edge is…
- The connected undirected graph with edges A–B, A–E, A–G, B–C, B–E, C–D, C–F, D–E, D–G, E–F, F–G, F–H must be walked so that every edge is…
- In the DAG with edges A→C, A→F, A→G, B→A, B→C, B→G, E→C, E→D, F→E, F→G, G→D, how many distinct directed paths are there from B to D, and…