(step (step now let us look at the algorithm to search for an element in the binary search tree as shown in fig in step we check if the value stored at the current node of tree is equal to val or if the current node is nullthen we return the current node of tree otherwiseif the value stored at the current node is less than valthen the algorithm is recursively called on its right sub-treeelse the algorithm is called on its left sub-tree inserting new node in binary search tree the insert function is used to add new node with given figure searching node with the value value at the correct position in the binary search tree in the given binary search tree adding the node at the correct position means that the new node should not violate the properties of the binary search tree figure shows the algorithm to insert given value in binary search tree the initial code for the insert function is similar to the search function this is because we first find the correct position where the insertion has to be done and then add the node at that position the insertion function changes the structure of the tree thereforewhen the insert function is called recursivelythe function should return the new tree pointer in step of the algorithmthe insert function checks if the current node of tree is null if it is searchelement (treevalnullthe algorithm simply adds the nodeelse it looks at the current node' value and then step if tree -data val or tree null recurs down the left or right sub-tree return tree else if the current node' value is less than that if val data of the new nodethen the right sub-tree is return searchelement(tree -leftvaltraversedelse the left sub-tree is traversed else the insert function continues moving down return searchelement(tree -rightvalthe levels of binary tree until it reaches [end of if[end of ifleaf node the new node is added by following step end the rules of the binary search trees that isif the new node' value is greater than that figure algorithm to search for given value in binary of the parent nodethe new node is inserted search tree in the right sub-treeelse it is inserted in the left sub-tree the insert function requires time insert (treevalproportional to the height of the tree in the worst case it takes (log ntime to execute step if tree null allocate memory for tree in the average case and (ntime in the worst set tree -data val case set tree -left tree -right null look at fig which shows insertion of else values in given tree we will take up the case if val data of inserting and insert(tree -leftval else insert(tree -rightval[end of if[end of ifstep end figure algorithm to insert given value in binary search tree deleting node from binary search tree the delete function deletes node from the binary search tree howeverutmost care should be taken that the properties of the binary search tree are not violated and nodes are not