Data Structures & AlgorithmsVery hardGATE CS
Keys 20, 94, 97, 28, 21, 78, 37, 93, 79, 36 are inserted into an empty AVL tree (giving preorder 78, 28, 21, 20, 37, 36, 93, 79, 94, 97). Then 78 and 21 are deleted in that order (a two-child node takes its inorder successor) with AVL rebalancing. What is the final preorder?
- A. 79, 28, 20, 37, 36, 93, 94, 97
- B. 37, 28, 20, 36, 93, 79, 94, 97
- C. 79, 28, 20, 37, 36, 94, 93, 97
- D. 37, 28, 20, 36, 94, 93, 79, 97
Correct answer: C. 79, 28, 20, 37, 36, 94, 93, 97
After each deletion walk back up and rotate at any node whose balance becomes ±2 (RR at 93). 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
- Dijkstra's algorithm runs from A on the directed graph A→B (14), A→C (11), A→D (8), A→E (1), A→F (15), B→C (6), B→E (2), B→F (5), C→D (9)…
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: E→D (9), A→B (6), F→A (-3), F→D…
- Prim's algorithm starts at D on the weighted undirected graph A–D (23), A–F (5), A–G (28), B–C (17), B–E (15), B–G (2), C–E (21), C–G…
- A binary search tree holds exactly the keys 41, 50, 62, 63, 68, 69, 74, 94. Which ONE of the following can be its POSTORDER traversal?
- A 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [58, 57, 54, 33, 11, 34, 22, 42, 30, 19]. After…
- Keys 33, 11, 72, 19, 76, 71, 31, 74, 40, 37, 45 are inserted in that order into an empty BST. Then 33 is deleted and after that 37 is…