0

I found this definition of an ancestor and this definition of a descendant. They look meaningful, but unfortunately only for rooted trees.

Also I found an informal definition for DAGs.

However, what I'm interested in is the FORMAL DEFINITION of ancestors and descendants for an undirected graph.

vdshk
  • 1
  • 3

3 Answers3

1

In an undirected graph you do not have ancestors or descendants. Since the edges do not have directions, you can not differentiate between nodes "before" (ancestors) and "after" (descendants) some node.

Let's compare a directed graph with an undirected graph. Here is a DAG (which is a special type of an directed graph)

enter image description here

In this directed graph the edges have a direction. Since it's a DAG, these directions induce an ordering. In other words, the edges allow you to say "some node comes before another node". Like, for example, node B comes after node A, because there is an edge pointing from A to B. Similarly you can say A comes before node D, because B comes before D and A comes before B. That is equivalent to saying A is an ancestor of B and D. Saying it the other way around, D is a descendant of A (and also of B).

Here is the same structure with directions removed, i.e. an undirected graph.

enter image description here

As you can see in this graph the edges do not have a direction. Because there are no directions there is no way of saying "node X comes before node Y". While you could say node A comes before B, you could just as well say node B comes before node A. The edges do not induce an order because they do not have a direction.

As the other answer states, you can define an order in the undirected graph. For example pick some node, for example D, and then walk while assigning directions to the edges you visit. However, that only comes across because you start to assign directions to the edges. That is not in the graph itself.


What you have, however, in an undirected graph are connected components. One connected component contains all the nodes in a graph that are connected by a path. In the undirected graph above (A, B, C, D, E) is one connected component and (F, G) is another.

cherrywoods
  • 1,284
  • 1
  • 7
  • 18
  • Hi @cherrywoods! Why is it impossible to define these concepts on an undirected graph? – vdshk Aug 13 '21 at 06:45
  • I updated the answer, but the problem is pretty fundamental to undirected graphs. In an undirected graph there are no directions, as the name states. Ancestors and descendant s need directions because they need a notion of "before" and "after" to be meaningfully defined. – cherrywoods Aug 13 '21 at 08:48
0
  1. Split the graph into 1 or more connected component.
  2. Select an arbitrary node in each component as the root.
  3. Generate the shortest paths from root to other vertices.
  4. A node's ancestor is the node preceding on the path from the root
  5. A nodes descendants are the vertices that succeed it on their paths from the root.

I cannot imagine anything very useful arising from this concept, but there it is. The problem is the arbitrary choice of the root.

ravenspoint
  • 19,093
  • 6
  • 57
  • 103
0

I found an interesting post that reveals the problem from a different angle.

Quote: "We can think of undirected graphs as being equivalent to directed graphs that have bidirectional edges between nodes. When we trace all ancestors of a node, we are recursively collecting nodes along the path into that node. If we continue recursively collecting nodes in the bidirectional representation of an undirected graph, then we will end up collecting all of the nodes in the connected component of the graph that are connected to the node we are asking for ancestors. The same argument applies to descendants."

With this in mind, we can determine:

  • "ancestors: All nodes that have a path into a node in graph G."
  • "descendants: All nodes that have a path from a node in graph G."
vdshk
  • 1
  • 3
  • Note that here the concept of ancestors and descendants collapses to one concept, the concept of a connected node. The set of ancestors and descendants are always equal with the above definition. – cherrywoods Dec 12 '21 at 13:42