Data Structures & AlgorithmsHardProduct-company placement
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?
- A. 13, 40, 69, 85, 21, 64, 98, 92
- B. 85, 40, 21, 13, 69, 64, 98, 92
- C. 13, 40, 21, 85, 69, 64, 98, 92
- D. 13, 40, 21, 98, 69, 64, 85, 92
Correct answer: C. 13, 40, 21, 85, 69, 64, 98, 92
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 13, 40, 21, 85, 69, 64, 98, 92 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
- 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…
- Five matrices have dimensions 10×15 , 15×3 , 3×5 , 5×15 , 15×15. What is the minimum number of scalar multiplications needed to compute…
- What is the minimum number of edges that must be deleted from the undirected graph with edges A–B, A–D, A–E, B–E, B–F, C–D, C–F, D–E, E–F…
- A 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [51, 46, 36, 39, 2, 22, 35, 14, 13, 24]. After…