Data Structures & AlgorithmsVery hardAmazon/Microsoft SDE pattern
Keys 60, 70, 80 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 70, left 60, right 80
- B. root 70, left 80, right 60
- C. root 60, left 70, right 80
- D. root 80, left 60, right 70
Correct answer: A. root 70, left 60, right 80
Inserting three keys in strictly increasing order creates a RR-shaped imbalance at the first-inserted node, fixed by a single rotation that makes the middle-valued key (70) 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 60.
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
- A binary tree has preorder traversal [90, 31, 36, 77, 58, 43, 83] and inorder traversal [31, 36, 43, 58, 77, 83, 90]. Reconstructing the…
- Undirected graph edges: A–D, D–C, B–C, C–A. Using a BFS 2-colouring, is this graph bipartite?
- Keys 57, 11, 34, 33, 80, 9, 72, 24, 56, 66 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain)…
- Undirected graph edges: B–C, C–A, E–C, E–D, E–B. Using a BFS 2-colouring, is this graph bipartite?
- Build a binary min-heap in place from the array [4, 37, 81, 88, 64, 1, 84, 86] using bottom-up heapify (sift-down from the last internal…
- An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [D, F]; B: [C, F]; C: [B, E]; D: [A, E]; E: [C, D]…