I'm learning about AVL trees and their rotations in data structures. I wish my lectures had showcased the simplest complete right rotation because I found the topic became way easier for me when I conceptualized it this way.
By "complete right rotation", I mean:
- The node being rotated (let's call it A) has a parent.
- A also has a left child (let's call it B).
- B has a right child.
This setup should cover all possible node relationships for a right rotation. I'm curious about the structure where, if my right rotation logic passes this test, it's very likely to handle all cases of right rotations correctly. What is the simplest AVL tree structure that showcases this kind of right rotation, with the least amount of nodes?
There are two cases you may want to look at: A is a left child of its parent P, or A is a right child of its parent P. Depending on how you implement the rotation, this difference may be important, as the rotation give P a different child. Here is the first case:
You required that A had a right child, but to be honest, it doesn't play a significant role in this rotation, as the link between A and C does not change.
There are three edges that are mutated. Here is the pseudo code for it (assuming you have a reference to P):
The second case, where A is the right child of P, is easy to construct from this.