Data Structures & AlgorithmsHardIBM · Deloitte pattern
Keys 41, 31, 21 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here), what is the resulting root and its two children (left, right)?
- A. root 41, left 21, right 31
- B. root 31, left 41, right 21
- C. root 21, left 21, right 31
- D. root 31, left 21, right 41
Correct answer: D. root 31, left 21, right 41
Inserting three keys in strictly decreasing order creates a LL-shaped imbalance at the first-inserted node, fixed by a single rotation that makes the middle-valued key (31) the new root, with the smallest key as its left child and the largest as its right child. Without rebalancing, the tree would stay a straight chain rooted at 41.
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
- Keys 38, 48, 58 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Undirected graph edges: B–D, C–A, E–B, E–A, D–E, C–B, A–B. Using a BFS 2-colouring, is this graph bipartite?
- A directed graph has edges E→A, C→D, D→B, C→E, D→C. Using 3-colour DFS (white/grey/black, a grey-to-grey back edge means a cycle), does…
- An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [B]; B: [A, C, F]; C: [B, E, F]; D: [F]; E: [C]; F…
- A binary tree has preorder traversal [90, 24, 42, 38, 77, 67, 57, 44] and inorder traversal [24, 38, 42, 44, 57, 67, 77, 90]…
- A binary tree has preorder traversal [9, 97, 20, 59, 28, 78] and inorder traversal [9, 20, 28, 59, 78, 97]. Reconstructing the tree (root…