365 views
2 votes
2 votes
Q.which give unique Binary tree?

1.level order and pre-order

2.level order and post-order

3.level order and in-order

1 Answer

Best answer
0 votes
0 votes

It would be level order and inorder.

To construct a binary tree uniquely inorder is a must along with it either postorder or preorder or level order can be there.

for eg let us take two trees:

Tree1:

root=a;  
root->left=b;  
root->left->right=c;  

Tree2 :

root=a;  
root->right=b;  
root->right->left=c;  

Both the trees have same preorder , postorder and levelorder So they cant be created with the help of this.LEVEL ORDER: a b c

pre-order - a b c  
post-order - c b a  

Preorder, as its name, always visits root first and then left and right sub-trees. That is to say, walking through a pre-order list, each node we hit would be a "root" of a sub-tree.

Post-order, as its name, always visits left and right sub-trees first and then the root. That is to say, walking through a post-order list backward, each node we hit would be a "root" of a sub-tree.

Level oder visits the tree level by level.

In-order, on the other hand, always visits left sub-tree first and then root and then right sub-tree, which means that given a root(which we can obtain from the pre-order or post-order traversal as stated above), in-order traversal tells us the sizes of the left and right sub-trees of a given root and thus we can construct the original tree.(This is the reason why inorder is needed)

Same is the case with level-order traversal. Thus if we want to obtain a unique tree we need an in-order traversal along with any other of the three traversals.
 

selected by

Related questions

0 votes
0 votes
3 answers
1
Roshan Pawar asked Jun 19, 2017
3,109 views
How many elements a simple queue and a circular queue both of size N can accommodates ?( A ) N and N respectively.( B ) N-1 and N-1 respectively.( C ) N and N-1 respec...
0 votes
0 votes
0 answers
3
1 votes
1 votes
1 answer
4
Subbu. asked Jul 18, 2022
475 views
BigO notation ofT(n)=T(n-1)+ √n ; n>=1 =0. ; Otherwise