Directed Graphs and Digraphs
Consider a network of one-way streets in a city grid. Even if every intersection is reachable from every other by some undirected path, that doesn't mean you can drive legally between them. One-way restrictions matter. This simple observation is the seed of an entire theory. When edges carry direction, connectivity splits into several genuinely different notions. The combinatorics of "who can reach whom" becomes far richer than in the undirected setting. Directed graphs, or digraphs, model any relationship that is not symmetric. Examples include task dependencies, web links, predator-prey relations, citation networks, precedence constraints in scheduling, and the flow of current through a circuit. Because the relation "there is an edge from to " need not imply "there is an edge from to ," digraphs support phenomena with no undirected analogue. Most important is the possibility of having no directed cycles at all. This gives rise to directed acyclic graphs (DAGs) and the notion of a topological order. The big picture of this article is that digraph theory develops in exact parallel to undirected graph theory. It replaces single notions with directional pairs. Degree splits into in-degree and out-degree. Connectivity splits into weak and strong connectivity. Components split into weakly and strongly connected components. Each of these directional refinements is a genuine strengthening. Strong connectivity is a strictly stronger condition than weak connectivity. The failure of one to imply the other is exactly what makes digraph theory interesting, rather than a trivial relabeling. This article builds the formal machinery from scratch. It covers the definition of a digraph, in-degree/out-degree, and the directed handshake lemma. It also covers strong connectivity and strongly connected components. It further covers directed acyclic graphs together with the topological sort theorem. Along the way it sets up the vocabulary needed later. This includes reachability, condensation, and strong components. These concepts support Network Flows and Max-Flow Min-Cut and the deeper structural results of Menger's Theorem.
- A digraph has edges that are ordered pairs , so direction matters and in general.
- Every vertex has two separate degree counts: in-degree and out-degree ; both sum to .
- Weak connectivity (connected after forgetting direction) is strictly weaker than strong connectivity (a directed path both ways between every pair).
- The strongly connected components of any digraph partition its vertices, and contracting each to a point yields a condensation that is always a DAG.
- A digraph is a DAG if and only if it admits a topological ordering — a linear order in which every edge points forward.
- Key idea: direction turns one connectivity question into several inequivalent ones, and the acyclic case (DAGs) is exactly the case where a total order compatible with all edges exists.
Where this lives today
Digraphs are the natural model whenever a relationship is asymmetric or has an inherent order. In computer science, task-scheduling systems (build tools like Make, CI/CD pipelines, spreadsheet recalculation engines) represent dependencies as a DAG and use a topological sort to decide a valid execution order — the theorem proved above is literally the correctness argument for these schedulers. Compilers use DAGs for common-subexpression elimination and instruction scheduling. In the web and citation networks, hyperlinks and citations are directed; strongly connected components of the web graph identify tightly interlinked clusters of mutually-referencing pages, and this SCC structure underlies early analyses of "bow-tie" web topology. In biology, gene regulatory networks and metabolic pathways are frequently modeled as digraphs, with feedback loops corresponding to directed cycles and one-way regulatory cascades corresponding to DAG substructures. In operations research and project management, PERT/CPM charts are DAGs whose topological order gives a feasible task sequence, and the longest path in the DAG (critical path) determines minimum project completion time. In cryptography and blockchain, hash-linked structures (e.g., some DAG-based distributed ledgers, as an alternative to strictly linear blockchains) rely on acyclicity to guarantee a consistent causal ordering of transactions. In probability and statistics, Bayesian networks are DAGs encoding conditional independence structure, and the acyclicity theorem underlies the existence of a valid factorization of the joint distribution along a topological order of the variables. Finally, digraph connectivity concepts feed directly into Network Flows and Max-Flow Min-Cut, where directed edge capacities model transportation and communication networks, and into Menger's Theorem, which quantifies strong connectivity in terms of vertex- and edge-disjoint directed paths.
Ask the tutor: How does the source-removal algorithm for topological sorting change if the digraph is allowed to have parallel edges or self-loops?
A directed graph (or digraph) is a pair where is a finite set of vertices and is a set of directed edges (or arcs), each written as an ordered pair with . For an edge , we call the tail and the head; we say goes from to , and that is an out-neighbor of while is an in-neighbor of . Unless stated otherwise, we forbid loops ( pairs are allowed to be excluded by convention; we exclude them here) and treat as a set, so no parallel edges (repeated identical ordered pairs) occur. A digraph satisfying these two restrictions is called a simple digraph; this is the default object of study here. The in-degree is the number of edges with head ; the out-degree is the number of edges with tail . A directed walk from to is a sequence with for each . A directed path is a directed walk with all distinct. A directed cycle is a directed walk with , , and distinct. The underlying (undirected) graph of , denoted , has the same vertex set and an undirected edge whenever or . is weakly connected if is connected. is strongly connected if for every ordered pair there is a directed path from to . A directed acyclic graph (DAG) is a digraph containing no directed cycle.
Intuition
Picture a city where every street is one-way. The underlying map (ignoring arrows) might be a single connected grid, so you can always get from any corner to any other if you're allowed to walk against traffic. But driving legally is a different question: strong connectivity asks whether, respecting every arrow, you can still drive from any corner to any other and back. A single one-way street sealing off a neighborhood's only exit can keep the map weakly connected while destroying strong connectivity entirely. This distinction is the heart of the subject. In-degree and out-degree separately track how much traffic converges on and diverges from an intersection; a source vertex () is an on-ramp with no way in, a sink () is a dead end. When a digraph has no directed cycles at all — a DAG — its vertices can be arranged left to right on a line so every arrow points rightward, exactly like a valid schedule of tasks respecting prerequisites.
Let be a digraph. Then
(Double counting.) Consider the set of pairs
We count two ways. First, group by vertex : for fixed , the number of edges with tail is by definition . Since every edge has exactly one tail, each edge contributes to exactly once, paired with its unique tail. Summing over all vertices,
Second, group by edge : for each , there is exactly one vertex (its tail) with , so each edge contributes exactly one pair. Hence
Combining the two counts gives . The identical argument applied to heads instead of tails (using , the number of edges with head ) gives .
∎Let be a digraph. Define a relation on by if and only if there is a directed path from to and a directed path from to (with the convention that every vertex has a trivial length-0 path to itself). Then is an equivalence relation on , and its equivalence classes — the strongly connected components (SCCs) of — partition . Moreover, if (the condensation of ) is the digraph whose vertices are the SCCs of , with an edge from SCC to SCC () whenever some edge of goes from a vertex in to a vertex in , then is a directed acyclic graph.
Equivalence relation. We check the three properties directly. Reflexive: for any , the length-0 walk from to is a directed path (vacuously, with no edges), so . Symmetric: if , then by definition there is a directed path from to and one from to ; this is a symmetric statement in , so . Transitive: suppose and . Then there are directed paths , , , . Concatenating the walk followed by gives a directed walk from to (walks may repeat vertices, so concatenation of two walks is always a walk); every directed walk from to contains a directed path from to as a subsequence (delete a chord: if a vertex repeats in the walk, excise the loop between the repetitions and repeat until all vertices are distinct — this terminates since the walk is finite and each excision strictly shortens it). Hence a directed path exists. Symmetrically, concatenating then gives a directed walk from to , and hence a directed path . Thus . Since is an equivalence relation on the finite set , its equivalence classes partition (this is the standard fact that equivalence classes of an equivalence relation partition the underlying set — every element lies in its own class, and two classes are either equal or disjoint by transitivity and symmetry).
Condensation is acyclic. Suppose toward a contradiction that contains a directed cycle
where are distinct SCCs of (distinct because a directed cycle in , as a digraph, is defined to have distinct vertices among ). By definition of the condensation's edges, for each there exist vertices , with . Also, since is a single SCC, any two of its vertices are -equivalent, so there is a directed path inside from to any other chosen vertex of , in particular to (the vertex we use to leave next). Chaining these edges and paths together over produces a directed walk in starting and ending in , and passing through at least one vertex of every . If , this walk visits a vertex of (say or the return point in ) and later a vertex of , and eventually returns to : extracting the sub-walk from a vertex back to a vertex that passes through gives directed walks and, by reflexivity/symmetry within 's own internal connectivity (a directed path from back to exists since are -equivalent), a directed walk . But we also get, by the same chaining restricted to just two indices, directed walks from a representative of to a representative of and — going the rest of the way around the cycle — back from that representative of to the representative of . Converting each directed walk to a directed path as in the transitivity argument above, this shows in the vertex sense, i.e., the representative vertices are mutually reachable, forcing and to be the same SCC. This contradicts . (The case , a self-loop in , is excluded by definition since condensation edges are only drawn between distinct SCCs.) Either way we reach a contradiction, so has no directed cycle: it is a DAG.
∎Let be a digraph with . Then is a directed acyclic graph if and only if there exists a bijection (topological order) such that for every edge , .
We prove both directions.
() If a topological order exists, is acyclic. Suppose for contradiction has a directed cycle with and distinct. Since are all edges, applying the defining property of repeatedly gives
But is also an edge, so . Combining, , a contradiction (strict inequality cannot hold with itself). Hence no directed cycle exists, and is acyclic.
() If is acyclic, a topological order exists. We argue by strong induction on . Base case : the empty bijection trivially satisfies the (vacuous) condition. Inductive step: Assume every acyclic digraph on fewer than vertices has a topological order, and let be acyclic with . Claim: has a vertex with (a source). Proof of claim: Suppose not — every vertex has in-degree at least . Build a sequence by picking any starting vertex , and having chosen , since there is an edge for some ; continue backward this way to define indefinitely (this is always possible since every vertex has an in-edge). Since is finite, by the pigeonhole principle some vertex repeats among (that is terms drawn from possible vertices): there exist with . The edges then form a directed cycle (after discarding any earlier repeats within this segment to make vertices distinct, which is possible by the same excision argument used above, and the segment is nonempty since ). This contradicts acyclicity of . This proves the claim. Now let be a source of , and let be the digraph obtained by deleting and all edges incident to it. is acyclic: any directed cycle in would also be a directed cycle in (it uses only edges of that were already present), contradicting acyclicity of . Also has vertices. By the inductive hypothesis, has a topological order . Define by and for . This is a bijection onto since is a bijection onto and is used exactly once (by ). Check the ordering condition on every edge :
- If : since has in-degree , 's constraint is irrelevant here we need , i.e. , which holds since (no edge from to , as is simple/loop-free) forces .
- If : then also , because has in-degree so no edge has head . Both means is an edge of too (it survives deletion of ), so by the inductive hypothesis, hence .
In both cases , completing the induction.
∎Worked examples
Example 1 (degree sums and a strong-component computation). Let with and
Degrees. Compute in/out-degree at each vertex directly by scanning :
| 1 | 1 (to 2) | 1 (from 3) |
| 2 | 1 (to 3) | 1 (from 1) |
| 3 | 2 (to 1, to 4) | 1 (from 2) |
| 4 | 1 (to 5) | 2 (from 3, from 5) |
| 5 | 1 (to 4) | 1 (from 4) |
Sum of out-degrees: . Sum of in-degrees: . Both equal , confirming the Directed handshake lemma numerically. Strong components. Vertices form a directed cycle , so any two of them are mutually reachable: is (contained in) one SCC. Vertices satisfy , a 2-cycle, so is (contained in) one SCC. Is there a path from back from ? The only edge leaving would have to originate at or ; but 's only out-edge goes to , and 's only out-edge goes to — both stay inside . So there is no directed path from or back to , even though exists in the other direction. Hence the SCCs are exactly
The condensation has two vertices, and , with a single edge (induced by ) and no edge . This is indeed acyclic, consistent with the theorem.
Example 2 (topological sort via repeated source removal, non-trivial ties). Let have vertices and edges
Check acyclicity informally first: draw out-degrees/in-degrees.
| in-edges | out-edges | |
|---|---|---|
| none | ||
| none | ||
| none |
Step 1. Sources (in-degree ): and . The construction in the theorem's proof only requires finding one source at each stage; there can be several. Pick (the choice is not unique — this is expected, since topological orders need not be unique). Assign . Delete and its edges . Updated in-degrees: : was (from ), now . : was (from ), now (from only). unchanged: still , still , still . Step 2. Sources now: and . Pick . Assign . Delete edge . Now 's in-degree drops from to . Step 3. Sources now: and . Pick . Assign . Delete edge . 's in-degree drops from to (only remains). Step 4. Sources now: only . Assign . Delete edges . 's in-degree drops to ; 's in-degree drops from to (only remains). Step 5. Sources now: only . Assign . Delete edge . 's in-degree drops to . Step 6. Only remains. Assign . Resulting topological order: with exactly this rank. Verify every edge points forward: : ✓. : ✓. : ✓. : ✓. : ✓. : ✓. : ✓. All seven edges point forward, confirming is acyclic and this is a valid topological order — and note that choosing before in Step 1 would have produced a different, equally valid order, illustrating non-uniqueness.
The forward direction of the theorem (existence of topological order acyclic) is unconditional and cannot fail; the content that needs a hypothesis is the converse: acyclicity is necessary for a topological order to exist, and if we instead try to assert "every digraph has a topological order" by dropping the acyclicity hypothesis, it fails immediately. Take , a -cycle. Suppose a topological order existed. From edge we'd need ; from edge we'd need . These cannot both hold for real numbers , so no such exists. Indeed contains the directed cycle , so it is not acyclic — exactly the situation the theorem excludes. This shows the acyclicity hypothesis in the theorem is not a technical nicety but the exact dividing line: any directed cycle, no matter how short, obstructs the existence of a topological order, because traversing the cycle forces a strictly increasing then strictly decreasing chain of labels that returns to its start.
Scope, edge cases & common traps
| Situation | What to watch for |
|---|---|
| Weakly vs. strongly connected | A digraph can be weakly connected with every vertex having in-degree and out-degree , yet still fail to be strongly connected (Example 1's condensation edge persists). |
| Loops and parallel edges | The definitions above assume a simple digraph (no loops, no parallel edges); if loops are allowed, a single loop at is itself a directed cycle and blocks from being a DAG. |
| Uniqueness of topological order | Topological orders are generally not unique (Example 2); uniqueness holds iff the DAG's condensation-free structure is a total order, i.e. every pair of vertices is comparable via a directed path. |
| Condensation vs. original graph | The condensation is always acyclic regardless of whether itself is acyclic; do not confuse " is a DAG" with " is a DAG" — the latter is a theorem true for every digraph. |
| In-degree vertices | A DAG can have more than one source (Example 2 had two: ); it can also have exactly one, or in degenerate cases (single isolated vertex) trivially one. |
The mathematician behind it
Origins · 1 minLeonhard Euler and how this was discovered
Euler's 1736 resolution of the Seven Bridges of Königsberg problem is usually cited as the origin of graph theory, though he worked with undirected multigraphs, not digraphs in the modern sense. The formal study of directed graphs — degree sequences with direction, strong connectivity, and topological ordering — crystallized much later, in the twentieth century, driven by operations research, computer science (scheduling and dependency analysis), and the theory of tournaments and relations, with foundational contributions from Claude Berge, Frank Harary, and others who systematized digraph terminology alongside the classical undirected theory.
Is a digraph just a graph where I remember which way each edge "was drawn"?
Not quite — it's a genuinely different combinatorial object. In an undirected graph, an edge is a single unordered pair, and the graph is fully described once you know which unordered pairs are edges. In a digraph, and are both potentially present, independently of each other, giving up to twice as many possible edges on the same vertex set (before excluding loops). This means digraphs can encode information — like " points to but not vice versa," or mutual edges in both directions — that has no direct undirected analogue, which is exactly why connectivity, degree, and cycle notions all need directional refinements.
Why does strong connectivity require paths in both directions rather than just one?
Because the goal is to capture mutual reachability, the digraph analogue of "you can get from any vertex to any other," which for undirected graphs is symmetric automatically. If we only required a path from to for some fixed order of every pair (say, always before alphabetically), we would not get a meaningful notion of connectivity — the "requirement" would depend on an arbitrary labeling rather than the graph's structure. Requiring both directions for every ordered pair is precisely what makes strong connectivity well-defined independent of vertex labels, and it is what allows the strong-components relation to be proven an equivalence relation.
Can a DAG have more than one topological order?
Yes, and this is the typical case rather than an exception, as Example 2 demonstrates. Uniqueness of the topological order holds exactly when the DAG has a directed path between every pair of vertices in some order — i.e., when the reachability relation is a total order on — because then no two vertices are "incomparable" and free to be swapped. Whenever the source-removal construction in the proof encounters more than one available source (in-degree-0 vertex) at some stage, different choices yield different valid orders, so multiplicity of sources at any stage is a certificate of non-uniqueness.
How do I check whether a digraph is a DAG in practice?
Run the repeated-source-removal procedure from the theorem's proof (this is essentially Kahn's algorithm): repeatedly find a vertex of current in-degree , output it, and delete it along with its outgoing edges, updating in-degrees. If this process removes all vertices, the digraph is acyclic and the output order is a valid topological order. If at some point no in-degree- vertex remains but vertices are still undeleted, those remaining vertices necessarily lie on a directed cycle, so the digraph is not a DAG. This gives both a correctness certificate and, in the failing case, a witness to non-acyclicity.
What's the difference between the condensation being acyclic and the original digraph being acyclic?
These are different claims with different scopes. The condensation of any digraph — even one packed with directed cycles — is always acyclic, because by construction distinct strongly connected components cannot have paths going both ways between them (otherwise they'd have been merged into one SCC). The original digraph being acyclic is a much stronger, restrictive condition: it forces every strongly connected component of to be a single vertex with no self-loop, since any SCC with vertices or with a self-loop already contains a directed cycle. So " is a DAG" is equivalent to "every SCC of is a single vertex," while "the condensation of is a DAG" is unconditionally true.
Does every digraph have a source vertex (in-degree 0)?
No — only acyclic digraphs are guaranteed to have one, and this was exactly the key lemma used inductively in the topological-order proof. A digraph containing a directed cycle can have every vertex with in-degree at least ; indeed the simplest counterexample is the -cycle , where both and , so no source exists. The proof of the source-lemma is itself a proof by contradiction using the pigeonhole principle: assuming no source exists lets you walk backwards forever along in-edges, and finiteness of forces a repeated vertex, which yields a directed cycle.
How does strong connectivity relate to Menger's Theorem and network flows?
Strong connectivity is the qualitative, yes/no version of a question that Menger's Theorem and Network Flows and Max-Flow Min-Cut make quantitative. Once you know a digraph is strongly connected, natural follow-up questions are: how many vertex-disjoint or edge-disjoint directed paths connect a given pair , and how many edges (or vertices) must be deleted to destroy all directed paths from to ? Menger's theorem answers this by equating the maximum number of disjoint paths to the minimum size of a separating cut, and max-flow min-cut generalizes this further by attaching capacities to edges, turning "how many disjoint paths" into "how much flow can be pushed," with strong connectivity as the base case ensuring at least one path exists between every pair.