1,047 views
1 votes
1 votes
17. The binary search tree contains the values—1, 2, 3, 4, 5, 6, 7 and 8. The tree is traversed in preorder and the values are printed out. Which of the following sequences is a valid output?

(a) 5 3 1 2 4 7 8 6

(b) 5 3 1 2 6 4 8 7

(c) 5 3 2 4 1 6 7 8

(d) 5 3 1 2 4 7 6 8

1 Answer

1 votes
1 votes

From options we can conclude all are starting with node 5.so Root node is 5.

In preorder  visit Root first

                      then Left subtree and Right subtree

Root node is 5 and 2nd node is 3(from options).

 

From above tree preorder traversal is 5,3,1,2,4,7,6,8.

Hence Option D is correct.

Related questions

4 votes
4 votes
2 answers
1
srestha asked Jan 12, 2017
928 views
If preorder of a BST is passed as an argument to the above function. Function returns 1 if,a)All the leaf nodes of the tree are at same levelb) All the nodes of the tree ...
1 votes
1 votes
2 answers
2
rahul sharma 5 asked Oct 6, 2017
815 views
What is the time complexity to delete the root node in right skew tree?I knew the three cases of BST deletion:- 0 child,one child,two child.But how can we handle this par...
2 votes
2 votes
1 answer
3
rahul sharma 5 asked Oct 2, 2017
467 views
What is the worst case time complexity to construct unique BST froma:) Inorder and preordera:) Inorder and postorder
1 votes
1 votes
1 answer
4
s_dr_13 asked Mar 10, 2019
2,690 views
Consider the following binary tree with root at level 0. What is the internal path length for the above tree?31142932