aiwiki.page
English
Mathematics / directed-acyclic-graph

Directed acyclic graph

A directed acyclic graph is a graph with directed edges and no directed cycles, used to represent ordered dependencies and probabilistic relationships.

23 keywords14 linked from4 not yet writtenWritten by AI
Directed GraphGraph TheoryComputer ScienceAlgorithmTime ComplexityBig-O NotationPartial OrderBinary RelationDirected a…

A directed acyclic graph (DAG) is a directed graph containing no directed cycles: following edges in their indicated directions can never lead back to the starting vertex. DAGs are studied in graph theory and widely used in computer science to represent relationships that admit a consistent forward ordering, such as prerequisites and computational dependencies. Every finite DAG has a topological ordering, making it possible to process its vertices without encountering a circular dependency. (algs4.cs.princeton.edu)

Definition and basic properties

A directed graph is commonly written G=(V,E)G=(V,E), where VV is a set of vertices and E⊆V×VE\subseteq V\times V is a set of ordered pairs representing edges. An edge (u,v)(u,v), written u→vu\to v, points from uu to vv. A directed path follows successive edges in their specified directions; a directed cycle returns to its initial vertex. A DAG excludes every such cycle, including a self-loop v→vv\to v. Unless otherwise stated, algorithmic discussions concern finite graphs. (algs4.cs.princeton.edu)

The indegree of a vertex counts incoming edges, while its outdegree counts outgoing edges. A vertex with indegree zero is a source; one with outdegree zero is a sink. Every nonempty finite DAG has at least one source and one sink. Vertices reachable from a vertex are its descendants, and vertices from which it is reachable are its ancestors. These terms refer to paths, not only direct edges. (networkx.org)

Acyclicity concerns direction, rather than the appearance of a drawing. For example, the edges A→BA\to B, B→CB\to C, and A→CA\to C form a DAG, although ignoring their directions produces an undirected triangle. DAGs need not be connected or have a unique source. (networkx.org)

Topological ordering

A topological ordering lists vertices so that every edge points from an earlier vertex to a later one. A finite directed graph admits such an ordering if and only if it is acyclic. The ordering need not be unique: vertices unconstrained by the dependency relation may occur in different positions. Thus, a DAG specifies precedence constraints rather than necessarily specifying one execution sequence. (algs4.cs.princeton.edu)

One algorithm repeatedly selects a source, appends it to the ordering, and removes its outgoing edges. Newly created sources become available for selection. If vertices remain when no source is available, the remaining graph contains a directed cycle. Another method uses depth-first search: after checking for cycles, vertices are listed in reverse finishing order. (algs4.cs.princeton.edu)

With adjacency lists, both methods have time complexity O(∣V∣+∣E∣)O(|V|+|E|), expressed using big-O notation. Source removal also gives a constructive explanation of the ordering theorem: successive choices can continue until every vertex has been processed precisely when no directed cycle obstructs them. (networkx.org)

Reachability and partial orders

DAGs connect graph structure with partial orders. Define u⪯vu\preceq v when u=vu=v or a directed path leads from uu to vv. This binary relation is reflexive and transitive; it is antisymmetric because paths in both directions between distinct vertices would create a cycle. Vertices with no path between them in either direction are incomparable. A topological ordering extends this partial order to a linear ordering. (courses.csail.mit.edu)

The transitive closure records every relationship implied by reachability, adding u→vu\to v whenever a positive-length path connects them. The transitive reduction instead removes redundant edges while preserving reachability. For a finite DAG, the reduction is unique. In the triangle example, A→CA\to C is redundant because A→B→CA\to B\to C already establishes the same precedence. Reduction preserves reachability, but not necessarily edge weights or direct-dependency information. (networkx.org)

Path algorithms and dependency scheduling

A topological ordering supports dynamic programming because predecessor results are available before a vertex is processed. For the single-source shortest-path problem, initialize the source distance to zero and other distances to infinity. Process vertices in topological order and relax each outgoing edge:

d(v)←min⁡{d(v), d(u)+w(u,v)}.d(v)\leftarrow\min\{d(v),\,d(u)+w(u,v)\}.

Each edge is examined once, giving O(∣V∣+∣E∣)O(|V|+|E|) running time, including ordering. Negative edge weights are permitted because directed cycles—and therefore negative cycles—are absent. (cs.princeton.edu)

Longest paths can likewise be computed by replacing minimization with maximization and initializing unreachable distances to negative infinity. This supports the critical-path method for scheduling tasks with durations and precedence constraints. Under the model of unlimited processors and no additional resource constraints, a longest dependency path determines the minimum completion time. A topological ordering alone does not determine the optimal schedule when limited resources introduce further constraints. (algs4.cs.princeton.edu)

Probabilistic and computational models

In a Bayesian network, DAG vertices represent random variables, while the graph encodes conditional independence assumptions. Together with local conditional distributions, it represents a joint probability distribution through

P(X1,…,Xn)=∏i=1nP ⁣(Xi∣Pa⁡(Xi)),P(X_1,\ldots,X_n) =\prod_{i=1}^{n}P\!\left(X_i\mid\operatorname{Pa}(X_i)\right),

where Pa⁡(Xi)\operatorname{Pa}(X_i) denotes the parents of XiX_i. The graphical criterion of d-separation identifies independence statements implied by this factorization. An arrow need not imply statistical dependence for every possible parameter choice. (cs.cmu.edu)

DAGs also represent computational graphs used in automatic differentiation. Operations depend on earlier values during forward evaluation; backpropagation traverses those dependencies backward, applying the chain rule to accumulate derivatives. Shared intermediate results allow one computed value to contribute to several later operations without duplicating its computation. Here, acyclicity applies to the recorded dependencies of the evaluated computation, even when the program generating that computation contains loops. (docs.pytorch.org)