Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A DAG is a directed acyclic graph: a set of nodes joined by arrows, with no path that follows the arrows and returns to its starting node. Because it has no directed cycles, its nodes can be arranged in an order that respects every arrow. That makes DAGs useful for representing dependencies, such as tasks that must be completed before other tasks begin.

What “directed” and “acyclic” mean

A graph consists of nodes (also called vertices) and edges connecting them. In a directed graph, each edge has an orientation, shown as an arrow. “Acyclic” means that following the arrows cannot bring you back to the node where you started. NIST defines a DAG as “a directed graph with no path that starts and ends at the same vertex.” NIST’s definition of a DAG

For example, if the nodes are tasks and an arrow means “must finish before,” then A → C says task A must finish before task C. The meaning of an arrow depends on the model: a DAG describes relationships, but does not by itself prove that one event causes another.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How a topological order works

A topological order is a sequence of the graph’s nodes in which each node comes before every node it points to. Formally, for every edge (u, v), u must appear before v. A DAG always has at least one such ordering. LEDA’s guide to topological sorting

For a dependency graph, read a topological order as one valid way to arrange the work so prerequisites come first. It is an ordering that obeys the arrows, not necessarily the only possible schedule.

Example: tasks with shared prerequisites

Suppose tasks A and B must both be completed before C, represented by A → C and B → C. A and B may be done in either order because neither points to the other. Both of these orders respect the dependencies:

  • A, B, C
  • B, A, C

If the graph also includes C → D, then D must come after C. DAGs are used to model these kinds of dependency relationships, and topological sorting can produce an order that respects them. Neo4j’s DAG algorithms overview

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why a cycle matters

A directed cycle makes a complete topological order impossible: each node in the cycle would have to appear before the next, while the final arrow would require the sequence to return to an earlier node. In a task model, that usually means the stated prerequisites conflict—for instance, one task depends on another that ultimately depends back on the first.

Some software may return only part of an ordering when cycles are present. Neo4j documents that its topological-sort result omits nodes in cycles and nodes that depend on those cycles, so a partial result should not be treated as a complete schedule. Neo4j’s topological-sort documentation

What to remember

  • DAG means directed acyclic graph: arrows have direction, and no directed path loops back to its starting node.
  • Every DAG has at least one topological order, in which each arrow points from an earlier node to a later one.
  • Independent nodes can appear in different orders, so valid topological orders are not always unique. NetworkX’s DAG reference includes a generator for topological sorts. NetworkX DAG reference
  • A directed cycle prevents a complete topological ordering and can reveal contradictory dependencies.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.