Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
Keys 32, 44, 47, 53, 93, 54, 12, 22, 68, 97 are inserted into an empty AVL tree (giving preorder 53, 44, 22, 12, 32, 47, 68, 54, 93, 97). Then 22 and 47 are deleted in that order (a two-child node takes its inorder successor) with AVL rebalancing. What is the final preorder?
- A. 53, 32, 12, 44, 68, 54, 93, 97
- B. 53, 44, 32, 12, 68, 54, 93, 97
- C. 53, 44, 12, 32, 68, 54, 93, 97
- D. 44, 32, 12, 54, 53, 93, 68, 97
Correct answer: A. 53, 32, 12, 44, 68, 54, 93, 97
After each deletion walk back up and rotate at any node whose balance becomes ±2 (LL at 44). 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
- Using parts 3, 4, 5 (each any number of times), in how many ways can 10 be written as an ORDERED sum (so 1 + 2 and 2 + 1 count separately)?
- The boolean expression T ^ F | T & T (T = true, F = false, & = AND, | = OR, ^ = XOR) can be fully parenthesised in 5 ways. In how many of…
- Coins of denominations 1, 3, 6, 8 are available in unlimited supply. What is the minimum number of coins needed to make 28, and how many…
- What is the length of the shortest string that has BOTH INTERVAL and RECESSION as subsequences (shortest common supersequence)?
- A tree on vertices 1–8 has edges 2–1, 3–1, 4–2, 5–4, 6–5, 7–2, 8–7. What is the sum of the distances (in edges) over all unordered pairs…
- How many structurally different binary trees with 7 nodes have height EXACTLY 3 (height = edges on the longest root-to-leaf path)?