Deleting a node in Binary tree only involves three cases,
- Deleting Leaf node [node with no child]
- Deleting node with 1 child
- Deleting node with 2 children
Deleting leaf node, just free the node space and make the parent's child link to null.
Deleting node with 1 child remove the node and make the grandchildren as its child.
10
/ \
5 15
/ \
2 17
/ \
1 3
here if we wish to delete 5, make 2 as child of 10, so the tree becomes
10
/ \
2 15
/ \ \
1 3 17
This also applies for deleting 15 from tree.