Abidullah Khan
Abidullah Khan

Reputation: 31

In a tree, can a child have multiple parents?

I am developing an application that contains multiple features and each feature has multiple functions. I represented this as a tree but some functions use other functions which means a child can have more than one parent (if I am not wrong). How it is possible in a tree data structure? Can I access the child node from another parent's child node? If so how can I implement this? Can graphs help me with this issue?

Upvotes: 3

Views: 4347

Answers (2)

Mureinik
Mureinik

Reputation: 311518

If a node has more than two parents, your data structure is no longer a tree. E.g., to quote the wikipedia entry:

A node has at most one parent, but possibly many ancestor nodes, such as the parent's parent.

If you need a data structure where a child can have multiple parents, you should look into a (directed) graph.

Upvotes: 3

user158881
user158881

Reputation: 133

a google search gives the answer that:

"Yes, you can have nodes have both “children” and “parents”. However that is no longer a tree structured graph, so you will not be able to use a TreeModel"

Original reference

Upvotes: 0

Related Questions