Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
Keys 66, 49, 54, 41, 65, 58, 22, 18, 42, 47 are inserted into an empty AVL tree (giving preorder 54, 41, 22, 18, 47, 42, 49, 65, 58, 66). Then 66 and 54 are deleted in that order (a two-child node takes its inorder successor) with AVL rebalancing. What is the final preorder?
- A. 41, 22, 18, 58, 47, 42, 49, 65
- B. 58, 41, 22, 18, 47, 42, 49, 65
- C. 49, 41, 22, 18, 47, 42, 65, 58
- D. 49, 22, 18, 42, 41, 47, 65, 58
Correct answer: A. 41, 22, 18, 58, 47, 42, 49, 65
After each deletion walk back up and rotate at any node whose balance becomes ±2 (LL at 58). 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
- An undirected connected graph has edges A–D, A–F, A–G, B–C, B–F, B–H, B–I, C–D, C–H, D–F, E–I. How many articulation points (cut vertices)…
- A min-heap holds 31 distinct keys in a 0-indexed array (a full tree with 5 levels). At how many different indices can the 4th-smallest key…
- In the grid 11111 / 11112 / 11121 / 11111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its…
- A B-tree has minimum degree t = 3 (every non-root node has between 2 and 5 keys) and height 2 (a root-only tree has height 0). What are…
- In the grid 11111 / 11210 / 21111 / 00111 (rows top to bottom; 2 = rotten, 1 = fresh, 0 = empty), every minute each rotten orange rots its…
- What is the edit distance (insert, delete, substitute; each cost 1) between RECESSION and HEAPSORT?