otherwise just delete it the last part works because the left-most node in the right sub-tree is guaranteed to be bigger than all nodes in the left sub-treesmaller than all the other nodes in the right sub-treeand have no left sub-tree itself for instanceif we delete the node with value from the tree in figure we get the tree displayed in figure figure example of node deletion in binary search tree in practicewe need to turn the above algorithm (specified in wordsinto more detailed algorithm specified using the primitive binary tree operatorsdelete(value vtree tif isempty(terror('errorgiven item is not in given tree'else if root( /delete from left sub-tree return maketree(root( )delete( ,left( ))right( ))else if root( /delete from right sub-tree return maketree(root( )left( )delete( ,right( )))else /the item to be deleted is root(tif isempty(left( )return right(telseif isempty(right( )return left(telse /difficult case with both subtrees non-empty return maketree(smallestnode(right( ))left( )removesmallestnode(right( )if the empty tree condition is metit means the search item is not in the treeand an appropriate error message should be returned the delete procedure uses two sub-algorithms to find and remove the smallest item of given sub-tree since the relevant sub-trees will always be non-emptythese sub-algorithms can be written with that precondition howeverit is always the responsibility of the programmer to ensure that any preconditions are met whenever given procedure is usedso it is important to say explicitly what the preconditions are it is often safest to start each procedure with