350 views

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 ;


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.

by