Data Structures & AlgorithmsHardProduct-company placement
Keys 51, 83, 75, 67, 42, 93, 22, 21, 38, 81 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. 5 rotations, root 75
- B. 3 rotations, root 75
- C. 5 rotations, root 51
- D. 6 rotations, root 75
Correct answer: A. 5 rotations, root 75
The rebalancing events are RL at 51, LL at 42, LR at 51: 1 single and 2 double, i.e. 1 + 2×2 = 5 rotations; the root ends as 75.
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
- In how many different ways can 'aaaaaa' be split into a sequence of words from the dictionary {a, aa, aaa} (every character used, order…
- 0/1 knapsack with capacity 14: items (weight, value) = (7, 23), (4, 12), (5, 8), (4, 12), (6, 34). What is the maximum total value?
- The POSTORDER traversal of a BST with distinct keys is 10, 12, 25, 49, 53, 92, 88, 93, 76, 32. What are the height of the tree (edges on…
- Kruskal's algorithm runs on the weighted undirected graph A–C (17), A–D (12), A–E (22), A–F (4), A–G (8), B–E (18), C–D (24), C–E (19)…
- What is the maximum flow from S to T in the network with directed capacities A→B (14), A→T (4), C→B (4), C→T (15), S→A (6), S→B (7), S→C…
- Heap sort (ascending) is run on [30, 16, 36, 4, 37, 35, 41, 28]: build a max-heap bottom-up, then repeatedly swap the root with the last…