2,016 views
0 votes
0 votes

someone please explain this question 

A binary search tree contains the values 1, 2, 3, 4, 5, 6, 7, 8. The tree is traversed in pre-order and the values are printed out. Which of the following sequences is a valid output?

 

 

how the option D is correct?

A

53124786

B

53126487

C

53241678

D 53124768

2 Answers

Best answer
0 votes
0 votes
  • We know the inorder of BST is sorted. So inorder is 1,2,3,4,5,6,7,8 

  • And preorder is given in option . With the help of inorder and preorder we construct a unique tree .

  • After constructing tree check it preorder is right or not .

  •  

 

edited by
1 votes
1 votes

D is coorect  preorder traversal as you are given bst the inorder will be sorted i.e it will be 1,2,3,4,5,6,7,8

now when you take D option than tree which is traversed for preorder will be 

 

edited by

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
0 answers
3
Vikas123 asked Jan 8, 2019
700 views
Acc. to (question) my solution is...uniquely constructed binary tree PRE+POST and IN+POST…where i am wrong….