- Published on
Introduction to Graph Theory - Part 6
- Authors

- Name
- Till Heller
Back in Part 2, we noted that the friendship between Alice and Bob is mutual — if Alice considers Bob a friend, then Bob considers Alice a friend too. But not all relationships work this way. On social media, Alice might follow Bob without Bob following her back. A one-way street lets you drive from intersection to intersection , but not the other way around. A webpage can link to another page without being linked back. In all these cases, the direction of the connection matters.
Until now, all our graphs have been undirected — edges had no direction. It's time to change that.
Directed Graphs
In Part 2, we mentioned in a footnote that and could be treated as different edges if we care about direction. Let's make this idea precise.
Definition 26. A directed graph (or digraph) is a pair , where is a finite set of vertices and is a set of arcs (or directed edges). An arc goes from to .
The key difference from undirected graphs is that order matters: the arc goes from to , while goes in the opposite direction. These are two different arcs. When we draw a digraph, we use arrows instead of plain lines to indicate direction.
Consider the digraph . This describes a directed cycle: from to , from to , and from back to . Notice that you cannot go from to directly — the arc only goes the other way.

Let's revisit our social media example. Suppose Alice follows Bob and Charlie, Bob follows Charlie, and Charlie follows Alice. We can model this as a digraph with vertices and arcs . Notice that Alice follows Bob but Bob does not follow Alice — the relationship is not symmetric. This is exactly the kind of situation that undirected graphs cannot capture1.
In-Degree and Out-Degree
In undirected graphs, the degree of a vertex counts all its neighbors. In digraphs, we need to distinguish between incoming and outgoing connections.
Definition 27. The in-degree of a vertex , denoted , is the number of arcs pointing to . The out-degree of a vertex , denoted , is the number of arcs pointing from .
In our social media digraph, Alice has in-degree (only Charlie follows her) and out-degree (she follows Bob and Charlie). Bob has in-degree and out-degree . Charlie has in-degree and out-degree .

Just like the Handshaking Lemma from Part 4, there is a directed version.
Lemma 3 (Directed Handshaking Lemma). For any digraph , we have .
Proof. Every arc contributes exactly to the out-degree of and exactly to the in-degree of . Summing over all arcs gives both equalities.
This makes intuitive sense: every arc that leaves some vertex must arrive at some vertex, so the total number of departures equals the total number of arrivals.
Directed Walks and Paths
The concepts of walks and paths from Part 4 carry over naturally to digraphs — we just have to follow the arrows.
Definition 28. A directed walk in a digraph is a sequence of vertices such that for all . A directed path is a directed walk with no repeated vertices.
The crucial difference from the undirected case is that we can only move in the direction of the arcs. In the digraph , the sequence is a valid directed path, but is not — there is no arc from to .
Weak and Strong Connectivity
In undirected graphs, connectivity was straightforward: either you can reach every vertex from every other vertex, or you can't. In digraphs, things are more subtle. Due to the direction of arcs, you might be able to reach from but not from . This gives rise to two different notions of connectivity.
Definition 29. A digraph is weakly connected if the undirected graph obtained by ignoring all arc directions is connected.
Definition 30. A digraph is strongly connected if for every pair of vertices , there exists a directed path from to and a directed path from to .
Strong connectivity is a much stronger requirement. Our directed cycle is strongly connected: from any vertex, you can reach any other by following the arcs around the cycle. But the digraph is only weakly connected — you can reach and from , but you cannot reach from or .
Just as undirected graphs decompose into connected components, digraphs decompose into strongly connected components.
Definition 31. A strongly connected component (SCC) of a digraph is a maximal subset such that for every pair , there is a directed path from to and from to .
Every vertex belongs to exactly one SCC (even if that component contains only the vertex itself). The strongly connected components of a digraph reveal its large-scale structure: within each component, everything can reach everything else; between components, the flow goes only one way.

Observation 6. If we contract each strongly connected component of a digraph into a single vertex, the resulting graph has no directed cycle.
This is worth a moment of thought. If two components were connected by directed paths in both directions, we could combine them into a single, larger strongly connected component — contradicting the fact that they are maximal. So the "condensed" digraph is always acyclic, which brings us to our next topic.
Directed Acyclic Graphs
Some of the most useful digraphs are those that contain no directed cycles at all. Think of prerequisite structures: to take Advanced Calculus, you first need Calculus I and II. There is a clear ordering — you can't have circular prerequisites. This is modeled by a directed acyclic graph.
Definition 32. A directed acyclic graph (or DAG) is a digraph that contains no directed cycle.
DAGs show up everywhere: task scheduling (some tasks must finish before others can start), dependency graphs in software builds, version histories in Git, and even citation networks among academic papers.
Two types of vertices play a special role in DAGs.
Definition 33. In a digraph, a source is a vertex with in-degree . A sink is a vertex with out-degree .
A source has no incoming arcs — nothing points to it. A sink has no outgoing arcs — it doesn't point to anything. In our prerequisite example, a course with no prerequisites is a source, and a course that is not a prerequisite for anything else is a sink.
Lemma 4. Every DAG has at least one source and at least one sink.
Proof. Suppose a DAG has no source. Then every vertex has at least one incoming arc. Starting at any vertex , we can follow an incoming arc backwards to find a vertex with . From , we can again follow an incoming arc to find , and so on. Since the graph is finite, this process must eventually revisit a vertex — but that means we have found a directed cycle, contradicting the assumption that is a DAG. So every DAG has at least one source. The argument for sinks is symmetric: follow outgoing arcs forward instead of incoming arcs backward.
Topological Ordering
Since DAGs have no directed cycles, their vertices can be lined up in an order that respects all the arcs — a topological ordering.
Definition 34. A topological ordering of a digraph is a linear ordering of all vertices such that for every arc , we have .
In other words, every arc points "forward" in the ordering. In our prerequisite example, a topological ordering tells you a valid sequence in which to take all your courses so that you never take a course before its prerequisites.
Theorem 5. A digraph has a topological ordering if and only if it is a DAG.
Proof. For the "only if" direction: suppose has a topological ordering and contains a directed cycle . Then the arc requires , the arc requires , and so on, until the arc requires . Chaining these inequalities gives , which is a contradiction. So must be a DAG.
For the "if" direction, we use Lemma 4 to build the ordering step by step. Let be a DAG. By Lemma 4, has a source . Place first in the ordering. Now remove and all its outgoing arcs from . The resulting digraph is still a DAG (removing vertices and arcs cannot create cycles), so it has a new source. Place that source next in the ordering. Continue until all vertices have been placed.
This constructive proof also gives us an algorithm: repeatedly find a source, output it, remove it, and repeat. This is known as Kahn's algorithm for topological sorting and runs efficiently even on large graphs2.

Looking Ahead
With directed graphs, we've expanded our toolkit considerably. Many real-world systems — from supply chains to web links — are naturally directed. If you're curious about what happens when we add capacities to arcs and ask how much "flow" we can push through a network, take a look at the series on Network Flows, which builds directly on the ideas from this part.
In the next part of this introduction, we will change direction and explore graph coloring — the art of assigning colors to vertices so that no two adjacent vertices share the same color. This seemingly simple idea leads to some of the most famous results and open problems in all of mathematics.
Footnotes
If a relationship is symmetric — every arc has a corresponding arc — we can replace each pair with a single undirected edge and work with an undirected graph instead. ↩
Kahn's algorithm runs in time, where is the number of vertices and is the number of arcs. An alternative approach based on depth-first search achieves the same time complexity. ↩