Graph isomorphism: when two drawings are the same graph
Two drawings of a network look nothing alike. How do we prove they show the same network, and how do we prove they do not?
Where you are 4 in Graphs, vertices and edges
Why this exists
A drawing is only one way to show a graph, and two drawings of one graph can share nothing visible. Before anyone can say “there are 11 graphs on four vertices” or “this network is a cycle”, “the same graph” needs a precise meaning: a renaming of the vertices that carries edges to edges. The harder half is proving that no such renaming exists.
Definition
This lesson takes two days. Day 1 is the definition, proving graphs isomorphic, and invariants that prove they are not (Examples 1 to 3). Day 2 is isomorphism as an equivalence relation, counting graphs up to isomorphism, complements and automorphisms (Examples 4 to 6).
The notation is that of Degree, the handshake lemma and complete graphs and Walks, paths, cycles and connected graphs: graphs are simple, G = (V, E), uv is the edge joining u and v, and \overline{G} is the complement. Let G_1 = (V_1, E_1) and G_2 = (V_2, E_2) be graphs. An isomorphism from G_1 to G_2 is a bijection f : V_1 \to V_2 (one-to-one and onto, One-to-one, onto and bijective functions) such that for all u, v \in V_1,
- G_1 and G_2 are isomorphic, written G_1 \cong G_2, if there is an isomorphism from G_1 to G_2.
- An automorphism of G is an isomorphism from G to itself; \operatorname{Aut}(G) is the set of them. The identity map is always one.
- An invariant is a number or property that is the same for any two isomorphic graphs.
- The graphs isomorphic to G form its isomorphism class; counting graphs up to isomorphism counts classes. A labeled graph on a set S is a graph whose vertex set is S; two labeled graphs on S are equal only when their edge sets are equal.
- G is self-complementary if G \cong \overline{G}.
“Exactly when” asks two things: edges go to edges, and non-edges go to non-edges. When the edge counts are equal, the first is enough (Result 1), which is how isomorphisms are checked in practice.
Intuition
Tsvetan makes wire-frame sculptures: joints are vertices and rods are edges. A frame can be bent into very different shapes, but which joints a rod connects never changes, and that list is the graph. Figure 1 shows two sketches of one six-joint, nine-rod frame; the chords on the right cross at points that are not joints. An isomorphism renames the joints of one sketch so that its rod list becomes the other’s. To prove two graphs are not isomorphic, trying all 6! = 720 renamings is hopeless; instead find an invariant, something every isomorphism keeps, on which they differ.
Results
1. Edges correspond. If f is an isomorphism from G_1 to G_2, then uv \mapsto f(u)f(v) is a bijection from E_1 to E_2, so \lvert V_1 \rvert = \lvert V_2 \rvert and \lvert E_1 \rvert = \lvert E_2 \rvert. Conversely, if \lvert E_1 \rvert = \lvert E_2 \rvert and a bijection f : V_1 \to V_2 sends every edge of G_1 to an edge of G_2, then f is an isomorphism.
2. Degrees and neighbors. An isomorphism f maps the neighbors of v one-to-one onto the neighbors of f(v). So \deg(f(v)) = \deg(v), isomorphic graphs have the same degree sequence, and the list of degrees of the neighbors of v equals that of f(v).
3. Routes. An isomorphism carries each walk (v_0, \ldots, v_k) of G_1 to the walk (f(v_0), \ldots, f(v_k)) of G_2, and every walk of G_2 comes from exactly one walk of G_1. Paths go to paths and cycles to cycles of the same length. So isomorphic graphs have the same number of cycles of each length and the same number of components.
4. Invariants prove difference. If an invariant differs on G_1 and G_2, then G_1 \not\cong G_2. Agreement proves nothing.
5. An equivalence relation. G \cong G; if G_1 \cong G_2 then G_2 \cong G_1; if G_1 \cong G_2 and G_2 \cong G_3 then G_1 \cong G_3. So isomorphism splits any set of graphs into Relations, equivalence classes and partitions, the isomorphism classes.
6. Complements. A bijection is an isomorphism from G to H exactly when it is an isomorphism from \overline{G} to \overline{H}. So G \cong H exactly when \overline{G} \cong \overline{H}.
7. Self-complementary graphs. A self-complementary graph on n vertices has \displaystyle \frac{n(n-1)}{4} edges, so n \equiv 0 or n \equiv 1 \pmod 4. The converse, that every such n has one, is stated here without proof.
8. Labelings. If G has n vertices, exactly \displaystyle \frac{n!}{\lvert \operatorname{Aut}(G) \rvert} labeled graphs on \{1, 2, \ldots, n\} are isomorphic to G.
9. Small counts. A set of n vertices carries 2^{\binom{n}{2}} labeled graphs, since each pair is an edge or not. Up to isomorphism there are 4 graphs on 3 vertices, 11 on 4 (against 2^6 = 64 labeled ones) and 34 on 5; the last count is stated without proof.
10. No fast test is known. No method is known that decides whether any two graphs are isomorphic within a number of steps bounded by a fixed power of the number of vertices. This is stated without proof.
Why it is true
Result 1. Proof. For uv \in E_1, f(u)f(v) \in E_2 by the definition. If \{f(u), f(v)\} = \{f(x), f(y)\} then \{u, v\} = \{x, y\}, as f is one-to-one; so the edge map is one-to-one. Each edge of G_2 is f(u)f(v) for some u, v, as f is onto, and then uv \in E_1 by “exactly when”; so it is onto. For the converse, the map on pairs is one-to-one, so the \lvert E_1 \rvert edges of G_1 go to \lvert E_2 \rvert different edges, all of E_2. A non-edge of G_1 cannot then go to an edge, since that edge is already the image of an edge. \square
Result 2. Proof. u is a neighbor of v exactly when f(u) is a neighbor of f(v), and every vertex of G_2 is some f(u). So f maps the neighbors of v onto those of f(v), one-to-one as f is. As v runs over V_1, f(v) runs over V_2 once each, so the degree lists agree, and each neighbor u of v is matched with the neighbor f(u) of f(v) of the same degree. \square
Result 3. Proof. Consecutive vertices of a walk are adjacent, and f keeps adjacency, so the image is a walk of the same length. A walk (w_0, \ldots, w_k) of G_2 is the image of (f^{-1}(w_0), \ldots, f^{-1}(w_k)), a walk of G_1 by “exactly when”, and of no other, as f is one-to-one. For the same reason the image repeats a vertex exactly where the walk does, so paths go to paths and cycles to cycles. Two vertices are joined exactly when their images are, so f maps each component onto a component. \square
Result 4 is the contrapositive of “if G_1 \cong G_2, the invariant agrees” (A conditional and its contrapositive). Example 3 shows agreement proving nothing.
Result 5. Proof. The identity map is an isomorphism. If f is an isomorphism from G_1 to G_2, then f^{-1} is a bijection (Composing functions between sets, and when an inverse exists), and for x, y \in V_2, xy \in E_2 exactly when f(f^{-1}(x))f(f^{-1}(y)) \in E_2, exactly when f^{-1}(x)f^{-1}(y) \in E_1. If g is an isomorphism from G_2 to G_3, then g \circ f is a bijection and uv \in E_1 exactly when f(u)f(v) \in E_2, exactly when g(f(u))g(f(v)) \in E_3. \square
Result 6. Proof. Let f be a bijection and u \ne v, so f(u) \ne f(v). The statement “uv \in E(G) exactly when f(u)f(v) \in E(H)” is equivalent to its negated form “uv \notin E(G) exactly when f(u)f(v) \notin E(H)”, and for distinct vertices “not an edge” means “an edge of the complement”. So the condition for G and H holds exactly when it holds for \overline{G} and \overline{H}. \square
Result 7. Proof. If G \cong \overline{G}, Result 1 gives \lvert E(G) \rvert = \lvert E(\overline{G}) \rvert, and the two add to \binom{n}{2} (Degree, the handshake lemma and complete graphs, Result 6). So \displaystyle \lvert E(G) \rvert = \frac{n(n-1)}{4} and 4 \mid n(n - 1). One of n and n - 1 is odd and shares no factor with 4, so 4 divides the other: 4 \mid n or 4 \mid n - 1. \square
Result 8. Proof. Let S = \{1, \ldots, n\}. A bijection g : V \to S turns G into the labeled graph g(G) on S with edges g(u)g(v) for uv \in E, and g is an isomorphism onto it. Every labeled graph on S isomorphic to G is g(G) for some g, namely an isomorphism. Fix h. Then g(G) = h(G) exactly when h^{-1} \circ g maps G onto itself, that is, when g = h \circ \alpha for some \alpha \in \operatorname{Aut}(G). So the n! bijections fall into groups of \lvert \operatorname{Aut}(G) \rvert, one group for each labeled copy. \square
Result 9. The counts 11 and 4 are Example 4 and Exercise 6.
Worked examples
Day 1: proving two sketches show one frame
Prove that the graphs of Figure 1 are isomorphic. G_1 has vertices a, b, c, p, q, r and edges ab, bc, ca, pq, qr, rp, ap, bq, cr. G_2 has vertices 1, \ldots, 6 and edges 12, 23, 13, 45, 56, 46, 16, 25, 34.
SolutionBoth have 6 vertices, 9 edges and every degree 3. That is needed (Results 1 and 2) but proves nothing; an isomorphism has to be produced. Use what it must keep. By Result 3, triangles go to triangles. In G_1 the triangles are abc and pqr: a triangle through a rung such as ap would need a common neighbor of a and p, but a has neighbors b, c, p and p has q, r, a. In G_2 the triangles are 123 and 456, and the edges 16, 25, 34 join them.
Try f(a) = 1, f(b) = 2, f(c) = 3. Rungs must go to rungs, so p, joined to a, goes to 6, joined to 1: f(p) = 6, and likewise f(q) = 5, f(r) = 4. Check every edge: ab, bc, ca, pq, qr, rp, ap, bq, cr go to 12, 23, 31, 65, 54, 46, 16, 25, 34. All nine images are edges of G_2 and the edge counts are equal, so f is an isomorphism by Result 1, and G_1 \cong G_2.
Day 1: a frame with no triangle
Tsvetan’s third sketch (Figure 2) has joints 0, 1, \ldots, 5, with i joined to i + 1, i - 1 and i + 3, modulo 6. Show it is not isomorphic to the frame of Figure 1.
The first invariants agree: 6 vertices, 9 edges, every degree 3, connected. Look at cycles. Each edge joins numbers differing by 1, 3 or 5, all odd, and since 6 is even, reducing modulo 6 keeps parity. So every edge joins an even vertex to an odd one. Suppose x, y, z formed a triangle. Then x and y have opposite parity, as do y and z, so x and z have the same parity and are not adjacent, a contradiction. This graph has no cycle of length 3, and Figure 1 has two. By Result 3 the graphs are not isomorphic. Graphs whose edges all run between two sides return in Bipartite graphs.
Day 1: same degrees, same cycle, still different
In Figure 3, G has edges ab, bc, cd, da, ae, bf and H has edges 12, 23, 34, 41, 15, 36. Show that G \not\cong H.
Much agrees: 6 vertices, 6 edges, degree sequence (3, 3, 2, 2, 1, 1), both connected. Each has exactly one cycle, of length 4: a vertex of degree 1 lies on no cycle, so a cycle stays inside the square, whose only cycle is the square itself.
The difference: in G the two vertices of degree 3, a and b, are adjacent; in H the two vertices of degree 3, 1 and 3, are not. Suppose f were an isomorphism. By Result 2, \{f(a), f(b)\} = \{1, 3\}, and since ab is an edge, 13 would be an edge of H. It is not, so no isomorphism exists. In the language of Result 2: the neighbors of a have degrees 3, 2, 1, while the neighbors of 1 and of 3 have degrees 2, 2, 1. Degree sequence and cycle lengths together do not decide isomorphism.
Day 2: every graph on four vertices
Find all graphs on four vertices up to isomorphism, and reconcile the count with the 2^6 = 64 labeled graphs on \{1, 2, 3, 4\}.
SolutionSort by the number of edges k, an invariant. By Result 6, complementing matches the classes with k edges one-to-one with the classes with 6 - k edges, so it is enough to find k \le 3.
k = 0 and k = 1 give one class each. For k = 2 the edges share an end or not, two classes with degree sequences (2, 1, 1, 0) and (1, 1, 1, 1). For k = 3 the degrees add to 6. If a vertex has degree 3, it is joined to all others (graph 6). If not, and there is a triangle, the fourth vertex is isolated (graph 5). Otherwise every degree is at most 2 and the sequence is (2, 2, 2, 0), which is a triangle, or (2, 2, 1, 1). In the last case, if the degree-2 vertices x, y were not adjacent, both would be joined to both other vertices, giving those degree 2. So xy is an edge and x, y each have one more neighbor, different ones: a path through all four vertices (graph 7). Graphs 5, 6, 7 have different degree sequences, so they are three classes. Complements give 2, 1, 1 classes for k = 4, 5, 6, and the total is 1 + 1 + 2 + 3 + 2 + 1 + 1 = 11 (Figure 4).
Now count labeled copies by Result 8. For the path (w, x, y, z), an automorphism keeps the ends \{w, z\}, and once it fixes or swaps them the rest is forced, so \lvert \operatorname{Aut} \rvert = 2 and there are \displaystyle \frac{24}{2} = 12 labeled paths, the 24 orders of 1, 2, 3, 4 read in pairs from either end. In the same way graphs 1 to 11 have 24, 4, 8, 2, 6, 6, 2, 8, 2, 4, 24 automorphisms, so 1, 6, 3, 12, 4, 4, 12, 3, 12, 6, 1 labeled copies. With k edges there must be \binom{6}{k} labeled graphs: 3 + 12 = 15 = \binom{6}{2}, 4 + 4 + 12 = 20 = \binom{6}{3}, and the row adds to 64.
Day 2: a cycle that is its own complement
Show that C_5 is self-complementary. How many edges would a self-complementary graph on 8 vertices have, and is there one on 6 vertices?
C_5 has vertices 0, \ldots, 4 with i joined to i \pm 1 modulo 5. Its complement has the other 10 - 5 = 5 pairs, those differing by 2 or 3, that is, i joined to i \pm 2. Try f(i) = 2i \bmod 5, which takes the values 0, 2, 4, 1, 3: a bijection. It sends the edge \{i, i + 1\} to \{2i, 2i + 2\}, a pair differing by 2, an edge of \overline{C_5}. Five edges go to edges, the counts are equal, and Result 1 makes f an isomorphism: the pentagon becomes the star (Figure 5).
On 8 vertices, Result 7 gives \displaystyle \frac{8 \cdot 7}{4} = 14 edges. On 6 vertices it would need \displaystyle \frac{6 \cdot 5}{4} = 7.5 edges, so there is none.
Day 2: counting labeled copies
How many labeled graphs on \{1, 2, 3, 4, 5\} consist of two triangles sharing exactly one vertex? Use Result 8, then count directly.
SolutionCall the triangles cxy and czw. Vertex c alone has degree 4, so every automorphism fixes it and permutes the two edges not at c, xy and zw. It keeps or swaps these two edges, and within each it keeps or swaps the ends; each of the 2 \cdot 2 \cdot 2 = 8 choices keeps the edge set. So \lvert \operatorname{Aut}(G) \rvert = 8 and Result 8 gives \displaystyle \frac{120}{8} = 15.
Directly: choose the shared vertex in 5 ways, then split the other four labels into two pairs in 3 ways (choose the partner of the smallest). That is 5 \cdot 3 = 15, as before.
Boundaries
- Simple graphs. For multigraphs an isomorphism must also match the number of edges between each pair and the loops at each vertex; with that change the results carry over.
- Invariants work one way. A differing invariant proves G_1 \not\cong G_2. Agreement on any list of invariants proves nothing (Example 3); only an isomorphism, produced and checked, proves sameness.
- The drawing is not the graph. Positions, lengths and crossings are not part of G.
- Say which count. “Graphs on four vertices” means 64 labeled graphs on a fixed set or 11 up to isomorphism.
- Stated without proof here: the converse of Result 7, the count 34, and Result 10.
Where this goes next
From here on, graphs are named up to isomorphism: “a path”, “C_5”, “K_4” each mean a class. Invariants become tools: the later lessons on routes, trees, planar graphs and coloring each add one. In Adjacency matrices and their powers, isomorphic graphs have adjacency matrices that differ only by the same reordering of rows and columns.
Exercises
Day 1: isomorphic or not
- G has vertices 1, \ldots, 6 and edges 12, 23, 34, 45, 56, 61, 14. H has vertices a, \ldots, f and edges ab, ad, bc, be, cf, de, ef. Give an isomorphism and check every edge.
- Show that G of Exercise 1 is not isomorphic to C_6 on \{1, \ldots, 6\} with the edge 13 added.
- Which of these are isomorphic? A: edges 12, 23, 34, 45, 51. B: edges ab, bc, ca, cd, de. C: edges pr, rt, tq, qs, sp. Give an isomorphism for each isomorphic pair.
- G is the path (1, 2, 3, 4, 5, 6) and H has vertices a, \ldots, f and edges ab, bc, ca, de, ef. Show they have the same degree sequence, and give two invariants on which they differ.
- G is the 4-cycle (a, b, c, d, a) with the edges ae, ef, fg added; H is the 5-cycle (1, 2, 3, 4, 5, 1) with the edges 16, 67 added. Show they agree in vertices, edges and degree sequence but are not isomorphic, by two different invariants.
Day 2: classes, complements and labelings
- Find all graphs on 3 vertices up to isomorphism, with \lvert \operatorname{Aut} \rvert for each, and check Result 8 against the 2^3 = 8 labeled graphs.
- How many labeled graphs on \{1, \ldots, 6\} are cycles of length 6?
- How many isomorphisms are there from G_1 to G_2 in Figure 1?
- Show that \overline{C_6} is isomorphic to G_1 of Figure 1. Then use Result 6 to give a second proof that Figure 2 is not isomorphic to Figure 1.
- Show that the path on four vertices is self-complementary and is the only self-complementary graph on four vertices.
- The graph with edges ab, bc, ca, ad, be is a triangle with two tails. Show it is self-complementary by giving an isomorphism to its complement.
- For which n from 10 to 20 can a self-complementary graph on n vertices exist? How many edges would one on 12 vertices have?
- How many of the 11 graphs in Figure 4 are connected?
- Use Results 8 and 9 to show, without listing them, that there are at least 9 graphs on five vertices up to isomorphism.
Reasoning
- Let f be an isomorphism from G_1 to G_2. Prove that d(f(u), f(v)) = d(u, v) for all vertices u, v.
- Prove that \lvert \operatorname{Aut}(C_n) \rvert = 2n for every n \ge 3.
- Prove that G and \overline{G} have exactly the same automorphisms.
- Refute with a counterexample: “two graphs with the same degree sequence and the same number of components are isomorphic.” Do not use a graph from this lesson.
- Prove that a self-complementary graph with at least two vertices is connected.
- Prove that if a self-complementary graph is r-regular on n vertices, then n = 2r + 1 and n \equiv 1 \pmod 4.
Answers
- f(1) = b, f(2) = a, f(3) = d, f(4) = e, f(5) = f, f(6) = c. The edges go to ba, ad, de, ef, fc, cb, be, all seven edges of H, so Result 1 applies. Found from the degree-3 vertices 1, 4 and b, e, each pair joined by an edge lying on two 4-cycles.
- Every edge of G joins an odd and an even number, so as in Example 2, G has no triangle. The other graph has the triangle 123. By Result 3 they are not isomorphic.
- A \cong C by 1 \mapsto p, 2 \mapsto r, 3 \mapsto t, 4 \mapsto q, 5 \mapsto s, which sends 12, 23, 34, 45, 51 to pr, rt, tq, qs, sp. B is isomorphic to neither: its degree sequence is (3, 2, 2, 2, 1), theirs (2, 2, 2, 2, 2).
- Both have degree sequence (2, 2, 2, 2, 1, 1) and 5 edges. G has one component, H two (\{a, b, c\} and \{d, e, f\}); H has a triangle, G no cycle at all.
- Both have 7 vertices, 7 edges and degree sequence (3, 2, 2, 2, 2, 2, 1). G has a cycle of length 4 and no other cycle; H has one of length 5 and no other. Also, the vertex of degree 3 is at distance 3 from the vertex of degree 1 in G (a, e, f, g) and at distance 2 in H (1, 6, 7); Exercise 15 makes distance an invariant.
- Four: no edges (\lvert \operatorname{Aut} \rvert = 6, 1 copy), one edge (2, 3 copies), a path of two edges (2, 3 copies), a triangle (6, 1 copy). 1 + 3 + 3 + 1 = 8.
- 60. \lvert \operatorname{Aut}(C_6) \rvert = 12 by Exercise 16, and \displaystyle \frac{720}{12} = 60. Check: list 1 first and read the cycle from 1; the other 5 labels give 5! = 120 orders, each cycle counted twice (two directions).
- 12. An isomorphism sends triangle abc to one of the 2 triangles, a to one of its 3 vertices and b to one of the other 2; c is then forced, and the rungs force p, q, r. Each of the 2 \cdot 3 \cdot 2 = 12 choices sends triangle edges to triangle edges and rungs to rungs, so all are isomorphisms.
- \overline{C_6} joins i and j when they differ by 2, 3 or 4: triangles \{0, 2, 4\} and \{1, 3, 5\} and rungs 03, 14, 25. The map a, b, c, p, q, r \mapsto 0, 2, 4, 3, 5, 1 sends the nine edges of G_1 to 02, 24, 40, 35, 51, 13, 03, 25, 41, all edges. The complement of the Figure 2 graph joins numbers differing by 2 or 4: two disjoint triangles. Since C_6 is connected and two triangles are not, C_6 \not\cong \overline{\text{Figure 2}}, so by Result 6 \overline{C_6} \not\cong Figure 2, that is, Figure 1 \not\cong Figure 2.
- For the path (w, x, y, z) the complement has edges wy, wz, xz, the path (y, w, z, x); f: w \mapsto y, x \mapsto w, y \mapsto z, z \mapsto x sends wx, xy, yz to yw, wz, zx. A self-complementary graph on 4 vertices has \displaystyle \frac{4 \cdot 3}{4} = 3 edges. Of graphs 5, 6, 7 in Figure 4, graphs 5 and 6 are each other’s complements and have different degree sequences, so only the path remains.
- The complement has edges ae, bd, cd, ce, de: triangle cde with tails db and ea. The map a \mapsto d, b \mapsto e, c \mapsto c, d \mapsto b, e \mapsto a sends ab, bc, ca, ad, be to de, ec, cd, db, ea, all five edges.
- n = 12, 13, 16, 17, 20, the n with n \equiv 0 or 1 \pmod 4. For n = 12: \displaystyle \frac{12 \cdot 11}{4} = 33 edges.
- Six: graphs 6 to 11. Graphs 1 to 5 each have an isolated vertex or two separate edges.
- There are 2^{10} = 1024 labeled graphs on five vertices. Each class holds \displaystyle \frac{120}{\lvert \operatorname{Aut} \rvert} \le 120 of them, so k classes hold at most 120k. From 120k \ge 1024, k \ge 8.53\ldots, so k \ge 9. (The true count is 34.)
- By Result 3, walks of length k from u to v correspond one-to-one with walks of length k from f(u) to f(v). So a walk exists for exactly the same lengths, the shortest lengths agree, and if no walk exists on one side none exists on the other, giving \infty on both.
- Rotations i \mapsto i + s and reflections i \mapsto s - i (modulo n) keep differences of \pm 1, so they are 2n automorphisms, all different for n \ge 3 (a rotation equal to a reflection would need 2i constant). Conversely, an automorphism \alpha has n choices for \alpha(0) and, by Result 2, 2 for \alpha(1), a neighbor of \alpha(0). Then \alpha(2) is the neighbor of \alpha(1) other than \alpha(0), and inductively each \alpha(i + 1) is forced. So there are at most 2n.
- Take H = G in Result 6: a bijection of V is an isomorphism from G to G exactly when it is one from \overline{G} to \overline{G}.
- C_3 with C_5 beside it, against two separate copies of C_4: both have 8 vertices, every degree 2 and two components, but only the first has a triangle.
- First, if G is disconnected then \overline{G} is connected: vertices in different components of G are adjacent in \overline{G}, and two in the same component are both adjacent in \overline{G} to any vertex w of another component. Now let G \cong \overline{G}. If G were disconnected, \overline{G} would be connected, and by Result 3 so would G, a contradiction.
- In \overline{G} each vertex has degree n - 1 - r. Isomorphic graphs have equal degrees, so r = n - 1 - r and n = 2r + 1 is odd. Result 7 gives n \equiv 0 or 1 \pmod 4, and odd leaves n \equiv 1 \pmod 4. (C_5 is the case r = 2.)