3

Can there be multiple parents and/or multiple roots for a DAG?

f0331
  • 31
  • 1
  • 2

2 Answers2

2

Nothing in a DAG prevents a node from having more than one parent. Similarly, nothing prevents a DAG from having multiple roots. Thus, yes, you can have these two features in a DAG.

1

A DAG is a graph that flows in one direction, where no element can be a child of itself. You can still have multiple children and multiple parents for a single node of the graph.

enter image description here

A graph is formed by a collection of vertices and edges, where the vertices are structureless objects that are connected in pairs by edges. In the case of a directed graph, each edge has an orientation, from one vertex to another vertex. A path in a directed graph can be described by a sequence of edges having the property that the ending vertex of each edge in the sequence is the same as the starting vertex of the next edge in the sequence; a path forms a cycle if the starting vertex of its first edge equals the ending vertex of its last edge. A directed acyclic graph is a directed graph that has no cycles.

Source: Wikipedia

At the very minimum, a directed acyclic graph must have:

  • Nodes: A place to store the data.
  • Directed Edges: Arrows that point in one direction (the thing that makes this data structure different)
  • Some great ancestral node with no parents. (Fun fact: Most ancestry trees are actually DAGs and not actually trees because cousins at some point get married to each other.)
  • Leaves: Nodes with no children
sentenza
  • 1,608
  • 3
  • 29
  • 51