
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implement Self-Balancing Binary Search Tree in C++
Self Balancing Binary Search tree
A self-balancing binary search tree (BST) is a height-balanced binary search tree that automatically keeps its height (the maximum number of levels below the root) as small as possible when insertion and deletion operations are performed on the tree.
In the self-balancing binary search tree, the height is maintained in the order of O(logn), so that all operations take O(logn) time on average.
Common examples of self-balancing binary search trees are:
- AVL Tree
- RED Black Tree
- Splay Tree
AVL Tree
An AVL tree is a self-balanced binary search tree where the difference between the height of the left and right binary subtrees for any node cannot be more than one.

Following are the basic operation on AVL:
- Searching
- Insertion
- Deletion
To learn more about the AVL Tree visit this article.
Red Black Tree
The red black tree is also a self-balanced binary searched tree in which every node is colored either black or red. The root and leaf nodes (i.e., null node) in the red-black tree are always marked as black.

The following are the property of the red-black tree:
- Root Property: Root is black
- External Property: Every leaf (Leaf is a null child of a node) is black.
- Internal Property: The children of a red node are black. Hence possible parent of a red node is black node.
- Depth Property: All the leaves have same black depth.
- Path Property: Every path from the root to the descendent leaf node has an equal number of black nodes.
To learn more about the Red-Black Tree visit this article.
Splay Tree
Splay is also a self-balanced binary searched tree. The idea of implementing the splay tree is to bring the most recently inserted element to the root of the tree by performing a sequence of tree rotations, called splaying.

Following are the basic operation on AVL:
- Insertion
- Searching
- Deletion
- Rotation: There are two types of rotation in splay tree (zig rotation and zag rotation).
To learn more about the Splay Tree visit this article.