The keys 30, 10, 20 are inserted in that order into an empty AVL tree. Which rotation is needed?
Correct answer B. A left-right double rotation (left rotation at 10, then right rotation at 30)
Explanation
Node 30 becomes unbalanced with factor +2, and the new key 20 lies in the right subtree of 30's left child 10, a left-right case. A single right rotation at 30 would merely move the zig-zag to the other side. Rotating left at 10 first straightens the path, then rotating right at 30 makes 20 the root with children 10 and 30.
Answer checked How we write and check questions
Discussion