232 views
2 votes
2 votes

Consider the following representation of a ternary tree where $A: B,C,D$ denote that $B,C$ and $D$ are the child nodes of $A.$

  • $1:2,3,4$
  • $2:5,6$
  • $3:7$
  • $4:8,9,10$

If the root of the above tree is passed to the following C function (assume the the child nodes are represented by child1, child2 and child3 and all NULL values are assigned properly), the return value will be _____

int foo(struct node *root)
{
    if(!root) return 0;
    return 1 + foo(root->child1) +
        foo(root->child2) +
        foo(root->child3);
}

1 Answer

Best answer
3 votes
3 votes
The function is counting the number of elements in the ternary tree and so the return value will be $10.$
selected by
Answer:

Related questions

7 votes
7 votes
1 answer
1
gatecse asked Aug 9, 2020
686 views
Two balanced binary search trees are given with $m$ and $n$ elements respectively. They can be merged into another balanced binary search tree in $\Theta((m+n)^a {(\log (...
3 votes
3 votes
1 answer
2
gatecse asked Aug 9, 2020
408 views
The maximum number of leaf nodes in a tree with degree $5$ and height (starting from $1)\;4$ is __________
1 votes
1 votes
1 answer
3
gatecse asked Aug 9, 2020
185 views
What is the value of the postfix expression $8 \ 7 \ 2 \ 4 \ + \ – \ *?$: