Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Delete all the nodes from a binary tree

Recursive :

To delete all the nodes, you will have to visit all the nodes.

There are three ways to traverse the binary tree :

  • Post order

  • Pre order

  • In order.

To delete all the nodes, we will have to make sure we do not delete a parent before we delete all of its children. Because if we delete the parent, then we lose the pointers to its children.

Hence, we will have to use the Post order traversal.

 

 


Non-recursive :

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *