Foundations

Directed vs Undirected Graphs Explained

One word in the definition separates the two: whether the pair joining two vertices is ordered. This guide follows that word through degree, adjacency matrices, orientations and Robbins theorem, connectivity, and the algorithms that quietly stop working when you cross the line.

20 Min Read Updated: September 2026 Beginner Level
Mohammed Islam Hadjoudj
Mohammed Islam Hadjoudj
Expert Operations Research Engineer

1. The two definitions, side by side

The difference between a directed and an undirected graph is one word in the definition: whether the pair joining two vertices is ordered. Everything else in this article, including which algorithms still work, is a consequence of that word.

An undirected graph is the standard object covered in the guide to vertices and edges. Following Diestel's Graph Theory:

G = (V, E)      with   E ⊆ [V]²      an edge is an unordered pair {u, v}

A directed graph, or digraph, replaces the unordered pair with an ordered one:

D = (V, A)      with   A ⊆ V × V      an arc is an ordered pair (u, v)

Because (u, v) and (v, u) are different ordered pairs, both can be present at once, and a digraph containing both is said to have a digon between u and v. In the undirected world there is nothing to distinguish: {u, v} and {v, u} are the same set, so the edge exists once or not at all.

Diestel gives a more general formulation worth knowing, because it is the one that survives contact with real data. A directed graph is a pair (V, E) of disjoint sets together with two maps

init: E → V        assigning each edge its initial vertex
ter:  E → V        assigning each edge its terminal vertex

Here an arc is an object in its own right rather than a pair, so the definition admits parallel arcs and loops without any special pleading. It is the directed counterpart of the incidence-function definition that multigraphs need, and it is why a flight schedule with three separate daily flights from A to B is still a perfectly good digraph.

The formal relationship to logic is exact and worth stating once: an undirected graph without loops is precisely an irreflexive symmetric relation on V, while a digraph is an arbitrary binary relation on V. Direction is what you get when you stop insisting the relation be symmetric.

Two panels showing the same five vertices A to E. The left panel is an undirected graph with five plain edges: A to B, B to C, C to A, C to D and D to E, and each vertex is labelled with its degree, 2, 2, 3, 2 and 1. The right panel is a directed graph with six arrows: A to B, B to C, C to A, C to D, D to E and E back to D, and each vertex is labelled with its in-degree and out-degree. A caption notes the sum of degrees is 10 on the left, twice the five edges, while on the right the in-degrees and the out-degrees each sum to six, the number of arcs.
The running example. The digraph on the right has six arcs; the undirected graph on the left is its underlying graph, where the two arcs between D and E collapse into one edge.

These two graphs are the running example for the whole article. The digraph is

V = {A, B, C, D, E}
A = { (A,B), (B,C), (C,A), (C,D), (D,E), (E,D) }        6 arcs

and the undirected graph on the left is its underlying graph, with 5 edges, since the opposite arcs between D and E become the single edge {D, E}.

2. Edges, arcs, tails and heads

The vocabulary changes along with the definition, and the changes are not decorative. Bang-Jensen and Gutin's Digraphs, the standard reference on the directed side, is careful to reserve separate words so that a statement can never be ambiguous about which object it means.

UndirectedDirectedNotes
Edge {u, v}Arc (u, v)Many authors say "directed edge" for arc; the meaning is identical
EndpointsTail u and head vThe arrow points at the head
u and v are adjacentv is an out-neighbour of uAnd u is an in-neighbour of v. The relation is no longer symmetric
Degree deg(v)Out-degree d+(v), in-degree d-(v)Two numbers where there was one
Walk, path, cycleDirected walk, path, cycleEvery step must follow an arc forwards
ConnectedStrongly, unilaterally or weakly connectedOne notion splits into three, see section 7
Tree, forestArborescence, branchingA tree with every arc pointing away from a root

Two terms deserve their own line because they are routinely mixed up. An oriented graph is a digraph with no digons: you took an undirected graph and chose one direction for each edge. Every oriented graph is a digraph, but a digraph containing both (u,v) and (v,u) is not an oriented graph. This distinction is the whole subject of section 5.

3. Degree splits in two

In an undirected graph the degree of a vertex counts the edge ends meeting it, and the handshaking lemma says those counts sum to twice the number of edges. In a digraph each arc has one tail and one head rather than two symmetric ends, so the single count splits into two:

and the one identity splits into two as well:

undirected     ∑v∈V deg(v)   =  2m           every edge has two ends

directed       ∑v∈V d+(v)  =  ∑v∈V d-(v)  =  |A|
                                             every arc has one tail and one head

