Home » Data Structure & Algorithms » Size of Binary Tree

Size of Binary Tree

Question :
WAP to find the Size of a binary tree in O(n) time complexity.



Solution :
The problem is solved in recurssive way.

Algorithm :
Step 1 : If tree is empty then return 0.
Step 2 : Recursively traverse left sub-tree and right sub-tree.
Step 3 : For each node of left sub-tree add 1 and for each node of right sub-tree add 1 to the result and return the same.

Program :


Leave a comment

Your email address will not be published. Required fields are marked *

13 − 1 =