1

I want to create a tree in Fortran (90) like the one in this picture:

Intersecting Tree

The idea is that I would then be able to follow a path through the tree starting from the root in the following way. At each node perform a check with the value stored there: passing the check move to the left-most child, not passing or having reached a leaf-node move the highest node that the traversal hasn't been to yet. Here is an example of a possible traversal (green indicating passing the test and red not passing):

Traversal Example

Importantly, not every node is reached (the ones in black) which is the point of the procedure actually.

So, I think I need is a subroutine that would insert nodes in the tree, in order to build it and another that would allow me to follow paths of the kind described above.

My question is, is this possible? Does this data structure have a name?

Granted that I have virtually no experience with building data structures of this kind, Google has not been much help. An example code would be great but I would be happy to just be referred to some reading where I could learn this.

mzp
  • 181
  • 9
  • Never heard of this, but google suggests things like https://stackoverflow.com/questions/11554450/a-tree-where-each-node-could-have-multiple-parents http://discuss.joelonsoftware.com/default.asp?design.4.335549.10 It is probably just a kind of oriented graph that looks like a kind of a tree but is more general than that. I thing the intersections are not important, they are just an artefact of the visualization. The important point is that several nodes have multiple parents. – Vladimir F Героям слава Jun 05 '18 at 09:08
  • As Vladimir F notes, what you have isn't a tree, but a (potentially directed) graph. – francescalus Jun 05 '18 at 09:17
  • Thank you both, this is already very helpful. Having looked at the definitions what I want to build is indeed a directed graph. – mzp Jun 05 '18 at 09:37
  • 1
    I solved the problem using an adjacent list ([this is a good video explaining it](https://youtu.be/k1wraWzqtvQ)) – mzp Jun 05 '18 at 20:20

0 Answers0