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.
3 Respostas
- 1
The best thing is to traverse the tree in inorder traversal and if( (node->leftChild == null) && (node->rightChild == null) ) leaf_count++;
+ 1
we have to delete a node also along with that it will delt all the nodes in its subtree
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.