A graph is an abstract object. To compute with it, draw it, store it, or communicate it, one must choose a representation.
A representation is a concrete encoding of the vertex set and edge set. It may be a drawing, a list of edges, an adjacency list, a matrix, or a data structure in memory. The representation is not the graph itself. Different representations may describe the same graph.
The main representations are:
| Representation | Best use |
|---|---|
| Drawing | Human intuition |
| Edge list | Simple storage and input format |
| Adjacency list | Traversal and sparse graphs |
| Adjacency matrix | Fast adjacency queries and algebraic methods |
| Incidence matrix | Vertex-edge incidence and flow-style arguments |
4.1 Drawings
A drawing represents vertices as points and edges as curves or line segments between points.
For example, the graph
may be drawn as a square, a diamond, or two crossing diagonals depending on where the vertices are placed.
The drawing is only a visual representation. It may suggest structure, but it may also mislead. Two drawings can look different while representing the same graph.
Graph theory usually treats graphs abstractly. The exact positions of vertices and the shapes of edges matter only in special subjects such as planar graph theory, geometric graph theory, and graph drawing.
4.2 Edge Lists
An edge list stores the graph by listing its edges.
For the graph
with
the edge list is
For an undirected graph, the pair in an edge list usually represents the unordered edge . The notation is convenient for storage.
An edge list is compact and simple. It is often used in input files, streaming systems, graph databases, and distributed processing. It directly records the edges, and it does not require a fixed vertex ordering unless later converted into a matrix.
The main weakness is adjacency lookup. To decide whether and are adjacent, one may need to scan the list.
4.3 Adjacency Lists
An adjacency list stores, for each vertex, the list of its neighbors.
For the graph
the adjacency list is:
| Vertex | Neighbors |
|---|---|
In an undirected graph, each edge appears twice in the adjacency list: once for each endpoint. The edge appears in the list for and in the list for .
Adjacency lists are natural for graph traversal. To explore from a vertex , one reads the list . This makes adjacency lists well suited for breadth-first search, depth-first search, connected components, shortest paths on sparse graphs, and many network algorithms.
For a graph with vertices and edges, an adjacency list uses space proportional to
This is efficient when the graph is sparse. A sparse graph has relatively few edges compared with the maximum possible number of edges. Standard algorithm texts contrast this with the storage used by adjacency matrices.
4.4 Adjacency Matrices
An adjacency matrix represents a graph by a square matrix.
Let
be an ordered vertex set. The adjacency matrix of a simple graph is the matrix defined by
For the graph with vertex order and edge set
the adjacency matrix is
The matrix is symmetric because the graph is undirected. Also, the diagonal entries are zero because the graph has no loops. These are standard properties of adjacency matrices for finite simple undirected graphs.
4.5 Matrix Entries
The entry records adjacency between and .
For a simple graph,
For a multigraph, the entry may count the number of edges between and .
For a directed graph, the entry records an edge from to . The matrix need not be symmetric, since an edge from to need not be accompanied by an edge from to .
For a weighted graph, the entry may store the weight of the edge. If no edge exists, one often stores , , or a special missing value, depending on the algorithm.
| Graph type | Meaning of |
|---|---|
| Simple undirected graph | if is adjacent to , else |
| Directed graph | if there is an arc , else |
| Multigraph | Number of edges between the vertices |
| Weighted graph | Weight or cost of the edge |
4.6 Advantages of Adjacency Matrices
Adjacency matrices support fast adjacency tests.
If the graph is stored as a matrix, one can check whether and are adjacent by reading the single entry
This takes constant time in a standard array representation.
Adjacency matrices are also useful for algebraic graph theory. Matrix operations can reveal walks, spectra, connectivity, and structural properties. For example, powers of the adjacency matrix count walks in a graph. This fact will be developed later.
The main cost is storage. An adjacency matrix for vertices stores entries, even when the graph has few edges. Thus adjacency matrices are natural for dense graphs and algebraic methods, but inefficient for very sparse graphs.
4.7 Incidence Matrices
An incidence matrix records the relation between vertices and edges.
Let
and
The incidence matrix is an matrix . Its rows correspond to vertices, and its columns correspond to edges.
For an undirected simple graph,
For example, let
and
where
With vertex order and edge order , the incidence matrix is
Each column has two ’s because each edge has two endpoints.
Incidence matrices differ from adjacency matrices. An adjacency matrix records vertex-vertex relations. An incidence matrix records vertex-edge relations.
4.8 Oriented Incidence Matrices
For directed graphs, incidence matrices often use signs.
Let be an arc from to . The oriented incidence matrix may use
Some authors reverse the signs. The choice is conventional. What matters is consistency.
For the directed edges
with vertices ordered as , one convention gives
This representation is important in network flows, electrical networks, algebraic graph theory, and discrete differential operators.
4.9 Adjacency Maps
In computer programs, an adjacency list is often implemented as an adjacency map.
For example, a graph may be stored as a map from vertices to neighbor sets:
a -> {b, c}
b -> {a, d}
c -> {a, d}
d -> {b, c}This representation makes it easy to support arbitrary vertex labels. The vertices do not have to be integers from to .
A map from vertices to sets supports efficient neighbor iteration and, depending on the set implementation, efficient adjacency testing.
For weighted graphs, each neighbor may carry an edge value:
a -> {(b, 7), (c, 2)}
b -> {(a, 7), (d, 4)}
c -> {(a, 2), (d, 5)}
d -> {(b, 4), (c, 5)}This is the standard practical form used in many graph algorithms.
4.10 Comparison of Representations
No representation is best for all tasks.
| Representation | Space | Fast adjacency test | Fast neighbor iteration | Good for |
|---|---|---|---|---|
| Edge list | No | No | Input, streaming, simple storage | |
| Adjacency list | Sometimes | Yes | Sparse graphs, traversal | |
| Adjacency matrix | Yes | No for sparse graphs | Dense graphs, algebraic methods | |
| Incidence matrix | No | No | Edge-based algebra, flows |
Here and .
Adjacency matrices use space. Adjacency lists use space. This difference becomes decisive for large sparse graphs.
4.11 Sparse and Dense Graphs
A graph on vertices can have at most
edges if it is simple and undirected.
A graph is called sparse when is much smaller than . It is called dense when is close to .
Sparse graphs favor adjacency lists. Dense graphs may favor adjacency matrices.
For example, a road network is usually sparse: each intersection connects to only a few nearby intersections. A complete graph is dense: each vertex is adjacent to every other vertex.
The choice of representation should follow the expected operations.
4.12 Representation and Algorithms
Different algorithms prefer different representations.
Breadth-first search and depth-first search repeatedly ask for the neighbors of a vertex. Adjacency lists support this directly.
Shortest path algorithms on sparse graphs usually use adjacency lists with edge weights.
Algorithms based on matrix multiplication or eigenvalues require matrix representations.
Algorithms that process one edge at a time, such as sorting edges for Kruskal’s minimum spanning tree algorithm, naturally use edge lists.
| Task | Natural representation |
|---|---|
| Read graph from file | Edge list |
| Traverse graph | Adjacency list |
| Check whether one edge exists | Adjacency matrix or adjacency map |
| Compute eigenvalues | Adjacency matrix or Laplacian matrix |
| Sort all edges by weight | Edge list |
| Work with flows and conservation laws | Incidence matrix |
Representation is therefore an algorithmic decision, not only a storage decision.
4.13 Example
Let
and
The edge list is
The adjacency list is:
| Vertex | Neighbors |
|---|---|
The adjacency matrix, using the vertex order , is
If the edge order is
then the incidence matrix is
All four representations describe the same graph.
4.14 Summary
A graph can be represented by a drawing, an edge list, an adjacency list, an adjacency matrix, or an incidence matrix.
Drawings help intuition. Edge lists are simple. Adjacency lists support traversal and sparse graphs. Adjacency matrices support fast adjacency tests and algebraic methods. Incidence matrices record vertex-edge relations and are useful in flow and structural arguments.
The graph is the abstract pair . A representation is a chosen encoding of that pair. Later algorithms will depend strongly on this choice.