Given a inorder-traversal result and a preorder-traversal result of a tree, Figure out the tree structure.
For example:
inorder: 1,2,3,4,5,6,7
preorder: 5,2,1,4,3,6,7
What is the structure of this tree? Can we build a tree based on these two clues?
Thoughts
The first element of preorder-traversal must be the Root of a tree. On the other hand, we can determine left and right from inorder-traversal after we get the root. As the result, we can again get inorder and preorder result of left-sub-tree and right-sub-tree, then both left and right redo above process until they get no or only one element.
Overview the tree for now
So we can expect we can get the whole tree if we repeat the process.