Deleting a node

When we are deleting a node, we have to consider that the node can be an internal node or a leaf. If it's a leaf, it has zero children. However, if the node is internal, it can have one or two children. In such a case, we need to take extra steps to make sure the tree is constructed right after the deletion. That is why deleting a node from BST is always a challenging job compared to other operations. Here are the things to consider for a node deletion:

  1. If the node has no child, make the node NULL.
  2. If the node has only one child, make the child take node's place.
  3. If the node has two children, then find the successor of the node and replace it to the current node's place. Remove the successor node.

We have discussed most of the possible operations for a binary search tree. Now, we will implement the binary search tree step-by-step, starting with insert, search, finding minimum and maximum, and at the end, the delete operation. Let's get started with the implementations.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset