Binary Tree

For the given binary tree , leaf nodes are 5,7,10,15 (Total 4)
So output should be -> 4

Process:

  1. Given a binary tree , first process will ask root (9) how many leaf nodes it has, it will return answer as --> number of leaf nodes present in left sub-tree (root 6) + number of leaf nodes present in right sub-tree (root 12)
  2. So control will ask root of it's left sub-tree (that is 6) -- how many leaf nodes it has ? It will return same answer as --> number of leaf nodes present in left sub-tree(root 5) + number of leaf nodes present in right sub-tree (root 7) , and the output will be returned above to root (9)
  3. Similarly 




Post a Comment

Previous Post Next Post