TL;DR
Two graphs are isomorphic when you can rename the vertices of one so that it becomes exactly the other. The renaming is a bijection between the two vertex sets, and it must keep every connection and every missing connection. Isomorphic graphs are the same structure, even when their drawings look different.
Builds on: Graph, Bijective Function · Leads to: Weisfeiler-Lehman Test, graph neural networks
Where it's used
Chemistry. A molecule is drawn as a graph, with atoms as vertices and bonds as edges. Two diagrams that differ only in layout describe the same molecule when they are isomorphic. Chemists comparing a new compound against a database need exactly this test to decide whether the compound is already known.
Checking that two networks have the same shape. A transport planner may receive two maps of the same bus network, drawn by two agencies with different stop labels and different layouts. An isomorphism between the two maps shows which stop on one corresponds to which stop on the other, and that the routes match.
Graph neural networks. A graph neural network should give the same answer for a graph whatever order its vertices are listed in. The tests used to study the power of these networks ask when two graphs are different, and a widely used one, the Weisfeiler-Lehman test, is a fast but incomplete attempt at the isomorphism question.
How it works
Take two graphs with four vertices each. Graph has vertices and edges , , , . Graph has vertices and edges , , , . Both are a loop of four vertices, but the labels are different. We ask whether they are the same shape.
- Propose a renaming. Let send , , and . This is a bijection: the four outputs are distinct and cover .
- Send each edge of through the renaming. The edge becomes , which is an edge of . The edge becomes , also an edge of .
- Continue with the other two. The edge becomes , and becomes . Both are edges of .
- Check the reverse direction. has four edges and all four land on edges of . also has exactly four edges, so every edge of is the image of an edge of . Nothing extra is present on either side.
- Because the renaming is a bijection and it maps the edges of exactly onto the edges of , the two graphs are isomorphic. The renaming is the witness.
The renaming can be drawn as a picture. Both diagrams below are the same loop of four vertices.
flowchart LR
subgraph G
v1((1)) --- v2((2))
v2 --- v3((3))
v3 --- v4((4))
v4 --- v1
end
flowchart LR
subgraph H
va((a)) --- vc((c))
vc --- vb((b))
vb --- vd((d))
vd --- va
end
Run the same check on a graph that is not isomorphic to these. A triangle has three vertices, each joined to the other two, so it has three edges. A path with three vertices in a row has only two edges. No renaming of the vertices can turn three edges into two, so the triangle and the path are not isomorphic. The edge count is a quick test: if the counts differ, stop.
The math
A graph has a vertex set and an edge set , where each edge is a pair of distinct vertices. A graph has vertex set and edge set .
An isomorphism from to is a bijection such that for every pair of distinct vertices in ,
The graphs and are isomorphic, written , when such a exists. The symbol means "if and only if". In words: and are joined in exactly when their images are joined in . The condition works in both directions, so a bijection that keeps only the edges and not the non-edges is not enough.
Step 1 in symbols
For the example, , , and . The four outputs are distinct and exhaust , so is a bijection.
Step 2 in symbols
For each edge of , apply to both ends:
Each image is in . This gives the forward direction of the definition for these pairs.
Step 4 in symbols
Both edge sets have four elements. The map from the edges of to the edges of that the renaming induces is injective, because is a bijection, and the four images are four distinct edges of . Since has only four edges, they are all of . So the condition holds in the reverse direction too.
A necessary condition
Any isomorphism preserves the number of edges, and it preserves the number of edges at each vertex. If , then and have the same degree, where the degree of a vertex is the number of edges touching it. Degrees give a fast way to reject a pair: if the sorted list of degrees differs, the graphs are not isomorphic. Matching degrees do not prove isomorphism, as the common mistakes section shows.
Worked examples
Graph is the path , with edges and . Graph is the path , with edges and . Find an isomorphism.
- Both graphs have three vertices and two edges, so try a bijection that sends the middle vertex to the middle vertex: .
- Send the ends to the ends: and . This is a bijection onto .
- Apply to the edges of . The edge becomes , an edge of . The edge becomes , also an edge of .
- The pair is not an edge of , and its image is not an edge of . So the non-edges match as well.
Interpretation: a path is a path however you name its vertices. The only thing that matters is which vertex sits in the middle.
Use the two graphs from the walkthrough: with edges , , , , and with edges , , , .
- Count the edges: has four, and so does .
- Check degrees. In , every vertex touches exactly two edges. In , every vertex also touches exactly two edges. The degree lists match.
- Use the bijection from the walkthrough, which sends , , , .
- Each of the four edges of maps to an edge of , and the four images are all of 's edges.
- The non-edges also match. In , the pair is a non-edge, and its image is also a non-edge in .
Interpretation: both graphs are the cycle of length four, so the relabelling works. The check on non-edges in step 5 is the part people forget.
Map has a central stop joined to , and , and a route . Map has a central stop joined to , and , and a route . The two agencies drew them differently. Are they the same network?
- List the edges of : , , and . That is four edges.
- List the edges of : , , and . That is also four edges.
- Match the hubs and the degree-two stops. Let , , and . This is a bijection.
- Apply to the edges of . becomes , becomes , becomes , and becomes . Those are exactly the four edges of .
- The two maps are isomorphic. Every route on one map corresponds to exactly one route on the other.
Try it: a third map has four stops in a row, , with three routes. Is isomorphic to ? Answer: no. has three edges and has four. No bijection can keep the edges when the counts differ, so the test fails at the first step.
Common mistakes and tradeoffs
Same number of vertices and edges means isomorphic. It is tempting to think that equal counts settle the question. In fact they do not. Take two disjoint triangles and a single six-vertex loop. Both have six vertices and six edges, and every vertex in both has degree two. But the two triangles fall apart into two pieces, while the loop is one piece. A bijection cannot join pieces that do not match, so the graphs are not isomorphic. Matching counts are a necessary condition, not a sufficient one.
A different drawing means a different graph. It is tempting to judge graphs by how they look on the page. In fact the drawing carries no information: moving a vertex, straightening a curved edge or swapping labels does not change the graph. Two drawings that look different may be isomorphic, and two drawings that look alike may not be.
Keeping only the edges is enough. It is tempting to check only that each edge of maps to an edge of . In fact the definition is an if-and-only-if, so non-edges must match too. Without the reverse check, a graph with fewer edges could appear to map into a graph with more.
When to use it. Use an isomorphism test when the labels are arbitrary and you care only about structure, such as comparing molecules or networks, or deduplicating a list of graphs. Use the quick tests first: the vertex count, the edge count and the sorted degree list reject most non-matches at once.
Alternatives. No general method is known to decide isomorphism in polynomial time for all graphs, and the problem is not known to be NP-complete. In practice, programs use invariants that are fast to compute and stronger than degree, such as the Weisfeiler-Lehman test. A test that says "not isomorphic" is always correct when it fires. A test that says "maybe isomorphic" is only a suggestion, and a full search is needed for a proof.
History
As graph theory developed, isomorphism became the standard notion of "same structure" for graphs, and the bijection in its definition is the same idea of exact pairing used for sets.
Isomorphism is also a hard computational question. Once a bijection is given it can be checked quickly, but no polynomial-time algorithm for all graphs is known. In 2015 László Babai announced an algorithm that runs in quasi-polynomial time, which is much faster than a brute-force search over all bijections but slower than polynomial time.
Recap
- A Graph is a set of vertices joined by edges.
- An isomorphism between two graphs is a bijection between their vertex sets that keeps every edge and every non-edge.
- Equal vertex counts, edge counts and degree lists are necessary for isomorphism, but they do not prove it.
- To show two graphs are isomorphic, give the bijection and check every edge in both directions.
- Stronger tests such as the Weisfeiler-Lehman Test can often reject a pair quickly, and they are the bridge to the question of what graph neural networks can and cannot tell apart.
Check yourself
QuestionAre the paths and isomorphic? The first has edges , , ; the second has edges , , .Show answer
Yes. Use the map , , , . It is a bijection. The three edges of the first path map to , and , which are exactly the edges of the second. Both paths have three edges, so no edge is left out on either side.
QuestionA graph has five vertices and six edges. Can a graph with five vertices and five edges be isomorphic to ? Give the reason in one sentence.Show answer
No. An isomorphism is a bijection that maps edges to edges and non-edges to non-edges, so it preserves the number of edges. Six edges cannot correspond to five.
QuestionGive the degree of each vertex of the triangle on and of the path , and explain whether the degree lists settle whether the two graphs are isomorphic.Show answer
In the triangle, each vertex touches two edges, so the degrees are . In the path, and have degree and has degree , so the degrees are . The lists differ, so the graphs are not isomorphic. Here the degree test was enough, but in general matching degree lists do not prove isomorphism.
QuestionA chemist draws two diagrams of a molecule with the atoms labelled differently and the diagrams laid out differently. Explain how an isomorphism between the two diagrams shows that they describe the same molecule.Show answer
Each diagram is a graph whose vertices are atoms and whose edges are bonds. An isomorphism is a bijection from the atoms of one diagram to the atoms of the other that sends every bond to a bond and every non-bond to a non-bond. Such a bijection shows that each atom in one diagram corresponds to exactly one atom in the other, with the same bonds between them. The layout and labels do not matter, so the two diagrams describe the same connections.