Part 13 of 15 in Binary Trees  

Count number of leaves in a binary tree by animeshn

Problem statement

In this problem, you need to count the number of leaves in a binary tree. A leaf in a tree is a node which has no children, i.e. for a binary tree, both its left and right point to NULL. You do not need to write the whole program, just write a function int countLeaves(Node*) which takes the address of the root as a parameter. the function should return the count of the leaves.

You can use any traversal and check if both children are null then increase counter.

To try out your code

Sign in

Sign up