Self-Balancing Binary Search Trees are height-balanced binary search trees that automatically keeps height as small as possible when insertion and deletion operations are performed on tree. The height is typically maintained in order of Log n so that all operations take O(Log n) time on average.
Red Black Tree
How do Self-Balancing-Tree maintain height?
A typical operation done by trees is rotation. Following are two basic operations that can be performed to re-balance a BST without violating the BST property (keys(left) < key(root) < keys(right)). 1) Left Rotation 2) Right Rotation
T1, T2 and T3 are subtrees of the tree rooted with y (on the left side) or x (on the right side) y x / \ Right Rotation / \ x T3 – – – – – – – > T1 y / \ < - - - - - - - / \ T1 T2 Left Rotation T2 T3 Keys in both of the above trees follow the following order keys(T1) < key(x) < keys(T2) < key(y) < keys(T3) So BST property is not violated anywhere.
|Metric||RB Tree||AVL Tree||Splay Tree|
|Efficient Implementation requires||Three pointers with color bit per node||Two pointers with balance factor per
|Only two pointers with
no extra information
|Mostly used||As universal data structure||When frequent lookups are required||When same element is
retrieved again and again
|Real world Application||Multiset, Multimap, Map, Set, etc.||Database Transactions||Cache implementation, Garbage collection Algorithms|
- Comparisons involved in Modified Quicksort Using Merge Sort Tree
- Second minimum element using minimum comparisons
- Maximise the number of toys that can be purchased with amount K using min Heap
- Count inversions in an array | Set 4 ( Using Trie )
- Lexicographical ordering using Heap Sort
- Need for Abstract Data Type and ADT Model
- Shortest cycle in an undirected unweighted graph
- Van Emde Boas Tree | Set 4 | Deletion
- Queries for the number of nodes having values less than V in the subtree of a Node
- Red-Black Trees | Top-Down Insertion
- Van Emde Boas Tree - Set 3 | Successor and Predecessor
- Implementing a BST where every node stores the maximum number of nodes in the path till any leaf
- String Range Queries to find the number of subsets equal to a given String
- Pre-Order Successor of all nodes in Binary Search Tree
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.