0

Count the number of leaf nodes.

You are given a tree with N nodes numbered from 0 to N-1.you are also given a node X which you are supposed to delete.you have tell the number of leaf nodes in a tree after deleting the given node.Note that deleting a node deletes all the nodes in its subtree.

7th Apr 2018, 6:45 AM
sitesh Kumar behera
sitesh Kumar behera - avatar
3 Answers
- 1
The best thing is to traverse the tree in inorder traversal and if( (node->leftChild == null) && (node->rightChild == null) ) leaf_count++;
7th Apr 2018, 5:33 PM
G P
G P - avatar
+ 1
we have to delete a node also along with that it will delt all the nodes in its subtree
7th Apr 2018, 5:37 PM
sitesh Kumar behera
sitesh Kumar behera - avatar
0
To delete the leaf nodes, back track to the parent Node of the leaf and initialize the leaf node to null or use the free() function to free the dynamically allocated memory.
7th Apr 2018, 5:50 PM
G P
G P - avatar