i/p : inorder and postorder for BST are given
o/p : unique BST
Algorithm : postorder basically tells us the Root and inorder basically tells us right and left part of root.
Scan postorder from right to left. first element from left would be ROOT of tree and then search this node value in inorder , after getting item , left part of that item would be left subtree elements of ROOT and right part of that node will be right subtree elements of ROOT , then for left subtree and right subtree construction again run the same procedure in recursive manner.
If given tree is BT then to search roots , TC would be O(n) linear search.
but if it's BST , inorder is sorted so to search directly apply binary search so complexity=O(logn)
for Postorder for each and every element from left we have to apply same procedure so
TC for BT=O(n2)
TC for BST=O(nlogn)