Data Structures & AlgorithmsHardProduct-company placement
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. 48, 39, 22, 15, 33, 44, 71, 49, 90
- B. 90, 39, 22, 15, 33, 48, 44, 71, 49
- C. 48, 33, 22, 15, 39, 44, 71, 49, 90
- D. 15, 22, 44, 39, 33, 49, 90, 71, 48
Correct answer: C. 48, 33, 22, 15, 39, 44, 71, 49, 90
Rebalance at the lowest unbalanced ancestor after each insert; the rotations performed are LR at 90, LL at 90, LR at 39. Treating an LR/RL case as a single rotation leaves a wrong (still unbalanced) shape.
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 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…
- 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…