Binary Search Tree: A binary search tree is a type of tree in which every node is organized in the sorted order. It is also called an ordered binary tree.

Properties of BST

  1. The left sub-tree value is less than the root node.
  2. Similarly, the right sub-tree value is higher than the root node.
  3. This rule is reapplied to all left and right sub-trees of the root.
Binary Search Tree

Operations of the BST

There are three types of operations in the BST.

  1. Search operation
  2. Insertion operation
  3. Delete operation

Search operation:

The search operation is used to search a particular node in a BST. Whenever any node in BST is searched, that node is first compared with the root node. If the node is less than the root node, it is searched in the left subtree. If the node is greater than the root node, it is searched in the correct subtree.

Algorithm of the Search operation

Insertion Operation

It is used to add a new node to a particular location in a specific situation. Whenever a new node is inserted in the BST, the location of that node is first searched. The new node is first compared with the root node. If the new node is less than the root node, search the null location in the left subtree and insert that node. If the node is greater than the root node, search the null location in the right subtree and insert that node.

Algorithm of the Insertion operation

Delete operation

This operation is used to delete a node in a specific situation. A node can be deleted from the following locations.

  1. Leaf node
  2. One child node
  3. Two child nodes

Leaf node: In this case, it simply removes the leaf node in the tree. This case is much simpler than other cases.

For example, remove the 6 in this BST.

Binary Search Tree

One child node: In this case, first, the original node is replaced with the child node, and then the node is removed. For example, remove the 9 in this BST.

Binary Search Tree

Pin It on Pinterest

Share This