in DS edited by
596 views
0 votes
0 votes

Consider the following function with a Binary Tree with atleast one node:
int path (struct node *x, int len)

{

if(x==null) return B;

else return A;

}

 

Assume the above function is used “to check the given binary tree has any path with specified length from root to the leaf node”. Let T be a binary tree with root pointed by  The function path  returns non-zero if there exist any path from root to leaf has a path length of 10.

Otherwise return zero. Find B and A with the recursive calls of path?

a) A is path(x -->left, len-1) || path(x--> right, len-1), B is (len=0)

b) A is path(x -->left, len-1) || path(x--> right, len-1), B is (len=-1)

c) A is path(x -->left, len-1) || path(x--> right, len-1), B is (len=1)

d) A is path(x -->left, len) || path(x--> right, len), B is (len=1)

in DS edited by
596 views

4 Comments

@shaik
how you wrote B in that form options did not have..? how man how..??
0
0

@  Shubham Shukla 6

how you wrote B in that form options did not have..? how man how..??

 

options are not matching, then i analyses, what should be B for required procedure.


Sambhrant Maurya

Why len==-1?

 path means no.of edges, therefore no.of vertices is exactly one more than no.of edges

it implies when you are last node your variable len=0, therefore when you are at null ( last node -> next ) , your variable should be -1

0
0

options are not matching, then i analyses, what should be B for required procedure

exactly i was stuck too..:( 

0
0

Please log in or register to answer this question.

Related questions