What is a Binary Search Tree (BST)?

A Binary Search Tree (BST) is a binary tree in which every node contains only smaller values in its left subtree and only larger values in its right subtree. This property is called the BST property and every binary search tree follows this property as it allows efficient insertion, deletion, and search operations in a tree.

Conditions for a Tree to be a Binary Search Tree

For a tree to be called a binary search, it should fulfill the following conditions:

  • All the nodes in the left subtree of any node contain smaller values and all the nodes in the right subtree of any node contain larger values.
  • Both the left and right subtrees of any node in the tree should themselves be a BST. This means that they should follow the BST rule.
  • A unique path exists from the root node to every other node.

Binary Search Tree in C++

A Binary Search Tree (BST) is a type of binary tree in which the data is organized and stored in a sorted order. Unlike, a binary tree that doesn’t follow a specific order for node placement, in a binary search tree all the elements on the left side of a node are smaller than the node itself, and elements on the right side of a node are greater.

In this article, we will learn more about the binary search tree, operations performed on BST, and implementation of BST, as well as the advantages, disadvantages, and applications of binary search tree in C++.

Similar Reads

What is a Binary Search Tree (BST)?

A Binary Search Tree (BST) is a binary tree in which every node contains only smaller values in its left subtree and only larger values in its right subtree. This property is called the BST property and every binary search tree follows this property as it allows efficient insertion, deletion, and search operations in a tree....

Binary Search Tree Representation in C++

In BST, every value on the left subtree < parent node < right subtree value....

Basic Operations on Binary Search Tree

The following are the basics operations performed on a binary search tree:...

C++ Program to Implement Binary Search Tree

The below program demonstrates all the major operations on a binary search tree: creation, searching, insertion and deletion....

Applications of Binary Search Tree

Following are the applications of binary search tree:...

Advantages of Binary Search Tree

Because of the unique properties of BST, it provides an efficient way to search an element having O(log n) time complexity. The In-Order Traversal of BST is always in a sorted order. So, it becomes easier to retrieve elements in sorted order in a BST.It can adapt to various applications by defining a custom node structure.Balanced Binary search tree have logarithmic height that ensures efficient operations.It stores only the key values, that makes them space-efficient....

Disadvantages of Binary Search Tree

The performance of BST depends upon its balance. Skewed BST is the worst-case scenario where the search complexity becomes O(n), just like any other tree.Although operations like insertion and deletion are easy in BST, maintaining the balance of the tree is hard.If the tree is made by using a sorted list, then the creation can lead to a highly unbalanced BST which degrades its performance. One solution is to balance the tree after every insertion.Binary search tree become less efficient for very large datasets...

Frequently Asked Questions on Binary Search Tree

What is Binary Search Tree (BST)?...