Size of Binary search tree
The size of BST is:
(size of left subtree)+1(root)+(size of right subtree)
(size of left sub-subtree)+1(left-sub-root)+(size of right sub-tree) + 1(root) + (size of left sub-subtree)+1(right-sub-root)+(size of right sub-tree)
int getSize(Node* root)
{
if(root==0)
return 0;
else
return getSize(root->left)+getSize(root->right)+1;
}
{
if(root==0)
return 0;
else
return getSize(root->left)+getSize(root->right)+1;
}
Comments
Post a Comment