Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band
Keys [39, 30, 10, 5, 31, 38, 32, 20, 1] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right, left–right and right–left cases). How many rotation operations are performed in total, where a double rotation counts as two single rotations?
- A. 2
- B. 4
- C. 9
- D. 3
Correct answer: D. 3
The insertions trigger 2 rebalancing events; the double rotations add 2 each, giving 3 rotation operations. Counting events, or the final height, is not the same quantity.
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
- Distinct words ['a', 'b', 'ba', 'bb', 'aaa', 'ac'] are inserted into an empty trie (one node per character, shared prefixes share nodes…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–E (1), A–G (1), B–C (1), B–E (1), B–F (1), C–F (1), C–G (1), D–E (1), D–G…
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(11) and count every invocation of f…
- 4 × 5 grid, rows top to bottom ('#' = blocked, '.' = open): ..#.. / ..#.. / ..... / ...#.. Count the paths from top-left to bottom-right…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- On an 7 × 7 chessboard with rows and columns numbered 0 to 6, a knight starts at (0, 3) and must reach (5, 2) (as (row, column)). A knight…