The missing factor of 2 catches people out. It is not a different theorem, it is the same double-counting argument applied to a set whose elements now contribute to two separate sums instead of twice to one.

Check it on the running example. Out-degrees are A 1, B 1, C 2, D 1, E 1, summing to 6. In-degrees are A 1, B 1, C 1, D 2, E 1, also summing to 6, which is the number of arcs. On the underlying undirected graph the degrees are 2, 2, 3, 2, 1, summing to 10, which is twice its 5 edges.

Two named vertex types come out of this immediately and have no undirected counterpart at all:

Sources and sinks are the entry and exit points of flow networks and the starting and finishing positions of a topological order. In an undirected graph the concepts are simply not expressible.

4. What changes in the matrix and the list

Direction shows up in storage as clearly as it does in the definition, and the differences are the ones set out in Cormen, Leiserson, Rivest and Stein's Introduction to Algorithms.

Two five by five adjacency matrices for the same vertex set A to E. The left matrix, for the undirected graph, is symmetric about its main diagonal, with mirrored pairs of ones highlighted. The right matrix, for the digraph, is not symmetric: the entry from C to D is one while the entry from D to C is zero. Row sums on the right are labelled as out-degrees and column sums as in-degrees.
Symmetry is the visible signature of an undirected graph. On the right, C reaches D but D does not reach C, so the two mirrored entries disagree.

The adjacency matrix. For an undirected graph the matrix is always symmetric, A = AT, because {u, v} and {v, u} are the same edge. For a digraph it generally is not, and that asymmetry carries real information:

The adjacency list. An undirected graph stores every edge twice, once in each endpoint's list, so the lists hold 2m entries. A digraph stores each arc once, in the tail's list, giving m entries. This has a practical consequence that surprises people the first time: to walk a digraph backwards you need a second structure, the reverse adjacency list, because a vertex's list tells you where you can go, not where you came from. Kosaraju's algorithm for strongly connected components is built directly on that observation and traverses the reverse graph on its second pass.

Two counting bounds follow. A simple undirected graph on n vertices has at most n(n-1)/2 edges. A digraph with no loops has at most n(n-1) arcs, exactly twice as many, because each ordered pair is now its own slot.

5. Orientations and the underlying graph

The two worlds are connected by a pair of constructions that go in opposite directions, and naming them properly removes a lot of confusion.

These are not inverse operations. Taking the underlying graph loses information that no orientation can restore, and a graph with m edges has 2m distinct orientations, since each edge is an independent binary choice. The running example's underlying graph has 5 edges and therefore 32 orientations, of which the original digraph is not even one, because the original has a digon.

That raises the question the next section answers. Of those 2m orientations, is any of them good, in the sense that you can still get everywhere?

6. Robbins' theorem: which streets can go one-way

In 1939 Herbert Robbins published a short paper in the American Mathematical Monthly with the memorable title "A theorem on graphs, with an application to a problem of traffic control". The problem is exactly the one a city planner faces: if every street becomes one-way, can drivers still reach every part of town?

Robbins' theorem. A connected undirected graph has a strongly connected orientation if and only if it has no bridge.

A bridge, also called a cut edge, is an edge whose removal disconnects the graph. A connected graph with no bridges is exactly a 2-edge-connected graph, one where every edge lies on a cycle. (Connectedness matters here: a disconnected graph can be bridgeless without being 2-edge-connected.)

Two panels. On the left a four-vertex cycle with no bridges, shown oriented as a directed cycle, marked with a green tick and the note that every vertex can still reach every other. On the right the same cycle with an extra vertex attached by a single edge, which is a bridge, shown with that edge oriented outwards, marked with a red cross and the note that whichever way the bridge is oriented, one side becomes unreachable from the other.
A bridge admits only two orientations and both of them strand one side. Everything else on a bridgeless graph can be oriented so that the whole graph stays mutually reachable.

One direction of the proof is the easy one and is worth seeing, because it explains the whole result. Suppose e = {u, v} is a bridge, so removing it splits the graph into a component holding u and a component holding v. Any orientation must send e one way or the other. If it becomes (u, v) then nothing on v's side can ever return to u's side, because e was the only connection and it now points the wrong way. If it becomes (v, u) the same argument runs in reverse. Either way the orientation fails to be strongly connected. The converse, that every bridgeless connected graph does admit a strongly connected orientation, is the substantial half, and the standard proof runs a depth-first search and orients tree edges away from the root and back edges towards it.

