Which of the following traversal is sufficient to construct Binary sea...
To construct BST either preorder or postorder is sufficient because inorder is always sorted for BST.
View all questions of this test
Which of the following traversal is sufficient to construct Binary sea...
Explanation:
To construct a binary search tree, we need at least one of the traversal techniques to be able to reconstruct the tree.
Preorder Traversal:
Preorder traversal visits the root node first, then the left subtree and finally the right subtree. It means that we can get the root node of the tree from the first element of the preorder traversal list.
Inorder Traversal:
Inorder traversal visits the left subtree first, then the root node and finally the right subtree. In a binary search tree, the left subtree contains all the nodes with values less than the root node, and the right subtree contains all the nodes with values greater than the root node. Therefore, we can use the inorder traversal list to determine the left and right subtrees of the root node recursively.
Postorder Traversal:
Postorder traversal visits the left subtree first, then the right subtree and finally the root node. It means that the last element of the postorder traversal list is the root node.
Conclusion:
Preorder and postorder traversal techniques alone are not sufficient to construct a binary search tree since they do not provide enough information about the left and right subtrees. However, using either preorder or postorder traversal in combination with inorder traversal is sufficient to construct a binary search tree. Therefore, option B is the correct answer.