I am looking for an algorithm to construct a possible top down tree structure when the only input data is path decisions (in random order) for the leaf nodes.
The path decisions is notaded with [nodeID]+ if the leaf node has passed through that node and [nodeID]- if the leaf node has not passed through that node. Example input:
One possible tree structure from the example input above would be:
The output should be a list of nodes and the node respective parent, like this:
As you can see the possible positions for each leaf node is not limited to one, since the input data is not complete paths. Leaf1 in the example can be a child of node D or node I.
There can be any number of leafs you get path data from, but only one single line of path data per leaf. There can be leafs you get no data from at all and you are not aware of how many total leafs there is in the tree. All nodes mentioned in path data should be present in the output table and only the calculated root shouldn’t have any parent assigned.
I guess one must somehow combine the facts from each Leaf paths, like from Leaf1 you know: A and E must not be in parallell lines, and from Leaf2 you know that A and I must not be in parallell lines, and so on ...
Preferable javascript but other language or pseudo code is also welcomed!