Insertion

Insertion begins as a search would begin; if the root is not equal to the value, we search the left or right subtrees as before. Eventually, we will reach an external node and add the value as its right or left child, depending on the node's value. In other words, we examine the root and recursively insert the new node to the left subtree if the new value is less than the root, or the right subtree if the new value is greater than or equal to the root.

Here is an algorithm for Insertion a new element into binary search tree
---------------------------------------------------
/* Inserts the node pointed to by "newNode" into the subtree rooted at "treeNode" */
void InsertNode(struct node *&treeNode, struct node *newNode)
{
if (treeNode == NULL)
treeNode = newNode;
else if (newNode->value < treeNode->value)
InsertNode(treeNode->left, newNode);
else
InsertNode(treeNode->right, newNode);
}
----------------------------------------------------

Example:

The part that is rebuilt uses T(log n) space in the average case and O(n) in the worst case.
In either version, this operation requires time proportional to the height of the tree in the worst case, which is O(log n) time in the average case over all trees, but O(n) time in the worst case.
Another way to explain insertion is that in order to insert a new node in the tree, its value is first compared with the value of the root. If its value is less than the root's, it is then compared with the value of the root's left child. If its value is greater, it is compared with the root's right child. This process continues, until the new node is compared with a leaf node, and then it is added as this node's right or left child, depending on its value.