title: Binary Tree from inorder and postorder
body: <p>I have just started studying Binary Tree. Is there an algorithm to find out the binary tree structure,given the Inorder and Postorder OR Inorder and Preorder? I have been trying to do it manually,but it never comes out correct.For eg.-These two are valid Inorder and Postorder traversal of a given tree:</p>
  
  <p>Inorder:    D B F E A G C L J H K
  Postorder : D F E B G L J K H C A</p>
  
  <p>Clearly A is the root as it is the last element in Postorder. Now looking in Inorder,the left subtree becomes: {D B F E} and right subtree becomes: {G C L J H K}. The root of right subtree would be the second last element in preorder i.e C. I can now further divide the right subtree(with C as root), giving {G} as right subtree and {L J H K} as left. Therefore I have this structure:</p>
  
  <pre><code>                               A
                                  \
                                   C
                                  /  
                                 G
  </code></pre>
  
  <p>But,whatever algorithm I apply,next seems to work differently for different trees . Someone please explain.</p>