Graph Isomorphism
Graph isomorphism means two graphs have the same structure, even if they are drawn or labeled differently. Graphs G and H are isomorphic when a one-to-one matching of their vertices sends every edge of G to an edge of H and every non-edge to a non-edge. To prove it, give the matching; to disprove it, find a difference.
Before this lesson: Graph Theory Basics, Injective, Surjective and Bijective Functions and Transpose of a Matrix
The idea
A graph only records which vertices are joined. The same graph can be drawn in many ways, with different positions, different names and even crossing edges. Two drawings of the same structure should count as “the same graph.”
An isomorphism is a renaming of the vertices that turns one graph exactly into the other. If you relabel the vertices of G by the rule and every edge lines up with an edge of H, nothing about the structure has changed.
Representing graphs
To compare graphs, we first need a way to write them down. Two standard ways are the adjacency list and the adjacency matrix.
- An adjacency list lists each vertex with its neighbors.
- The adjacency matrix of a graph with vertices v_1, \dots, v_n is the n × n matrix A with a_{ij} = 1 when v_i and v_j are adjacent and a_{ij} = 0 when they are not.
For a simple graph, A has 0s on the diagonal (no loops) and is symmetric, A^T = A, because v_i \sim v_j exactly when v_j \sim v_i. Row i adds up to \deg(v_i).
Graph isomorphism definition
Graphs G and H are isomorphic, written G \cong H, if there is a bijection f : V(G) \to V(H) such that
uv \in E(G) \iff f(u)f(v) \in E(H)
The bijection f is an isomorphism. Because f is one-to-one, it matches vertices exactly; because of the “if and only if,” it matches edges to edges and non-edges to non-edges.
Graph invariants
An invariant is a property that isomorphic graphs always share. If two graphs differ in any invariant, they are not isomorphic.
| Invariant | Why an isomorphism keeps it |
|---|---|
| Number of vertices | f is a bijection between the vertex sets. |
| Number of edges | f matches edges one to one. |
| Degree sequence | f sends each vertex to a vertex with the same number of neighbors. |
| Number of triangles (3-cycles) | f sends a triangle to a triangle. |
| Connected or not | f sends a path to a path. |
| Degrees of a vertex’s neighbors | f keeps both adjacency and degree. |
Matching invariants are not a proof. Two graphs can agree on every invariant you check and still differ. To prove isomorphism, you must give a bijection and check every edge.
How to test two graphs
- Compare the vertex counts, edge counts and degree sequences. If any differ, the graphs are not isomorphic.
- Compare other invariants: triangles, connectedness, which degrees are next to which.
- Build a matching: send each vertex to a vertex of the same degree, using neighbors to decide between choices.
- Check every edge of G. If each maps to an edge of H and the edge counts are equal, f is an isomorphism.
Graph isomorphism examples
Example 1: Adjacency list and matrix
Graph G has vertices 1, 2, 3, 4 and edges {1, 2}, {1, 3}, {2, 3} and {3, 4}. Write its adjacency list and adjacency matrix, and read off the degrees.
1: 2, 3;\ \ 2: 1, 3
Vertex 1 is joined to 2 and 3; vertex 2 is joined to 1 and 3.
3: 1, 2, 4;\ \ 4: 3
Vertex 3 is joined to 1, 2 and 4; vertex 4 only to 3.
A = \begin{bmatrix} 0 & 1 & 1 & 0 \\ 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{bmatrix}Put a 1 in row i, column j for each neighbor j of i.
2,\ 2,\ 3,\ 1
The row sums are the degrees of 1, 2, 3 and 4.
2 + 2 + 3 + 1 = 8
Add the degrees.
2 \cdot 4 = 8
Twice the 4 edges, as the handshaking lemma says.
Answer: the list and matrix are above; the matrix is symmetric with a zero diagonal, and the degrees are 2, 2, 3 and 1.
Example 2: Proving two graphs are isomorphic
Show that the pentagon G and the star H in the figure are isomorphic, using f: a → 1, b → 3, c → 5, d → 2, e → 4.
5 = 5
Both graphs have 5 vertices, and f uses each vertex of H once, so f is a bijection.
ab \mapsto 13 \in E(H)
Edge ab goes to 1–3, an edge of H.
bc \mapsto 35 \in E(H)
Edge bc goes to 3–5.
cd \mapsto 52 \in E(H)
Edge cd goes to 5–2.
de \mapsto 24 \in E(H)
Edge de goes to 2–4.
ea \mapsto 41 \in E(H)
Edge ea goes to 4–1.
|E(G)| = |E(H)| = 5
All 5 edges of G land on the 5 edges of H, so non-edges go to non-edges too.
Answer: f is an isomorphism, so G \cong H. Both graphs are a single 5-cycle; the star just draws it with crossings.
Example 3: Different degree sequences
G is the path a–b–c–d–e. H has vertices 1 to 5 and edges {1, 2}, {1, 3}, {1, 4} and {4, 5}. Are they isomorphic?
5 = 5,\ 4 = 4
Both have 5 vertices and 4 edges, so those invariants agree.
1,\ 2,\ 2,\ 2,\ 1
Degrees of a, b, c, d, e in G.
3,\ 1,\ 1,\ 2,\ 1
Degrees of 1, 2, 3, 4, 5 in H.
\deg(1) = 3
H has a vertex of degree 3, and G has none.
Answer: not isomorphic. An isomorphism would have to send vertex 1 of H to a vertex of degree 3 in G, and there is none.
Example 4: Same degrees, still different
G is the 6-cycle 1–2–3–4–5–6–1. H is two separate triangles, a–b–c and d–e–f. Are they isomorphic?
6 = 6,\ 6 = 6
Both have 6 vertices and 6 edges.
2,\ 2,\ 2,\ 2,\ 2,\ 2
Every vertex in both graphs has degree 2: the degree sequences match.
\text{triangles: } 0 \ne 2G has no 3-cycle; H has two.
\text{G connected, H not}G has a path between any two vertices; H has no path from a to d.
Answer: not isomorphic, even though the vertex counts, edge counts and degree sequences all agree.
Example 5: Two network designs (word problem)
Network X links servers P, Q, R, S with cables PQ, QR, RS, SP and PR. Network Y links servers 1, 2, 3, 4 with cables 12, 13, 14, 23 and 34. Do the two networks have the same design?
3,\ 2,\ 3,\ 2
Degrees of P, Q, R, S in X.
3,\ 2,\ 3,\ 2
Degrees of 1, 2, 3, 4 in Y: the sequences match.
P \mapsto 1,\ R \mapsto 3
Send the degree-3 servers to the degree-3 servers.
Q \mapsto 2,\ S \mapsto 4
Send the degree-2 servers to the degree-2 servers.
PQ \mapsto 12,\ QR \mapsto 23
Both images are cables of Y.
RS \mapsto 34,\ SP \mapsto 41
Both images are cables of Y.
PR \mapsto 13
The last cable also maps to a cable of Y; all 5 of X’s 5 cables match.
Answer: yes. The map P → 1, Q → 2, R → 3, S → 4 is an isomorphism, so the networks have the same design: a 4-cycle with one cross-link.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Stopping when invariants match | “Same counts and degrees, so the hexagon and two triangles are isomorphic.” | Matching invariants never prove isomorphism; give a bijection and check every edge. |
| Checking only that f is a bijection | “f matches 5 vertices to 5 vertices, so it is an isomorphism.” | Also check that every edge maps to an edge. |
| Matching vertices of different degrees | Sending a degree-3 vertex to a degree-2 vertex | An isomorphism keeps degrees; match degree to degree. |
| Judging by the drawing | “The star has crossings and the pentagon does not, so they differ.” | Positions and crossings are not part of the graph. |
| Filling in half the matrix | A 1 in row 1, column 2 but a 0 in row 2, column 1 | For a simple graph, a_{ij} = a_{ji}: the matrix is symmetric. |
| Reordering only the rows | Swapping two rows of A to relabel two vertices | Relabeling swaps the matching rows and the matching columns. |
Related ideas
Isomorphism with matrices
Relabeling the vertices permutes the rows and the columns of the adjacency matrix in the same way. In matrix form, G \cong H exactly when A_H = P A_G P^T for some permutation matrix P: multiplying by P on the left permutes the rows, and multiplying by its transpose on the right permutes the columns the same way.
Counting walks
The entry in row i, column j of A^k counts the walks of length k from v_i to v_j (see matrix multiplication). On the diagonal of A^2 you get the degrees: in Example 1, the (3, 3) entry of A^2 is 3.
Isomorphism is an equivalence relation
Every graph is isomorphic to itself, the inverse of an isomorphism is an isomorphism, and a composition of two isomorphisms is one. So “is isomorphic to” is an equivalence relation on graphs, and its classes are the different shapes a graph can have.
Practice problems
- Write the adjacency matrix of the graph with vertices 1, 2, 3, 4 and edges {1, 2}, {1, 4}, {2, 3} and {2, 4}, and give its degrees.
- A graph has the adjacency list a: b, c; b: a; c: a, d; d: c. How many edges does it have, and what is its degree sequence?
- List the edges of the graph whose adjacency matrix has rows (0, 1, 1, 1), (1, 0, 0, 0), (1, 0, 0, 1) and (1, 0, 1, 0).
- G is the path a–b–c–d. H has one vertex joined to three others and no other edges. Are G and H isomorphic?
- G is the 4-cycle a–b–c–d–a, and H has edges {1, 3}, {3, 2}, {2, 4} and {4, 1}. Show that f: a → 1, b → 3, c → 2, d → 4 is an isomorphism.
- For networks X and Y in Example 5, is f: P → 2, Q → 1, R → 4, S → 3 an isomorphism?
- G has edges ab, bc, ca, cd and de. H has edges 12, 23, 34, 41 and 15. Are they isomorphic?
- Two graphs each have 7 vertices. G has 10 edges and H has 11. Can they be isomorphic?
- G has edges ab, ac, bc and cd. H has edges 12, 23, 24 and 34. Find an isomorphism from G to H.
- A program tests whether two 6-vertex networks are the same by trying every one-to-one matching of their vertices. How many matchings does it try? If both degree sequences are 3, 3, 2, 2, 2, 2 and it only tries matchings that keep degrees, how many does it try?
Show answers
1.
1: 2, 4;\ \ 2: 1, 3, 4
List the neighbors of 1 and 2.
3: 2;\ \ 4: 1, 2
List the neighbors of 3 and 4.
A = \begin{bmatrix} 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 1 \\ 0 & 1 & 0 & 0 \\ 1 & 1 & 0 & 0 \end{bmatrix}Put a 1 for each neighbor.
2,\ 3,\ 1,\ 2
Row sums.
Answer: the matrix above; degrees 2, 3, 1, 2
2.
2 + 1 + 2 + 1 = 6
Add the list lengths (the degrees).
6 \div 2 = 3
Each edge appears in two lists.
Answer: 3 edges (ab, ac, cd); degrees 2, 1, 2, 1
3.
\{1, 2\},\ \{1, 3\},\ \{1, 4\}Row 1 has 1s in columns 2, 3 and 4.
\{3, 4\}Row 3 has a 1 in column 4 (rows 2 and 4 repeat edges already listed).
Answer: {1, 2}, {1, 3}, {1, 4}, {3, 4}
4.
1,\ 2,\ 2,\ 1
Degrees in G.
3,\ 1,\ 1,\ 1
Degrees in H.
Answer: no; H has a vertex of degree 3 and G does not
5.
ab \mapsto 13,\ bc \mapsto 32
Both are edges of H.
cd \mapsto 24,\ da \mapsto 41
Both are edges of H.
4 = 4
All 4 edges of G land on the 4 edges of H, and f is a bijection.
Answer: f is an isomorphism
6.
PQ \mapsto 21,\ QR \mapsto 14
Both are cables of Y.
RS \mapsto 43,\ SP \mapsto 32
Both are cables of Y.
PR \mapsto 24
Y has no cable 2–4.
Answer: no; this f fails on cable PR (even though another map works)
7.
3,\ 2,\ 2,\ 2,\ 1
Sorted degrees of G (c has 3; e has 1).
3,\ 2,\ 2,\ 2,\ 1
Sorted degrees of H (1 has 3; 5 has 1): they match.
abc \text{ is a triangle}G has a 3-cycle.
\text{no triangle in H}H is the 4-cycle 1–2–3–4 plus the edge 1–5.
Answer: not isomorphic
8.
10 \ne 11
An isomorphism keeps the number of edges.
Answer: no
9.
c \mapsto 2,\ d \mapsto 1
c and 2 have degree 3; d and 1 have degree 1.
a \mapsto 3,\ b \mapsto 4
The remaining degree-2 vertices.
ab \mapsto 34,\ ac \mapsto 32
Both are edges of H.
bc \mapsto 42,\ cd \mapsto 21
Both are edges of H; all 4 edges match.
Answer: a → 3, b → 4, c → 2, d → 1
10.
6! = 6 \cdot 5 \cdot 4 \cdot 3 \cdot 2 \cdot 1
Count the bijections (see permutations).
6! = 720
Multiply.
2! \cdot 4! = 2 \cdot 24
Match the 2 degree-3 vertices among themselves and the 4 degree-2 vertices among themselves.
2 \cdot 24 = 48
Multiply.
Answer: 720 matchings, or 48 when degrees must match
Graph isomorphism FAQ
How do you prove two graphs are isomorphic?
Give a bijection between their vertex sets and check that every edge of the first graph maps to an edge of the second. If the edge counts are equal, that is enough.
How do you show two graphs are not isomorphic?
Find an invariant they disagree on, such as the number of edges, the degree sequence, the number of triangles or connectedness.
Is the same degree sequence enough for isomorphism?
No. A 6-cycle and two separate triangles both have every degree equal to 2, but they are not isomorphic.
What is an adjacency matrix?
It is a square table with a 1 in row i, column j when vertices i and j are joined, and a 0 otherwise. For a simple graph it is symmetric with 0s on the diagonal.
Summary
- Adjacency lists and adjacency matrices write a graph down; row sums of the matrix are the degrees.
- G and H are isomorphic when a bijection of their vertices sends edges to edges and non-edges to non-edges.
- Isomorphic graphs share every invariant: vertex and edge counts, degree sequence, triangles, connectedness.
- A difference in any invariant proves the graphs are not isomorphic.
- Matching invariants never prove isomorphism; give the bijection and check every edge.
Previous lesson: Graph Theory Basics
Next lesson: Bipartite Graphs
Back to the Discrete Math Index