The running example makes the theorem concrete. Its underlying graph contains the triangle A, B, C, which is bridgeless, but the edges {C, D} and {D, E} are both bridges. So by Robbins' theorem no orientation of that graph is strongly connected, which is precisely why the digraph in the figure is not strongly connected no matter how you redraw the arrows.

Nash-Williams generalised the result in 1960: every 2k-edge-connected undirected graph has a k-arc-connected orientation, of which Robbins' theorem is the case k = 1. The practical reading is unchanged. One-way systems are safe exactly where the road network has redundancy, and a single road connecting a suburb to the rest of town can never be made one-way without cutting it off.

7. Connectivity becomes three different questions

In an undirected graph, connectivity is a single yes or no: is there a path between every pair of vertices? Direction breaks that into a hierarchy. The classification is due to Harary, Norman and Cartwright's Structural Models, and it is the piece of directed-graph theory most often skipped and most often needed.

A digraph iswhen, for every pair u and vRunning example
Strongly connectedu reaches v and v reaches uNo: D cannot reach A
Unilaterally connectedu reaches v or v reaches uYes: A reaches D, which is enough for that pair
Weakly connectedthe underlying undirected graph is connectedYes
Disconnectednot even weakly connectedNo

Each condition implies the one below it, so strong implies unilateral implies weak. The running example sits exactly in the middle of the hierarchy, which is the common case in practice: you can get from the A, B, C triangle out to D and E, but never back.

The useful refinement is to stop asking about the whole digraph and ask about its parts. A strongly connected component, or SCC, is a maximal set of vertices in which every vertex reaches every other. Every digraph partitions uniquely into SCCs, and contracting each one to a single vertex produces the condensation, which is always acyclic. That last fact is not an accident: if the condensation had a cycle, every component on it would reach every other, so they would all have been one SCC to begin with.

On the left the running digraph with its two strongly connected components shaded: one containing A, B and C which form a directed triangle, and one containing D and E which point at each other. On the right the condensation, in which each component has been contracted to a single vertex, leaving a single arc from the A B C component to the D E component, a directed acyclic graph.
Two strongly connected components and the condensation they induce. Contracting each component always leaves a DAG, whatever the original digraph looked like.

Finding the SCCs takes linear time. Tarjan's 1972 paper "Depth-first search and linear graph algorithms" does it in a single depth-first traversal using low-link numbers, and the Kosaraju-Sharir method does it with two passes, the second over the reverse digraph. Both run in O(n + m), and both have no undirected counterpart, because in an undirected graph the connected components fall out of any single traversal.

8. Cycles, DAGs and topological order

The word "cycle" quietly means something stricter once arrows are involved, and the gap causes real bugs.

In a simple undirected graph, a cycle is a closed walk with no repeated vertex, and it needs at least three vertices, since going along an edge and straight back is not considered a cycle. An undirected graph with no cycles is a forest, and a connected one is a tree.

In a digraph, a directed cycle must follow the arrows the whole way round, and a digon counts: the two arcs (D, E) and (E, D) form a directed cycle of length 2. A digraph with no directed cycles is a DAG, a directed acyclic graph, and DAGs carry a property nothing in the undirected world has:

A digraph has a topological order, a linear arrangement of its vertices in which every arc points forwards, if and only if it is acyclic.

Kahn's 1962 paper in Communications of the ACM gave the standard algorithm: repeatedly take a vertex of in-degree 0, output it, and delete it along with its outgoing arcs. If the digraph empties, the output is a topological order; if it stalls with vertices remaining, every survivor lies on a cycle. The details are in the guide to topological sorting.

Two traps follow from all this:

9. Which algorithms transfer, and which break

The practical question is which parts of an undirected toolkit survive the move. The pattern is clearer than it first appears: anything that only follows edges forwards transfers, and anything that relies on symmetry does not.

ProblemUndirectedDirectedWhat changes
BFS and DFSWorksWorksSame code, follow out-arcs only. Reachability is now one-way
Shortest path, non-negative weightsDijkstraDijkstraNothing. Dijkstra never assumed symmetry
Shortest path, negative weightsUnbounded, or NP-hardBellman-FordA single negative undirected edge can be walked back and forth, so it is already a negative cycle: shortest walks are unbounded, and restricting to simple paths makes the problem NP-hard
Connected componentsOne traversalTarjan or Kosaraju-Sharir for SCCsThree notions of connectivity instead of one
Cycle detectionAny non-parent visited neighbourBack edge to a vertex on the recursion stackThe undirected test gives false positives on a digraph
Minimum spanning treeKruskal, PrimDoes not applyThe directed analogue is the minimum arborescence, solved by Chu-Liu/Edmonds, not by a greedy edge sort
Eulerian circuitConnected and every degree evenConnected and d+(v) = d-(v) for every vThe parity condition becomes a balance condition
Maximum flowModel as two opposite arcsNativeFlow is directed by definition; Ford and Fulkerson posed it on a digraph
Topological sortMeaninglessKahn or DFSNeeds arrows to have anything to order

