Skip to content

Files

Latest commit

cf09cfa · Apr 22, 2023

History

History

Count Non-Leaf Nodes in Tree - GFG

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Count Non-Leaf Nodes in Tree

Easy

Given a Binary Tree of size N, your task is to complete the function countNonLeafNodes(), that should return the count of all the non-leaf nodes of the given binary tree.

Example:

Input: 

Output:
2
Explanation:
Nodes 1 and 2 are the only non leaf nodes.

Your Task:
You don't need to take input or print anything. Your task is to complete the function countNonLeafNodes() that takes root as input and returns the number of non leaf nodes in the tree.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(Height of the Tree).

Constraints:
1 ≤ Number of nodes ≤ 105