Masterclass: Graph Isomorphism – The Art of Structural Twins
Welcome to modern Graph Theory! Today, we are solving a classic puzzle: How do we know if two seemingly different networks are actually identical in structure?
Imagine you are an intelligence analyst tracking two different covert networks.
- Network G operates in London with operatives named Alice, Bob, and Charlie.
- Network H operates in Tokyo with operatives named 1, 2, and 3.
On paper, they look completely different. Different names, different cities, drawn on different maps. But as you analyze their communication logs, you notice something fascinating: Alice only talks to Bob, and Bob talks to Charlie. In Tokyo, Agent 1 only talks to Agent 2, and Agent 2 talks to Agent 3.
Despite the different labels, these two networks are structurally identical. In Computer Science, we call this structural identity Graph Isomorphism.
1. What is Graph Isomorphism?
The word Isomorphism comes from Ancient Greek:
- Iso = Same / Equal
- Morph = Shape / Form
Two graphs are isomorphic if they share the exact same structural connections, regardless of how they are drawn or what their vertices are labeled.
The Core Principle
Labels do not matter. Position on a screen does not matter. Only the connections matter.
2. The Formal Mathematical Definition
Let's translate our intuition into rigorous Computer Science notation.
Two graphs and are isomorphic (written as ) if and only if there exists a bijection (a perfect 1-to-1 mapping) from the vertex set of to the vertex set of :
such that for every pair of vertices :
Deconstructing the Formula
- and : The set of vertices (nodes) in Graph and Graph .
- Bijection (): A function where every node in pairs up with exactly one unique node in , leaving no node behind.
- Adjacency Preservation: If there is an edge between and in , there MUST be an edge between their mapped partners and in . If there is NO edge between and in , there MUST NOT be an edge between and in .
3. Visualizing Isomorphism
Let's look at our London vs. Tokyo spy network visually:
graph LR
subgraph Graph G (London)
A[A: Alice] --- B[B: Bob]
B --- C[C: Charlie]
end
subgraph Graph H (Tokyo)
1[1: Agent 1] --- 2[2: Agent 2]
2 --- 3[3: Agent 3]
end
The Mapping Function
We can define our bijection as follows:
Verifying Adjacency Preservation
- Edge exists in Edge exists in . (Matches!)
- Edge exists in Edge exists in . (Matches!)
- No edge in No edge in . (Matches!)
Because the mapping is bijective and preserves all connections, .
4. The Detective's Checklist: Graph Invariants
How do you quickly prove two massive graphs are NOT isomorphic? You look for Graph Invariants.
An invariant is a property of a graph that remains unchanged under isomorphism. If two graphs differ in even one invariant, they cannot be isomorphic!
Key Invariants to Check:
- Vertex Count (): Both graphs must have the same number of nodes.
- Edge Count (): Both graphs must have the same number of connections.
- Degree Sequence: A sorted list of vertex degrees (the number of edges connected to each vertex).
⚠️ CRITICAL WARNING: Having matching invariants is necessary, but NOT sufficient!
The Trap: Identical Invariants, Different Graphs
Consider two graphs, and , each with 6 vertices and 6 edges, where every vertex has a degree of 2:
- : A single connected ring of 6 vertices (a 6-cycle, ).
- : Two separate, disconnected triangles (two 3-cycles, ).
Both have:
- 6 Vertices
- 6 Edges
- Degree sequence:
[2, 2, 2, 2, 2, 2]
Are they isomorphic? No! is a single connected piece, while has 2 connected components. Connectedness is another invariant!
5. Algorithm: Checking Isomorphism in Pseudocode
To verify if two graphs are isomorphic programmatically, we can first check basic invariants as a fast-fail mechanism, then attempt to find a valid node mapping.
def are_isomorphic(G, H): # Step 1: Quick invariant checks if len(G.vertices) != len(H.vertices): return False if len(G.edges) != len(H.edges): return False if sorted(G.degree_sequence()) != sorted(H.degree_sequence()): return False # Step 2: Search for an adjacency-preserving bijection f # (Using brute-force permutation matching for demonstration) import itertools nodes_G = list(G.vertices) nodes_H = list(H.vertices) for perm in itertools.permutations(nodes_H): mapping = dict(zip(nodes_G, perm)) # Check if this mapping preserves adjacency valid = True for u in nodes_G: for v in nodes_G: has_edge_in_G = G.has_edge(u, v) has_edge_in_H = H.has_edge(mapping[u], mapping[v]) if has_edge_in_G != has_edge_in_H: valid = False break if not valid: break if valid: return True # Found a valid mapping! return False # No valid mapping exists6. Mini Practice Question
Let's test your understanding with a classic exam problem!
Question:
Are a Triangle Graph (a cycle of 3 vertices) and a Path Graph on 3 vertices isomorphic? Explain why or why not using graph invariants.
Solution & Walkthrough:
Let's analyze Graph 1: The Triangle ()
- Vertices (): 3
- Edges (): 3
- Degree Sequence:
[2, 2, 2](Every node connects to 2 others)
Let's analyze Graph 2: The Path ()
- Vertices (): 3
- Edges (): 2
- Degree Sequence:
[1, 2, 1](The endpoints have degree 1, center has degree 2)
Conclusion:
- They are NOT isomorphic!
- Reason: They fail the invariant check on both edge count () and degree sequence (
[2, 2, 2][1, 2, 1]). There is no bijection that can preserve structural connections here.
Key Takeaways
- Isomorphism means two graphs are structurally identical twins, even if dressed in different node labels or layout styles.
- It requires a bijection that preserves both edges and non-edges.
- Invariants (vertex count, edge count, degree sequence) are fast tools to rule out isomorphism, but matching invariants alone does not guarantee a match!