edited by
538 views
0 votes
0 votes

Assume that we have a ternary tree in which each node can have at most $3$ children, namely left, middle and right. Consider the following function to calculate total number of nodes with exactly $3$ children.

int func Node *L
{
int i;
if L==NULL return 0;
i=L --> left &&L ---> middle &&L --> right ?1:0
return _________;
}

Fill in the blank :

  1. i+ func L ->  left+ func L -> middle +func L ->  right ;
  2. i+ func L -> left+ func L -> middle ;
  3. i + func L -> left ;
  4. i ;
    
edited by

1 Answer

0 votes
0 votes

In this program we are counting for number of nodes in the ternary tree. Three condition can occur while counting exactly 3 children,

Cond. 1 : Tree with No child

if L==NULL return 0; //this line check for that.

cond. 2 : Tree with left, right & middle child

i=L --> left &&L ---> middle &&L --> right ?1:0 //this line is supposed to check for that.

cond 3 : Tree with further Left, right and middle sub child/grand child

i+ func L ->  left+ func L -> middle +func L ->  right ; //this line will check for that.

So answer is choice A.

Answer:

Related questions

0 votes
0 votes
1 answer
2
Bikram asked Nov 26, 2016
1,637 views
Three algorithms do the same task. Algorithm One is $O(N)$ and Algorithm Two is $O(\log N)$ and Algorithm Three is $O(N1/2)$. Which algorithm should execute the fastest f...
1 votes
1 votes
3 answers
3
0 votes
0 votes
0 answers
4