Data Structures & AlgorithmsVery hardProduct-company placement
Keys 85, 62, 86, 26, 40, 54, 92, 17, 18, 67 are inserted into an empty AVL tree (giving preorder 62, 40, 18, 17, 26, 54, 86, 85, 67, 92). Then 92 and 40 are deleted in that order (a two-child node takes its inorder successor) with AVL rebalancing. What is the final preorder?
- A. 62, 54, 18, 17, 26, 86, 85, 67
- B. 62, 26, 18, 17, 54, 86, 85, 67
- C. 62, 18, 17, 54, 26, 85, 67, 86
- D. 54, 18, 17, 26, 85, 62, 67, 86
Correct answer: C. 62, 18, 17, 54, 26, 85, 67, 86
After each deletion walk back up and rotate at any node whose balance becomes ±2 (LL at 86, LL at 54). Skipping the rotation, or rebuilding the AVL tree from the remaining keys, gives a different tree.
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 20, 24, 27, 35, 38 are searched with frequencies 4, 1, 3, 6, 11 respectively (only successful searches). The cost of a BST is Σ…
- DFS on the directed graph with adjacency lists A: CE; B: EFG; C: B; D: AG; E: C; F: G; G: – starts at A (scanning lists in the order…
- What is the minimum number of edges that must be deleted from the undirected graph with edges A–B, A–D, A–E, B–D, B–F, C–D, C–E, D–E, E–F…
- An undirected connected graph has edges A–C, B–D, B–F, B–H, C–D, C–F, D–G, D–I, E–H, F–G. How many articulation points (cut vertices) and…
- Coins of denominations 1, 9, 10, 11 are available in unlimited supply. What is the minimum number of coins needed to make 18, and how many…
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 46?