• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
May 31, 2022 |5.2K Views
Size of a Binary Tree
  Share   Like
Description
Discussion

Size of a tree is the number of elements present in the tree
size(tree)
1. If tree is empty then return 0
2. Else
    (a) Get the size of left subtree recursively  i.e., call 
         size( tree->left-subtree)
    (a) Get the size of right subtree recursively  i.e., call 
         size( tree->right-subtree)
    (c) Calculate size of the tree as following:
           tree_size  =  size(left-subtree) + size(right-
                              subtree) + 1
    (d) Return tree_size

Size of a Binary TreeSize of a Binary Tree: https://www.geeksforgeeks.org/write-a-c-program-to-calculate-size-of-a-tree/