in DS edited by
814 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 $x.$  The function path $(x,10)$ returns non-zero if there exists any path from root to leaf has a path length $10.$ Otherwise returns $0$. Find $B$ and $A$ with recursive call of path?

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

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


which of these two option correct? Please Explain. 

in DS edited by
by
814 views

4 Comments

@Abhishek Kumar 40

Ans given 2)

0
0
it can't be trace out by taking eg
0
0
On less than path length 10 it would still give true if left branch or right branch finishes earlier
0
0

1 Answer

0 votes
0 votes
Option 1 should be right

Related questions

2 votes
2 votes
3 answers
4