The minimum spanning tree row is the one that catches experienced people. Kruskal's and Prim's algorithms are greedy on a symmetric cost structure, and neither survives orientation. The right directed question is the minimum spanning arborescence: choose a set of arcs of least total weight so that every vertex is reachable from a fixed root. Chu and Liu in 1965 and Edmonds in 1967 solved it independently, and the algorithm looks nothing like a sorted edge scan: it selects each vertex's cheapest incoming arc, then contracts any cycle that forms and repeats.

10. Choosing: is your relation symmetric?

The modelling question has one form: if the relation holds from u to v, must it hold from v to u? If yes, use an undirected graph. If no, or if you are unsure, use a digraph, because a digraph can always express a symmetric relation but not the reverse.

RelationSymmetric?Model
"is friends with" on a social networkYes, by construction on most platformsUndirected
"follows" on a social networkNoDirected
"links to" between web pagesNoDirected. Brin and Page's PageRank is defined on this digraph
"co-authored a paper with"YesUndirected
"cites"No, and it is usually acyclic in timeDirected, very nearly a DAG
"is connected by a two-way street to"YesUndirected, unless costs differ by direction
"depends on" between build targetsNoDirected, and it must be a DAG or the build cannot run
"can be reached in one flight from"Usually but not alwaysDirected, since one-way routes exist

One case deserves special attention because it looks symmetric and is not. An undirected edge can carry only one weight. If the cost of going from u to v differs from the cost of coming back, the relation is mutual but the model must still be directed. Cycling uphill and downhill, uploading and downloading on an asymmetric link, and exchanging currency in one direction versus the other are all mutual connections with two different costs, and each of them forces a digraph with two arcs carrying different weights.

11. Converting between the two

Three conversions come up constantly, and each loses or invents something you should be aware of.

12. Common mistakes

13. Glossary

TermMeaning
Arc (u, v)A directed edge, from tail u to head v
DigraphA directed graph, D = (V, A) with A ⊆ V × V
DigonA pair of opposite arcs between the same two vertices
Oriented graphA digraph with no digons: one direction chosen per edge
Orientation of GThe oriented graph produced by directing every edge of G
Underlying graphThe undirected graph obtained by forgetting all arrow directions
Reverse digraphEvery arc flipped; its matrix is AT
In-degree, out-degreed-(v) arcs arriving, d+(v) arcs leaving
Source, sinkIn-degree 0, out-degree 0 respectively
Strongly connectedEvery vertex reaches every other, following arrows
SCCA maximal strongly connected set of vertices
CondensationThe digraph of SCCs contracted to single vertices; always a DAG
DAGA digraph with no directed cycle
ArborescenceA directed tree with all arcs pointing away from one root
BridgeAn edge whose removal disconnects an undirected graph

14. Frequently asked questions

What is the difference between a directed and an undirected graph?

An undirected graph joins vertices with unordered pairs {u, v}, so the connection works both ways and the relation is symmetric. A directed graph, or digraph, uses ordered pairs (u, v), so an arc runs from a tail to a head and the reverse arc is a separate object that may or may not exist. Everything else follows from that: degree splits into in-degree and out-degree, the adjacency matrix stops being symmetric, and connectivity splits into strong, unilateral and weak.

Is an undirected graph just a digraph with arcs in both directions?

For storage and for traversal, yes, and that is exactly how most libraries represent undirected graphs. For structural questions, no. Doubling every edge into two opposite arcs turns each edge into a directed cycle of length 2, so a DAG test always fails, every connected component becomes a single strongly connected component, and a cycle detector fires on every edge. The representation is faithful; running directed structural algorithms on it is not.

Does Dijkstra's algorithm work on directed graphs?

Yes, without any modification. Dijkstra's algorithm only ever relaxes edges leaving the vertex it has just settled, so it never relies on symmetry. Its real requirement is that weights are non-negative, which is a condition on the weight function rather than on direction. Note the reverse point too: shortest paths with negative weights are really a directed problem, because a single negative undirected edge can be traversed back and forth and is therefore already a negative cycle, which leaves shortest walks unbounded and shortest simple paths NP-hard.

What is the difference between a digraph and an oriented graph?

