What is the main purpose of a single right rotation in an AVL tree?
Think about which side is heavy and how the rotation moves nodes to restore balance.
A single right rotation is used when a node's left subtree is heavier. It moves the left child up to the root position and the original root down to the right, restoring balance.
In which situation is a double rotation (left-right or right-left) necessary in an AVL tree?
Consider the imbalance direction of the child subtree relative to its parent.
Double rotations are needed when a subtree is unbalanced in a zig-zag pattern, such as a left child having a right-heavy subtree or a right child having a left-heavy subtree. This requires two rotations to fix.
Given an AVL tree where node 10 has a left child 5, and node 5 has a right child 7, what is the structure of the subtree after performing the correct rotation to balance it?
Initial subtree:
10
/
5
\
7Think about the left-right double rotation steps: first left rotation on 5, then right rotation on 10.
The left-right rotation first rotates node 5 left around 7, then rotates node 10 right around 7. This makes 7 the new root, with 5 as left child and 10 as right child.
Which statement correctly describes the difference between single and double rotations in AVL trees?
Consider the imbalance patterns each rotation type addresses.
Single rotations handle simple cases where imbalance is on one side. Double rotations handle zig-zag cases where the child subtree is heavy in the opposite direction.
After performing a single left rotation on an AVL tree node, what happens to the height of the subtree rooted at that node?
Think about how rotations affect subtree height and balance.
A single left rotation reduces the height of the heavier right subtree, decreasing the overall height of the subtree by one and restoring balance.