binary-tree

Drawing Binary Tree from inorder and preorder


In-order traversal: 24,17,32,18,51,11,26,39,43
Pre-order traversal: 11,32,24,17,51,18,43,26,39

The question asked to find which nodes belong on the right subtree of the root node. I am having trouble constructing the tree based on the 2 traversal methods..

Would greatly appreciate some help on this.


Solution

  • The tree that is defined by those two traversals is:

            __ 11 __
           /        \
       _ 32 _        43
      /      \      /
    24        51  26
      \      /      \
       17  18        39
       
    

    The procedure to build this, is described in this Q&A