An oriented graph is a digraph with no digons, meaning it never contains both (u, v) and (v, u). Equivalently, it is what you get by taking an undirected graph and choosing exactly one direction for each edge. Every oriented graph is a digraph, but a digraph with a pair of opposite arcs is not an oriented graph. An undirected graph with m edges has 2 to the power m distinct orientations.

When can every street in a city be made one-way?

Exactly when the street network has no bridge, that is, no single road whose removal would split the town in two. This is Robbins' theorem of 1939: a connected undirected graph has a strongly connected orientation if and only if it is bridgeless. The reason a bridge fails is easy to see, since whichever of its two directions you choose, nothing on the far side can ever come back.

Do minimum spanning tree algorithms work on directed graphs?

No. Kruskal's and Prim's algorithms are greedy on a symmetric cost structure and have no directed version. The directed analogue of the problem is the minimum spanning arborescence: pick the cheapest set of arcs so that every vertex is reachable from a chosen root. Chu and Liu in 1965 and Edmonds in 1967 solved it independently, and the method is different in kind, selecting each vertex's cheapest incoming arc and then contracting any cycle that appears.

15. References

The definitions, theorems and attributions above come from these sources, listed in chronological order.

  1. Robbins, H. E. (1939). "A theorem on graphs, with an application to a problem of traffic control." American Mathematical Monthly 46(5), 281 to 283. The bridgeless orientation theorem in section 6.
  2. Ford, L. R. and Fulkerson, D. R. (1956). "Maximal flow through a network." Canadian Journal of Mathematics 8, 399 to 404. Flow posed on a digraph from the beginning.
  3. Nash-Williams, C. St. J. A. (1960). "On orientations, connectivity and odd-vertex-pairings in finite graphs." Canadian Journal of Mathematics 12, 555 to 567. The k-arc-connected generalisation of Robbins.
  4. Kahn, A. B. (1962). "Topological sorting of large networks." Communications of the ACM 5(11), 558 to 562.
  5. Chu, Y. J. and Liu, T. H. (1965). "On the shortest arborescence of a directed graph." Scientia Sinica 14, 1396 to 1400.
  6. Harary, F., Norman, R. Z. and Cartwright, D. (1965). Structural Models: An Introduction to the Theory of Directed Graphs. New York: Wiley. Source of the strong, unilateral and weak classification.
  7. Edmonds, J. (1967). "Optimum branchings." Journal of Research of the National Bureau of Standards 71B(4), 233 to 240.
  8. Tarjan, R. E. (1972). "Depth-first search and linear graph algorithms." SIAM Journal on Computing 1(2), 146 to 160. Linear-time strongly connected components.
  9. Sharir, M. (1981). "A strong-connectivity algorithm and its applications in data flow analysis." Computers & Mathematics with Applications 7(1), 67 to 72. The two-pass method usually paired with Kosaraju's name.
  10. Brin, S. and Page, L. (1998). "The anatomy of a large-scale hypertextual Web search engine." Computer Networks and ISDN Systems 30(1 to 7), 107 to 117. PageRank on the web digraph.
  11. West, D. B. (2001). Introduction to Graph Theory, 2nd edition. Upper Saddle River: Prentice Hall.
  12. Bondy, J. A. and Murty, U. S. R. (2008). Graph Theory. Graduate Texts in Mathematics 244. London: Springer.
  13. Bang-Jensen, J. and Gutin, G. (2009). Digraphs: Theory, Algorithms and Applications, 2nd edition. London: Springer. The standard reference for directed graph terminology.
  14. Cormen, T. H., Leiserson, C. E., Rivest, R. L. and Stein, C. (2009). Introduction to Algorithms, 3rd edition. Cambridge, Massachusetts: MIT Press. Source of the representation costs in section 4.
  15. Chartrand, G., Lesniak, L. and Zhang, P. (2015). Graphs & Digraphs, 6th edition. Boca Raton: CRC Press. A textbook that develops both objects side by side.
  16. Diestel, R. (2017). Graph Theory, 5th edition. Graduate Texts in Mathematics 173. Berlin: Springer. Source of both definitions quoted in section 1.

Watch direction change the answer

Build a graph, flip its edges to arcs, and run the same traversal twice. The set of reachable vertices changing in front of you is the fastest way to internalise everything on this page.

Open the visualizer

Watch Direction Change the Answer

Build a graph, run a traversal, and see exactly which vertices are reachable. Then flip the arrows and run it again. The set of reachable vertices changing in front of you is the fastest way to internalise everything on this page.

Launch the SCC Visualizer