Practice mode Data Structures

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.