Search⌘ K
AI Features

Rotation

Understand the rotation operations on subtrees in balanced binary search trees. Explore how left and right rotations help maintain the BST property while balancing tree height. Learn the impact of rotations on tree structure and performance, enabling efficient search, insertion, and deletion operations with logarithmic time complexity.

We'll cover the following...

Before we discuss how self-balancing BST works, we must first understand the rotation operation on a subtree (left and right). While doing a rotation - BST property should stay intact.

Keeping the above points in mind, let’s see what a left rotation looks like.

Take a look at the below BST:

%0 node_1 A node_1716485480899 T1 node_1->node_1716485480899 node_1716485461615 B node_1->node_1716485461615 node_1716485494812 T2 node_1716485461615->node_1716485494812 node_1716485487110 T3 node_1716485461615->node_1716485487110

We want to perform a left rotation:

  1. BB becomes the root. Since key(A)<key(B)key(A) < key(B), AA
...