Suppose we have a set of binary trees with their inorder and preorder traversals given and where no tree is a subtree of another tree in the given set. Now another binary tree Q is given.
Find whether it can be formed by joining the binary trees from the given set(while joining each tree in the set should be considered atmost once). In this case a joining operation means: Pick the root of any tree in the set and hook it to any vertex of another tree such that the resulting tree is also a binary tree.
Can we do this using LCA (least common ancestor)? Or does it needs any special datastructure to solve?