Labels: data structures, Java programs.
Dec 17, I've found 4 algorithms to remove the node with 2 children from Binary Search Tree: 1) Find the smallest node from right sub tree and replace it with the node which we want to delete. 2) Find the biggest node from left sub tree and replace it with the node which we want to delete. Nov 27, Wikipedia article gives a good description of BST: bushdig.bar When you delete a node with 2 children, 5 in your case, you can replace the deleted node with minimum value node from the right subtree, or maximum value node from the left subtree.
Nov 28, Case 1: Deleting a node with no children: remove the node from the tree. Case 2: Deleting a node with two children: call the node to be deleted N. Do not delete N. Instead, choose either its inorder successor node or its inorder predecessor node, R. Copy the value of R to N, then recursively call delete on R until reaching one of the first two cases.
If we choose the inorder successor of a node, as the right subtree is not NULL (our present case is a node with 2 children), Estimated Reading Time: 3 mins.