To complete our discussion of Binary Search Trees we need to discuss the bstDelete operation. The process would go something like the following:
Search for a node containing the "key" valueLet's take a look at the following BST:
if (key not found)
return
else if (either subtree is empty)
{
delete the node replacing the parents link with the
ptr to the nonempty subtree or NULL if both
subtrees are empty
}
else
{
Traverse the left subtree of the node to be deleted
such that you find the rightmost node (Rnode) in the left
subtree
Move the content of Rnode to the node to be deleted
Set Rnode's parent pointer to point to the left subtree
of Rnode
Free the storage from the unused node
}
P#1: Assume that you always start with the above tree, how would each of the following nodes be deleted?
8
12
5
15
10
P#2: How would you change the existing BT ADT to make deletion of a node in a BST easier?