Description: Size of a tree is the number of elements in the tree. Given a tree, we have to calculate the size of the tree, that is the number of elements.
The tree below contains 5 elements.
/*Recursive algorithm to solve the problems is:*/
int size(node *root)
return 0;/*tree is empty*/
return (size(root->left) +size(root->right) + 1 );/*size of left subtree+right subtree+1*/
O(n) where n is the number of elements in the tree.