# What is a directed acyclic graph (DAG)?

I am reading this link on Wikipedia; it states the following definition is given for a DAG.

Definition: A DAG is a finite, directed graph with no directed cycles.

Reading this definition believes me to think that the digraph below would be a DAG as there are no directed cycles here (there are cycles of the underlying graph but there are no directed cycles).

However, all the pictures on Wikipedia show examples of DAGs with arrows pointing the same way. So, I think I am interpreting this definition wrong. In particular, why does the definition mention later on an equivalent definition is that it must have topological ordering such that "every edge is directed from earlier to later in the sequence"? Reading the definition above would lead me to believe that the graph above is a DAG, but then the equivalent definition would make me think otherwise.

• If you are learning about dags, a useful resource is webgraphviz, which lets you write dags using a simple description language and will then draw them for you in as close to a top-to-bottom ordering as it can manage. – Eric Lippert Feb 26 '19 at 16:07
• @EricLippert Thank you! I will keep that in mind! – W. G. Feb 26 '19 at 20:05
• @EricLippert or yEd. the beautiful thing is that you can ask it to animate between layouts. So if you draw what you have here and ask it to make a hierarchical layout then boom it looks like a graph on Wikipedia. – joojaa Feb 26 '19 at 21:53
• Another newer graph exploration tool is erkal.github.io/kite . Check it out, it's kind of fun. – Ben Feb 26 '19 at 23:23

The graph you show is a DAG.

It is conventional to draw DAGs with all the arrows going in the roughly the same direction, because that usually gives a clearer intuition about what is going on in the graph.

But remember that locations and directions are not part of the formal definition of a graph -- they're just incidental features of the particular drawing at the graph you're looking at, and it would be the same graph if you drew the vertices in different locations on the paper.

(Even in your drawing, all the edges go in a broadly southeasterly direction -- or at least more southeast than northwest -- so you're actually following the convention).

In particular, why does the definition mention later on an equivalent definition is that it must have topological ordering such that "every edge is directed from earlier to later in the sequence"?

Because that is another way to define the same class of graphs, and sometimes (but not always) a more productive way to think about them. You should be able to prove that the finite directed graphs that have no directed cycles are exactly the same as the finite directed graphs that have a topological ordering.

• Another term is "embedding": a graph is an abstract mathematical object of nodes and edges. A drawing on a piece of paper that represents a graph is an embedding of the graph in two-dimensional space. – Acccumulation Feb 26 '19 at 16:48
• Unrelated: Is "graph is a DAG" sufficient and necessary for "graph is topologically sortable"? I suspect so. – Alexander Feb 26 '19 at 19:49
• In the area of (information) visualization, it is not uncommon to refer to a "graph" as the abstract, underlying data structure which does not know anything about positions (of vertices) and lines (for edges). The latter is then more specifically referred to as a Node-Link-Diagram - namely, a visual representation of the abstract data structure. Also see en.wikipedia.org/wiki/Graph_drawing#Graphical_conventions – Marco13 Feb 26 '19 at 21:49
• @Alexander yes it is. In one direction, you cannot topologically sort a directed cycle, obviously. In the other, observe that a DAG has a sink, place that sink last, remove it from the graph, and recurse. – Sasho Nikolov Feb 26 '19 at 22:17
• Yes, but why is it called a "directed acyclic graph", which sounds to me like an acyclic graph which has been given an orientation? Wouldn't it make more sense to call it an "acyclic directed graph"? Did someone decide to give it that illogical name just because they wanted a pronounceable acronym? – bof Feb 27 '19 at 6:57

the given graph is indeed a DAG,

The equivalent definition says that a graph $$(V, E)$$ is a dag if and only if you can find a total order that extends the order given by $$E$$. In simpler terms, let $$u_1, \ldots, u_n$$ be the elements of $$V$$ (the vertices), then $$(V, E)$$ is a dag if and only if you can find an order $$<$$ such that if $$(u_i, u_k)\in E$$ then $$u_i < u_k$$.

Both answers so far state that what you drew is a DAG. However, it is not a DAG by one definition in common use, because it has multiple edges between the two leftmost vertices. It is common to define a directed graph to be a pair $$(V,E)$$ where $$V$$ is a set, called the vertices, and $$E \subseteq V \times V$$ is a set, called the edges (excluding $$(v,v)$$ for all $$v \in V$$). A DAG is then a particular kind of directed graph (having no directed cycles). In particular, since $$E$$ is a set, there is no way to express the fact that there are two edges with the same starting and ending vertices (that would require a multiset). Therefore I would call what you drew a "directed acyclic multigraph". However, the reasoning for why how you draw it does not affect whether it is a DAG, as explained in Henning Makholm's answer, seems to have answered the question that you actually wanted to ask.

• Sortof yes but one can extend the system so that connections have a extra node in between then again a directed multigraph becomes a DAG that fulfills this same restriction. So they are mostly the same thing. – joojaa Feb 27 '19 at 4:52
• not true you can map every pair of vertices to a multiplicity in the naturals. $f:(V×V)\to \mathbb{N}$ – user645636 Mar 6 '19 at 10:40
• @RoddyMacPhee If you want other people to understand what you're writing, write using sentences. There is a reason I wrote "it is common to define a directed graph ...". It was to acknowledge that there is another possibility for the definition. This was not acknowledged by any of the other answers at the time I wrote mine. – Robert Furber Mar 7 '19 at 19:01

You can define things many ways as the Directed acyclic graph at: https://en.m.wikipedia.org/wiki/Magma_(algebra) under types of magma shows. You can define a graph multiple ways, Therefore, any type of graph has multiple definitions. Your drawing is a DAG under a definition of: a graph, whose vertices lack a cycle graph, when following the directed path ordered by direction.