The method to delete a key k can be described easily and is similar to the put method in that we must first find the node containing k (if there is one):
To delete k from the tree:
- if k < the key in the root of this tree, delete k (recursively) from the left subtree and reattach the modified left subtree.
- else if k > the key in the root of this tree, delete k from the right subtree and reattach the modified right subtree.
- else k is equal to the key in the root of the tree. If so, delete this node and return the possibly new root of the modified tree.
This guides us to write the same sort of pair public/private methods for delete as for put, but must fill in the part to delete the Node containing k once we have found it.