Binary Search Tree Deletion

Delete the given keys one at a time from the binary search tree. Possible equal keys were inserted into the right branch of the existing node. Please note that the insertion strategy also affects how the deletion is performed.

The tree can be modified by replacing keys or by updating edges. Replace is done by drag & dropping a key into a node. However, edges can also be drag & dropped to point into another node. For example, a whole subtree can be deleted by drag & dropping an edge to any of the empty nodes. In addition, multiple edges can be modified in one step as the tree is updated only after the Update References button is pressed.

Some additional problems.

Node Delete(Node root, Key k)
1  if (root == null) // failed search
2    return null;
3  if (k == root.key) // successful search
4    return DeleteThis(root, k);
5  if (k < root.key) // k in the left branch
6    root.left = Delete(root.left, k);
7  else // k > root.key, i.e., k in the right branch
8    root.right = Delete(root.right, k);
9  return root;

Node DeleteThis(Node root)
1  if root has two children
2    s = Smallest(root.right); // replace root with its immediate successor s
3    root.key = s.key;
4    root.right = Delete(root.right, s)
5    return root;
6  if root has only left child
7    return root.left
8  if root has only right child
9    return root.right
10  else root has no children
11   return null

Node Smallest(Node root)
1  if root has no left child
2    return root
3  return Smallest(root.left)


  Created Wed Jun 20 16:00:42 EEST 2007 - Powered by SVG-hut