Data Structures & AlgorithmsVery hardProduct-company placement
Keys 64, 54, 44 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 44, left 44, right 54
- B. root 54, left 64, right 44
- C. root 54, left 44, right 64
- D. root 64, left 44, right 54
Correct answer: C. root 54, left 44, right 64
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 (54) 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 64.
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 [23, 2, 94, 67, 57, 46, 81] and inorder traversal [2, 23, 46, 57, 67, 81, 94]. Reconstructing the…
- Build a binary min-heap in place from the array [29, 45, 8, 5, 74, 90, 69, 56, 38] using bottom-up heapify (sift-down from the last…
- Keys 45, 92, 18, 65, 91, 86, 78, 95 are inserted in this order into an empty BST (no rebalancing). What is the height of the tree (edges…
- Keys 55, 50, 19, 76, 39, 98, 34, 63, 58, 69 are inserted via separate chaining (h(k) = k mod 8, new keys appended to the end of the chain)…
- A trie is built from the words {cat, card, den, cats, dog, do, cap}. Using the trie (walk the prefix's characters, then count all words in…
- Build a binary min-heap in place from the array [2, 63, 36, 74, 23, 20, 15, 22] using bottom-up heapify (sift-down from the last internal…