9.2 Graph Representations, Subgraphs & Graph Isomorphism Invariants
๐ก Core Intuition: The 3-Second Mental Modelโ
๐ณ The Everyday Analogy: Spreadsheets vs Contact Books & Identical Floor Plansโ
Think of graph representation and isomorphism like organizing contact lists and recognizing twin architectural blueprints:
- Adjacency Matrix (The Full 2D Grid Table): An spreadsheet with all people on both rows and columns. Cell if they are friends; if not. You can instantaneously verify whether any two people know each other ( time), but it wastes memory storing zeros if people only have a few friends ( space).
- Adjacency List (The Mobile Contact Book): Each person only stores the names and numbers of their actual friends. Sparse, compact, and uses memory strictly proportional to real connections ().
- Graph Isomorphism (Same House, Different Blueprint Orientation): Imagine two architects drawing blueprints of the exact same house. Architect 1 numbers the rooms 1 to 4; Architect 2 numbers them to and rotates the drawing 90 degrees. The drawings look completely different at first glance, but if room 1 connects to 2 and 3, and room connects to and with identical relational connectivity, the two houses are isomorphic!
๐ป Bridging to Computer Science: Traversal Engines, Matrix Multiplications & GI Complexityโ
In computer systems:
- Graph Traversal (BFS / DFS / Dijkstra): Production graph algorithms use adjacency lists to achieve optimal linear execution.
- Walk Counting via Matrix Multiplication: In distributed systems and Markov chains, calculates the exact number of packet routes of length between network routers using matrix powers.
- The Graph Isomorphism (GI) Complexity Class: Unlike most problems which are either in or -complete, Graph Isomorphism is one of the celebrated problems suspected to be NP-Intermediate (solved in quasipolynomial time by Lรกszlรณ Babai in 2015).
๐พ Graph Representations: Matrix vs Listโ
Adjacency Matrix vs Adjacency List
The fundamental architectural trade-off between dense random access and sparse memory efficiency
Adjacency Matrix A
- โขStructure: An n ร n binary matrix where A[i][j] = 1 if {vแตข, vโฑผ} โ E, else 0.
- โขSpace Complexity: O(Vยฒ) fixed memory regardless of edge density.
- โขEdge Query Time: O(1) instantaneous lookup (A[u][v] == 1).
- โขRow Sum: Sum of row i equals deg(vแตข); total entries sum to 2|E|.
- โขAlgebraic Power: Matrix powers Aแต count multi-hop walks!
Adjacency List
- โขStructure: Array of V linked lists or vectors storing adjacent neighbors.
- โขSpace Complexity: O(V + E) compact memory footprint.
- โขEdge Query Time: O(deg(u)) requires scanning neighbor list.
- โขTraversal Standard: Native format for BFS, DFS, Dijkstra, and Tarjan.
- โขIteration: Scanning all incident edges takes optimal O(deg(v)) time.
Incidence Matrix Formalismโ
Let be an undirected graph with vertices and edges : The Incidence Matrix is an matrix defined as:
Structural Invariants of the Incidence Matrix:โ
- Column Sum Invariant: Every edge connects exactly two vertices. Therefore, every column of contains exactly two 1s, and the sum of each column is always :
- Row Sum Invariant: The sum of row equals the degree of vertex :
- Total Sum: Summing all elements in yields .
๐งฎ Multi-Hop Walk Counting & Matrix Trace Theoremsโ
Let be the adjacency matrix of a simple graph with vertices . For any positive integer , the -th entry of the -th power matrix :
equals the exact number of distinct walks of length from vertex to vertex !
Proof by Induction on :
- Base Case (): . By definition, if there is an edge (a walk of length 1) from to , and otherwise. Holds!
- Inductive Step: Assume counts walks of length . Any walk of length from to consists of a walk of length from to an intermediate neighbor , followed by a single edge from to . By matrix multiplication: Summing over all possible intermediate bridges gives the total number of walks of length .
Let be the adjacency matrix of a simple graph . The trace is the sum of diagonal elements .
- Trace of (Total Edges): The diagonal entry represents walks of length 2 from to itself (), which equals . Therefore:
- Trace of (Triangle Counting):
The diagonal entry represents closed walks of length 3 starting and ending at (). In a simple graph, any closed walk of length 3 is a triangle ().
- Each triangle can start at 3 different vertices.
- For each starting vertex, the triangle can be traversed in 2 cyclic directions (clockwise and counterclockwise).
- Thus, each single triangle contributes closed walks to !
๐งฉ Subgraphs: Spanning, Vertex-Induced & Edge-Inducedโ
Let be a graph:
- Subgraph (): A graph where and such that every edge in has its endpoints in .
- Spanning Subgraph: A subgraph that contains all vertices of : (e.g., A Spanning Tree of is a spanning subgraph that is a tree).
- Vertex-Induced Subgraph (): Given a subset of vertices , the subgraph induced by has vertex set and contains ALL edges of whose endpoints both belong to :
- Edge-Induced Subgraph (): Given a subset of edges , the subgraph induced by contains and all vertices incident to at least one edge in .
๐ช Graph Isomorphism: Structural Equivalenceโ
Two simple graphs and are isomorphic (denoted ) if there exists a bijective function:
such that for all pairs of vertices :
The mapping is called an isomorphism. It preserves adjacency, non-adjacency, and all structural graph invariants.
- Matrix Permutation Test: if and only if there exists an permutation matrix such that:
The 5-Filter Graph Isomorphism Verification Pipeline
Systematic invariant checklist to prove or disprove structural equivalence
Cardinality Invariants
Verify that |Vโ| = |Vโ| and |Eโ| = |Eโ|. If counts differ โน NOT ISOMORPHIC!
Degree Sequence Invariant
Sort degrees of both graphs. Degree sequences must be IDENTICAL. If sequences differ โน NOT ISOMORPHIC!
Cycle & Subgraph Spectrum
Count cycles of length 3 (triangles), 4, 5... Girth and cycle counts must match identically in both graphs.
Complement Graph Invariant
If Gโ โ Gโ, then their complements must also be isomorphic: Gฬโ โ Gฬโ.
Construct Bijective Mapping f
Map vertices with matching degrees and verify that every edge in Gโ corresponds to an edge in Gโ.
๐ Step-by-Step Worked Examplesโ
Example 1: Counting Multi-Hop Walks via Matrix Powersโ
Problem Statement: Consider a triangle graph with vertices and edges .
- Construct the adjacency matrix .
- Compute and .
- How many walks of length 3 exist from vertex to itself ()? Verify the Triangle Counting Theorem via .
Step-by-Step Solution:
-
Step 1: Construct Adjacency Matrix
-
Step 2: Compute and
- Compute : (Interpretation: Entry means there are 2 walks of length 2 from to : and ).
- Compute :
-
Step 3: Closed Walks & Triangle Verification
- Number of walks of length 3 from to : .
- The two walks are the two traversal directions around the triangle:
- (clockwise)
- (counter-clockwise)
- Verifying the Triangle Trace Theorem:
- Matches the graph structure exactly!
Key Takeaway: counts walks, not simple paths. The trace , and calculates the exact number of triangles in the graph!
Example 2: Proving Graph Isomorphism with Bijection Constructionโ
Problem Statement: Refer to the diagram above showing (vertices ) and (vertices ).
- Prove that by constructing an explicit isomorphism bijection .
Step-by-Step Solution:
-
Step 1: Check Invariants
- Vertices: , (Match).
- Edges: , (Match).
- Degree sequence in : .
- Degree sequence in : .
- Both graphs contain exactly 2 triangles () and 1 cycle of length 4 ().
-
Step 2: Construct Candidate Bijective Mapping
- High-degree vertices ():
- In , have degree 3 and are adjacent ().
- In , have degree 3 and are adjacent ().
- Set and .
- Lower-degree vertices ():
- In , vertex connects to .
- In , vertex connects to .
- Set .
- In , vertex connects to .
- In , vertex connects to .
- Set .
- High-degree vertices ():
-
Step 3: Edge-Preservation Verification
- (Preserved).
- (Preserved).
- (Preserved).
- (Preserved).
- (Preserved).
- Non-edges: (Preserved).
Conclusion: is a valid bijection preserving all adjacencies and non-adjacencies. Hence, .
Key Takeaway: To prove isomorphism, establish a candidate mapping between vertices of matching degrees and verify edge-by-edge that all connections are preserved.
๐ฏ Exam & Interview Pitfall Checkโ
Question 1: If two graphs have the exact same degree sequence, are they guaranteed to be isomorphic? Key Focus Points: No! Degree sequence equality is a necessary condition, but NOT a sufficient condition. Classic Counterexample:
- Graph : Cycle of length 6 (). Degree sequence is .
- Graph : Two disjoint triangles (). Degree sequence is also . Both graphs have vertices, edges, and identical degree sequences. However, is connected with girth 6, while is disconnected with 2 triangles. Hence, !
Question 2: How does the complement graph help prove or disprove graph isomorphism? Key Focus Points: Two graphs are isomorphic if and only if their complements are isomorphic:
When analyzing dense graphs with many edges (e.g., ), inspecting the complement graphs and is vastly simpler because the complements have very few edges (), making structural discrepancies instantly visible!
Trap 1: Confusing walks with paths in matrix powers Why it fails: counts all walks of length , NOT simple paths! A walk can revisit vertices and re-traverse edges (e.g., ). If an interview question asks for the number of simple paths, you cannot simply read off .
Trap 2: Forgetting the 1/6 factor when counting triangles from Tr(Aยณ) Why it fails: In , each triangle is counted 6 times (3 choices for the starting vertex 2 traversal directions: clockwise and counter-clockwise). Forgetting the factor will overestimate the triangle count by !