Reputation: 52952
If you have an object that has parents and children both of which are of the same type, and those children have parents and children etc. but the hierarchy can loop back (so the child of an object could be any other object in the entire hierarchy), what is the name of the data structure?
I have seen 'directed graph' but I am not sure if this is applicable or not.
If it makes any difference, the children have metadata stored against them.
Represented as classes in pseudocode, it would look like this:
class myObject {
list of myObject 'Parents'
list of myObjectData 'Children'
}
class myObjectData {
myObject 'Child'
integer 'someMetaData'
}
Upvotes: 0
Views: 154
Reputation: 1148
What you are describing is indeed a directed graph, where nodes can connect to any other node in one direction. Both directions may be achieved if any two nodes both have a connection to the other.
In this case, the idea of Parents and Children can be taken to mean nodes that are being pointed to (Parents), and those that are pointing to this node (Children). In this paradigm, a particular node may have the same child and parent. Eg:
If node n
is pointing to node p
(a Parent), and node p
is pointing to node n
(its Parent), then both nodes would be both Parent and Child to each other.
See https://en.wikipedia.org/wiki/Directed_graph
Upvotes: 1