Consider the C function foo and the following binary tree. The root holds 10; its left child holds 5 and its right child holds 11. Node 5 has left child 3 and right child 8. Node 11 has no left child and has right child 13. Nodes 3, 8 and 13 are leaves.
typedef struct node {
int val;
struct node *left, *right;
} node;
int foo(node *p) {
int retval;
if (p == NULL)
return 0;
else {
retval = p->val + foo(p->left) + foo(p->right);
printf("%d ", retval);
return retval;
}
}
When foo is called with a pointer to the root node of the given binary tree, what will it print?
- A3 8 5 13 11 10
- B3 5 8 10 11 13
- C3 8 16 13 24 50
- D3 16 8 50 24 13