Data Structures & AlgorithmsModerateProduct-company MCQ pattern
AVL tree: keys 30, 10, 20 are inserted in that order into an empty tree. What rebalancing happens, and what is the root afterwards?
- A. Single left rotation; root 20
- B. Left-Right double rotation; root 20
- C. No rotation is needed; root 30
- D. Single right rotation; root 10
Correct answer: B. Left-Right double rotation; root 20
30 becomes unbalanced (balance +2) with the new node in the RIGHT subtree of its LEFT child: the LR case. Rotate 10 left, then 30 right, making 20 the root with children 10 and 30. A single right rotation would leave 10 as root with 20 under 30, still unbalanced.
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
- What is the minimum number of nodes in an AVL tree of height 4 (a single node has height 0)?
- How many different spanning trees does the complete graph K₄ have?
- How many times in total is fib called (including the first call) when fib(6) is evaluated? c int fib(int n) { if (n <= 1) return n; return…
- What does fun(3) print? c void fun(int n) { if (n > 0) { fun(n - 1); printf("%d ", n); fun(n - 1); } }
- What are the time complexities of versions P and Q? c int P(int n) { if (n <= 1) return 1; return P(n/2) + P(n/2) + n; } int Q(int n) { if…
- What is the time complexity of solve(n)? python def solve(n): if n <= 0: return for i in range(n): pass # O(1) work solve(n - 1)