Data Structures & AlgorithmsHardProduct company OA · Infosys pattern
Keys 10, 20, 30, 25, 28 are inserted into an empty AVL tree. Which rotations are performed, in order (named by imbalance case)?
- A. RR, LR → root 20
- B. RR, RL → root 20
- C. RR, RR → root 25
- D. RL, LR → root 28
Correct answer: A. RR, LR → root 20
10, 20, 30 is right-right → left rotation at 10, root 20. 25 goes under 30 on the left, then 28 goes to 25's right: 30 now has balance +2 with a left child that is right-heavy → LR case (left rotation at 25, right rotation at 30), giving 28 with children 25 and 30. The root stays 20. The imbalance at 30 leans LEFT, so RL is the wrong case.
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
- Floyd–Warshall on vertices 0–3 starts from the weight matrix below (∞ = no edge). After the iteration with k = 0 (paths allowed to go…
- How many distinct spanning trees does the graph with vertices A, B, C, D and edges A–B, B–C, C–D, D–A, A–C (a 4-cycle plus one diagonal)…
- A recursive segment tree is built over an array of n = 6 elements (each internal node splits its range into two halves; leaves are single…
- In a Fenwick (binary indexed) tree of size 16 (1-based), the update at index 5 adds the value to i = 5 and then repeatedly does i += i &…
- Union–find with NO union by rank/size and NO path compression: union(a, b) sets parent[find(a)] = find(b). Starting with singletons 0–5…
- A connected undirected graph has vertex degrees A: 3, B: 4, C: 2, D: 3, E: 2. Does it have an Euler path (using every edge exactly once)…