I know this question has been addressed in other places but I have a slight twist on it. I want re-construct a binary tree, given the pre-order and inorder traversals. The link below shows good psuedo-code for this problem:
constructing a binary tree from its inorder and preorder traversals - C and C++ - Forums at ProgrammersHeaven.com
and this link shows the algorithm explicitly:
AcmeArticles : Reconstruction of binary trees from traversals
My problem is that these algorithms assume (I think) that all the node values are unique which is not the case in my data. I have duplicate node values. I was wondering if it is still possible to re-construct the tree?
If not, in my data I do know which nodes are terminal nodes (they all have the data value: -99). In this case I assume I should be able to reconstruct the tree with just pre-order - I know I can do it by hand.
I'm not a programmer (I'm a statistician who uses C), so I'm getting a bit lost in all of the recursion. I was wondering if anyone could assist.
Thank you,
Ben