Objective: Given a binary tree, write an algorithm to delete it.
This is one of the basic problem in trees. if you are new to trees then this problem will help you build your foundation.
- To delete a binary tree, we need to set all the node objects to null then garbage collection will take care of rest of the things. If you are writing the code in C/C++ then you will have to clear the allocated memory by yourself.
- Do the post order traversal and set the node to null.
Output: Deleting Node:4 Deleting Node:5 Deleting Node:2 Deleting Node:3 Deleting Node:1