Finding a unique tree for given in order and postorder traversals

194 Views Asked by At

I just encountered a problem to find a tree for given inorder and postorder traversals.Can anybody elaborate the same using an example ?

1

There are 1 best solutions below

0
On

For example, if you have $42513$ and $45231$

You would first realize $1$ is the root, and you have subtrees $425$ and $3$

Now you have reduced to problem to $425$ and $452$, you would realize $2$ is the root and $4,5$ are the children.

So the tree would look like

1---2---4
|   |
|   5
3