This problem demonstrates simple binary tree traversal. Given a binary tree, count the number of nodes in the tree.
Here is the code in c/cpp:
/\* Compute the number of nodes in a tree. \*/
int size(struct node\* node) {
if (node==NULL) {
return(0);
} else {
return(size(node->left) + 1 + size(node->right));
}
}