All topics
75

Double rotations: the zig-zag cases

Tier 1Locked

Where it runs

1. The problem

Steps 73 and 74 gave you the two single rotations. A left rotation lifts the right child up and fixes a right-heavy node. A right rotation, its mirror, fixes a left-heavy node. Both fix a straight tilt: the heavy child (the one with the extra height under it) tilts the same way as its parent. For example, a right child that itself tilts right, or a left child that tilts left. Sorted data builds exactly such a straight chain, and one rotation straightens it.

There is a second shape that one rotation does not straighten. A node is left-heavy, while its left child tilts the other way, to the right. Or a node is right-heavy, while its right child tilts left. This bend is called a zig-zag. Rotate the top node once, and the bend just moves to the other side; the height does not drop. A zig-zag is fixed with two rotations: first you straighten the child, then you rotate the node.

This step is part of the paid track

The first 33 steps are open to everyone: lesson, exercise and tests. This one opens with full access. Start with a free account and the free steps.

Create a free accountSee what is included

On LeetCode

No LeetCode problem asks for a double rotation on its own. The rebalance step from this lesson goes inside the AVL insert and delete. The full AVL tree comes together in lessons 76 and 77, and those lessons list the problems it solves.

We use necessary cookies to run the site (sign-in and language). If you accept, we also load Google Analytics to see which pages are used, and Google reCAPTCHA to keep spam off the contact and bug-report forms. Privacy policy