What does the following function do for a given binary tree?
if(root == NULL)
if(root->left == NULL && root->right == NULL)
return1 + fun(root->left) + fun(root->right);
(A) Counts leaf nodes (B) Counts internal nodes (C) Returns height where height is defined as number of edges on the path from root to deepest node (D) Return diameter where diameter is number of edges on the longest path between any two nodes.
Answer:(B) Explanation: The function counts internal nodes.
1) If root is NULL or a leaf node, it returns 0.
2) Otherwise returns, 1 plus count of internal nodes in left subtree, plus count of internal nodes in right subtree.
Please Login to comment...