- #1
Chinta
- 8
- 0
I guess this is the first question on partly CS topic in this forum. But I think you guys will be able to help me.
I have an algorithm which goes as follows:
int CN(struct node *node)
{
if(node==null)
return 0;
return 1 + CN(node->left) + CN(node->right);
}
My question is that how to calculate the complexity of the above code and what is the complexity in terms of number of nodes n.
The answer that I'm guessing is O(nlogn). But the answer is given as O(n); I'm clueless how to approach to get O(n)?
I have an algorithm which goes as follows:
int CN(struct node *node)
{
if(node==null)
return 0;
return 1 + CN(node->left) + CN(node->right);
}
My question is that how to calculate the complexity of the above code and what is the complexity in terms of number of nodes n.
The answer that I'm guessing is O(nlogn). But the answer is given as O(n); I'm clueless how to approach to get O(n)?