The Gateway to Computer Science Excellence
0 votes
47 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 Programming by Veteran (74.8k points)
edited by | 47 views

1 Answer

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.

by Active (1.2k points)
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,385 answers
198,558 comments
105,371 users