Consider the C function foo and the binary tree shown.
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?
Tap to open full sizeFigure description
A binary tree with root node 10. Root's left child is 5, root's right child is 11. Node 5's left child is 3 and right child is 8 (5 has no other children). Node 11's right child is 13; node 11 has no left child. Nodes 3, 8, and 13 are leaves with no children. Edges: 10->5 (left), 10->11 (right), 5->3 (left), 5->8 (right), 11->13 (right).
- (A)
3 8 5 13 11 10
- (B)
3 5 8 10 11 13
- (C)
3 8 16 13 24 50
- (D)
3 16 8 50 24 13