algorithmdata-structuresbinary-treeinorderpreorder

Construct a binary tree using inorder and preorder with duplicate values


I was studying this https://www.geeksforgeeks.org/construct-tree-from-given-inorder-and-preorder-traversal/ but could not find a way to construct a binary tree using preorder and inorder with duplicate values because hashmaps and linear search does not work in some cases to find the right index. Please tell if there is an algorithm for this. Any kind of help would be appreciated.


Solution

  • Actually, we can't create a tree from inorder and preorder or inorder and postorder if the tree contains duplicate values.