Robert M. Keller
Robert M. Keller
Robert M. Keller
by Robert M. Keller
A graph that has at least one such loop is called cyclic, and one
which doesn't is called acyclic. Acylic directed graphs are
also called dags.
An acylic graph:
A similar-appearing cylic graph:
Idea:
For example, in
node 3 is such a node. There in general may be other nodes,
but in this case it is the only one.
3. Choose a leaf of the graph. Remove this leaf and all arcs
going into the leaf to get a new graph.
4. Go to 1.
[ [1, 2], [2, 3], [2, 4], [4, 5], [6, 3], [4, 6], [5, 6] ]
First we have to find whether there is a leaf. By definition, a
leaf is a node with no arcs leaving it.
is_leaf(Node, Graph) =
Here Graph is our list of arcs. If the call to no returns 1 if, and
only if, there is no arc with Node as its first element.
We can test whether any of these is a leaf, and if so, return the
identity of the leaf, by:
find_leaf(Graph) =
no_leaf(Graph) = find_leaf(Graph) == [ ];
Example:
[ [1, 2], [2, 3], [2, 4], [4, 5], [6, 3], [4, 6], [5, 6] ]
nodes(Graph) =
remove_duplicates(leaves(Graph));
Caution: The "leaves" of this tree aren't only the leaf nodes of
the original graph; they include all the nodes, as desired.
3. Choose a leaf of Graph. Remove this leaf and all arcs going
into the leaf to get a new graph.
4. Go to 1.
remove_leaf(Leaf, Graph) =
As usual,
remove_leaf(Graph) =
remove_leaf(first(find_leaf(Graph)), Graph);
The form
P?T:F
acyclic(Graph) =
rex acyclic.rex
Once the file is loaded, you may try any of the examples
individually. The two graphs used as examples here are
examples graph1 and graph2 in the file.
DAGs may be used to model several different kinds of structure in mathematics and
computer science. The reachability relation in a DAG forms a partial order, and any finite
partial order may be represented by a DAG using reachability. DAGs may be used to
model processes in which information flows in a consistent direction through a network
of processors. Additionally, DAGs may be used as a space-efficient representation of a
collection of sequences with overlapping subsequences.
The corresponding concept for undirected graphs is a forest, an undirected graph without
cycles. Choosing an orientation for a forest produces a special kind of directed acyclic
graph called a polytree. However there are many other kinds of directed acyclic graph
that are not formed by orienting the edges of an undirected acyclic graph. For this reason
it may be more accurate to call directed acyclic graphs acyclic directed graphs or
acyclic digraphs.
A Hasse diagram representing the partial order ⊆ among the subsets of a three-element
set.
Each directed acyclic graph gives rise to a partial order ≤ on its vertices, where u ≤ v
exactly when there exists a directed path from u to v in the DAG. However, many
different DAGs may give rise to this same reachability relation: for example, the DAG
with two edges a → b and b → c has the same reachability as the graph with three edges
a → b, b → c, and a → c. If G is a DAG, its transitive reduction is the graph with the
fewest edges that represents the same reachability as G, and its transitive closure is the
graph with the most edges that represents the same reachability.
The transitive closure of G has an edge u → v for every related pair u ≤ v of distinct
elements in the reachability relation of G, and may therefore be thought of as a direct
translation of the reachability relation ≤ into graph-theoretic terms: every partially
ordered set may be translated into a DAG in this way. If a DAG G represents a partial
order ≤, then the transitive reduction of G is a subgraph of G with an edge u → v for
every pair in the covering relation of ≤; transitive reductions are useful in visualizing the
partial orders they represent, because that have fewer edges than other graphs
representing the same orders and therefore lead to simpler graph drawings. A Hasse
diagram of a partial order is a drawing of the transitive reduction in which the orientation
of each edge is shown by placing the starting vertex of the edge in a lower position than
its ending vertex.
Every directed acyclic graph has a topological ordering, an ordering of the vertices such
that the starting endpoint of every edge occurs earlier in the ordering than the ending
endpoint of the edge. In general, this ordering is not unique; a DAG has a unique
topological ordering if and only if it has a directed path containing all the vertices, in
which case the ordering is the same as the order in which the vertices appear in the path.
The family of topological orderings of a DAG is the same as the family of linear
extensions of the reachability relation for the DAG, so any two graphs representing the
same partial order have the same set of topological orders. Topological sorting is the
algorithmic problem of finding topological orderings; it can be solved in linear time. It is
also possible to check whether a given directed graph is a DAG in linear time, by
attempting to find a topological ordering and then testing whether the resulting ordering
is valid.
Some algorithms become simpler when used on DAGs instead of general graphs, based
on the principle of topological ordering. For example, it is possible to find shortest paths
and longest paths from a given starting vertex in DAGs in linear time by processing the
vertices in a topological order, and calculating the path length for each vertex to be the
minimum or maximum length obtained via any of its incoming edges. In contrast, for
arbitrary graphs the shortest path may require slower algorithms such as Dijkstra's
algorithm or the Bellman-Ford algorithm, and longest paths in arbitrary graphs are NP-
hard to find.
The same idea of using a DAG to represent a family of paths occurs in the binary
decision diagram,[4][5] a DAG-based data structure for representing binary functions. In a
binary decision diagram, each non-sink vertex is labeled by the name of a binary variable,
and each sink and each edge is labeled by a 0 or 1. The function value for any truth
assignment to the variables is the value at the sink found by following a path, starting
from the single source vertex, that at each non-sink vertex follows the outgoing edge
labeled with the value of that vertex's variable. Just as directed acyclic word graphs can
be viewed as a compressed form of tries, binary decision diagrams can be viewed as
compressed forms of decision trees that save space by allowing paths to rejoin when they
agree on the results of all remaining decisions.
Any undirected graph may be made into a DAG by choosing a total order for its vertices
and orienting every edge from the earlier endpoint in the order to the later endpoint.
However, different total orders may lead to the same acyclic orientation. The number of
acyclic orientations is equal to |χ(-1)|, where χ is the chromatic polynomial of the given
graph.[6]
Any directed graph may be made into a DAG by removing a feedback vertex set or a
feedback arc set. However, the smallest such set is NP-hard to find. An arbitrary directed
graph may also be transformed into a DAG, called its condensation, by contracting each
of its strongly connected components into a single supervertex.[7] When the graph is
already acyclic, its smallest feedback vertex sets and feedback arc sets are empty, and its
condensation is the graph itself.
Enumeration
The graph enumeration problem of counting directed acyclic graphs was studied by
Robinson (1973).[8] The number of DAGs on n labeled nodes, for n = 1, 2, 3, ..., is
[8]
Eric W. Weisstein conjectured,[9] and McKay et al. (2004) proved,[10] that the same
numbers count the (0,1) matrices in which all eigenvalues are positive real numbers. The
proof is bijective: a matrix A is an adjacency matrix of a DAG if and only if the
eigenvalues of the (0,1) matrix A + I are positive, where I denotes the identity matrix