Balanced binary search trees in Data Structure

Here we will see what is the balanced binary search tree. The binary search trees (BST) are binary trees, who has lesser element at left child, and greater element at right child.

The average time complexity for searching elements in BST is O(log n). It is depending on the height of the binary search tree. To maintain the properties of the binary search tree, sometimes the tree becomes skewed. So the skewed tree will be look like this −

This is actually a tree, but this is looking like a linked list. For this kind of trees, the searching time will be O(n). That is not effective for binary trees.

To overcome these problems, we can create a tree which is height balanced. So the tree will not be slewed. Forcefully, we will make then balanced. So each side of a node will hold a subtree whose height will be almost same

There are different techniques for balancing. Some of them are −

  • AVL tree

  • Red-Black Tree

The height balanced form of the above example will be look like this −