previous | start | next

Case 2: Deleting a Node with 2 children

If the node to be deleted has 2 children there are 2 obvious candidates to replace the key at that node:

Once this choice is made, we must decide how to change the tree to accomplish this replacement.

The following choices describe the deletion and is called Hibbard deletion.

Delete 40 from this tree. The next larger key is 50.

Replace key 40 with 50.

Now 50 is in two nodes. Delete 50 from the right subtree. Note that it in the right subtree 50 will not have a left child, so deleting it is handled by the simpler case 1 part of the code.

Set 50's left and right links to be 40's left child and the modified right child (50 was deleted from the right child).

root node 40 is to be deleted from this tree

new root after deleting 40 is its successor, 50



previous | start | next