Deleting in a BST
Procedure :
Search recursively for the data to be deleted.
Call the function on the left subtree if the data to be deleted is less than current node's data.
Call the function on the right subtree if the data to be deleted is greater than current node's data.
Once the node is found, check the height of it's left and right subtree.
If the height of left subtree is greater, find the inorder predecessor and replace the data in node to be deleted with inorder predecessor's data. Now, delete the inorder predecessor as it's a leaf node.
If the height of right subtree is greater, find the inorder successor and replace the data in node to be deleted with inorder successor's data. Now, delete the inorder successor as it's a leaf node.
If the node to be deleted is a leaf node, check if it is the root node. If yes, make the root as NULL. Then, free the memory.
Utility Functions :
Contributed by Nitin Ranganath
Last updated