Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a binary search tree be constructed from only the inorder traversal?

Wanted to check if there is a way to construct a binary search tree from only the inorder traversal which will be in sorted order. I am thinking there might be some way we can do it recursively, but not able to figure it out. Any pointers would be appreciated.

like image 651
user496934 Avatar asked Oct 21 '25 08:10

user496934


1 Answers

A BST has exactly one in-order traversal, but more than one BST can be constructed with a given in-order traversal. Hence, Yes, it is possible to construct a BST with a given in-order traversal, but you may not end up with the same tree whose in-order traversal you've started with.

Check this article for more info: https://www.geeksforgeeks.org/find-all-possible-trees-with-given-inorder-traversal/

like image 121
shine Avatar answered Oct 24 '25 16:10

shine