Data Structures & AlgorithmsHardGATE CS
Keys 72, 29, 21, 18, 28, 16, 23, 33, 25, 67 are inserted in order into an empty AVL tree. Counting a double rotation as two single rotations, how many single rotations are performed in total, and what is the final root?
- A. 4 rotations, root 21
- B. 6 rotations, root 21
- C. 6 rotations, root 72
- D. 7 rotations, root 21
Correct answer: B. 6 rotations, root 21
The rebalancing events are LL at 72, LL at 29, LR at 28, LR at 72: 2 single and 2 double, i.e. 2 + 2×2 = 6 rotations; the root ends as 21.
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
- DFS runs on the directed graph with adjacency lists A: BG; B: FG; C: AEFG; D: C; E: A; F: A; G: –, starting at A, scanning lists in the…
- A tree on vertices 1–8 has edges 2–1, 3–2, 4–2, 5–2, 6–2, 7–4, 8–3. What is the sum of the distances (in edges) over all unordered pairs…
- The weighted undirected graph A–B (1), A–C (3), A–D (5), B–D (3), B–E (6), C–D (3), D–E (6) has repeated weights. How many different…
- A DAG on vertices A–G has edges A→C, A→D, A→E, E→B, E→C, E→F, G→E, G→F. What order does Kahn's algorithm that always removes the…
- DFS on the directed graph with adjacency lists A: CDE; B: FG; C: –; D: G; E: FG; F: AG; G: – starts at A (scanning lists in the order…
- Keys 94, 18, 63, 88, 99, 54, 31 inserted in this order build a BST. How many of the 7! orderings of these same 7 keys, inserted into an…