Binary Search Tree Rotation
Why do you rotate a Binary Search Tree?
Binary Search Tree roatation is important in rebalancing trees and for reorganization.
This can be especially helpful in other type of trees, such as the Red Black Tree.
How do you rotate a Binary Search Tree?
Steps for a right rotation
- Set the root's left to the left child's right child
- Set the parent of that grandchild to the root
- Set the left child's right child to be the root
- You have successfully rotated a tree to the right!
Steps for a left rotation
- Set the root's right to the right child's left child
- Set the parent of that grandchild to the root
- Set the right child's left child to be the root
- You have successfully rotated a tree to the left!
For more information, you read up on it here!