AlgoFrames

Identify the rotation

Warm-up · Multiple choice · about 3 min

The keys 20, 10, 15 were inserted into an empty AVL tree. Before any repair the tree looks like the picture: 20 has balance +2. Which repair restores the AVL property?

Example 1

Input:

[[20,10,15]]

Output:

Rotate left at 10, then right at 20

The path from 20 goes left, then right: a zig-zag.

Constraints

  • Balance factor = left height − right height

Learn the idea first: AVL trees and rotations, a visual lesson.

More AVL trees and rotations problems