Skip to main content

9.2 Graph Representations, Subgraphs & Graph Isomorphism Invariants

๐Ÿ“šModule 09: Graph Theory Foundations, Paths & ConnectivityTopic 9.2: Representations & Isomorphismโฑ๏ธ5 min read
๐ŸŽฏHigh-Yield For:Semester Exams โ€ข GATE CSE โ€ข Technical Interviews

๐Ÿ’ก 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:

  1. Adjacency Matrix (The Full 2D Grid Table): An nร—nn \times n spreadsheet with all people on both rows and columns. Cell (i,j)=1(i, j) = 1 if they are friends; 00 if not. You can instantaneously verify whether any two people know each other (O(1)O(1) time), but it wastes memory storing zeros if people only have a few friends (O(V2)O(V^2) space).
  2. 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 (O(V+E)O(V + E)).
  3. 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 aa to dd 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 aa connects to bb and cc 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 O(V+E)O(V + E) execution.
  • Walk Counting via Matrix Multiplication: In distributed systems and Markov chains, (Ak)i,j(A^k)_{i, j} calculates the exact number of packet routes of length kk between network routers using matrix powers.
  • The Graph Isomorphism (GI) Complexity Class: Unlike most problems which are either in PP or NPNP-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

Adjacency Matrix A

๐Ÿ“‹
Dominant Architecture / DomainDense Graph Optimization
  • โ€ข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!
"Dense 2D grid ideal when |E| โ‰ˆ |V|ยฒ."
Adjacency List

Adjacency List

๐Ÿ“œ
Dominant Architecture / DomainSparse Graph Optimization
  • โ€ข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.
"Linear space ideal for real-world sparse graphs where |E| โ‰ช |V|ยฒ."

Incidence Matrix Formalismโ€‹

๐Ÿ“–Definition 9.1: The Incidence Matrix Mdefinition

Let G=(V,E)G = (V, E) be an undirected graph with nn vertices {v1,โ€ฆ,vn}\{v_1, \dots, v_n\} and mm edges {e1,โ€ฆ,em}\{e_1, \dots, e_m\}: The Incidence Matrix MM is an nร—mn \times m matrix defined as:

Mi,j={1ifย vertexย viย isย incidentย withย edgeย ej0otherwiseM_{i, j} = \begin{cases} 1 & \text{if vertex } v_i \text{ is incident with edge } e_j \\ 0 & \text{otherwise} \end{cases}

Structural Invariants of the Incidence Matrix:โ€‹

  1. Column Sum Invariant: Every edge connects exactly two vertices. Therefore, every column of MM contains exactly two 1s, and the sum of each column is always 22: โˆ‘i=1nMi,j=2(โˆ€j)\sum_{i=1}^{n} M_{i, j} = 2 \quad (\forall j)
  2. Row Sum Invariant: The sum of row ii equals the degree of vertex viv_i: โˆ‘j=1mMi,j=degโก(vi)\sum_{j=1}^{m} M_{i, j} = \deg(v_i)
  3. Total Sum: Summing all elements in MM yields 2m=2โˆฃEโˆฃ2m = 2|E|.

๐Ÿงฎ Multi-Hop Walk Counting & Matrix Trace Theoremsโ€‹

๐Ÿ“Theorem 9.1: Walk Counting via Matrix Powerstheorem

Let AA be the adjacency matrix of a simple graph GG with vertices {v1,v2,โ€ฆ,vn}\{v_1, v_2, \dots, v_n\}. For any positive integer kโ‰ฅ1k \ge 1, the (i,j)(i, j)-th entry of the kk-th power matrix AkA^k:

(Ak)i,j(A^k)_{i, j}

equals the exact number of distinct walks of length kk from vertex viv_i to vertex vjv_j!

Proof by Induction on kk:

  • Base Case (k=1k = 1): A1=AA^1 = A. By definition, Ai,j=1A_{i, j} = 1 if there is an edge (a walk of length 1) from viv_i to vjv_j, and 00 otherwise. Holds!
  • Inductive Step: Assume (Ak)i,j(A^k)_{i, j} counts walks of length kk. Any walk of length k+1k + 1 from viv_i to vjv_j consists of a walk of length kk from viv_i to an intermediate neighbor vmv_m, followed by a single edge from vmv_m to vjv_j. By matrix multiplication: (Ak+1)i,j=โˆ‘m=1n(Ak)i,mโ‹…Am,j(A^{k+1})_{i, j} = \sum_{m=1}^{n} (A^k)_{i, m} \cdot A_{m, j} Summing over all possible intermediate bridges vmv_m gives the total number of walks of length k+1k + 1.
๐Ÿ“Theorem 9.2: Trace Invariants for Edges and Trianglestheorem

Let AA be the adjacency matrix of a simple graph GG. The trace Tr(M)\text{Tr}(M) is the sum of diagonal elements โˆ‘Mi,i\sum M_{i, i}.

  1. Trace of A2A^2 (Total Edges): The diagonal entry (A2)i,i(A^2)_{i, i} represents walks of length 2 from viv_i to itself (viโ†’vjโ†’viv_i \to v_j \to v_i), which equals degโก(vi)\deg(v_i). Therefore: Tr(A2)=โˆ‘i=1n(A2)i,i=โˆ‘i=1ndegโก(vi)=2โˆฃEโˆฃ\text{Tr}(A^2) = \sum_{i=1}^{n} (A^2)_{i, i} = \sum_{i=1}^{n} \deg(v_i) = 2 |E|
  2. Trace of A3A^3 (Triangle Counting): The diagonal entry (A3)i,i(A^3)_{i, i} represents closed walks of length 3 starting and ending at viv_i (viโ†’vjโ†’vkโ†’viv_i \to v_j \to v_k \to v_i). In a simple graph, any closed walk of length 3 is a triangle (C3C_3).
    • Each triangle {u,v,w}\{u, v, w\} 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 3ร—2=63 \times 2 = 6 closed walks to Tr(A3)\text{Tr}(A^3)!
    Numberย ofย Trianglesย (C3)=16Tr(A3)=16โˆ‘i=1n(A3)i,i\text{Number of Triangles } (C_3) = \frac{1}{6} \text{Tr}(A^3) = \frac{1}{6} \sum_{i=1}^{n} (A^3)_{i, i}

๐Ÿงฉ Subgraphs: Spanning, Vertex-Induced & Edge-Inducedโ€‹

๐Ÿ“–Definition 9.2: Subgraph Taxonomydefinition

Let G=(V,E)G = (V, E) be a graph:

  1. Subgraph (HโІGH \subseteq G): A graph H=(Vโ€ฒ,Eโ€ฒ)H = (V', E') where Vโ€ฒโІVV' \subseteq V and Eโ€ฒโІEE' \subseteq E such that every edge in Eโ€ฒE' has its endpoints in Vโ€ฒV'.
  2. Spanning Subgraph: A subgraph HH that contains all vertices of GG: V(H)=V(G)andE(H)โІE(G)V(H) = V(G) \quad \text{and} \quad E(H) \subseteq E(G) (e.g., A Spanning Tree of GG is a spanning subgraph that is a tree).
  3. Vertex-Induced Subgraph (G[S]G[S]): Given a subset of vertices SโІVS \subseteq V, the subgraph induced by SS has vertex set SS and contains ALL edges of GG whose endpoints both belong to SS: E(G[S])={{u,v}โˆˆEโˆฃuโˆˆSโˆงvโˆˆS}E(G[S]) = \{ \{u, v\} \in E \mid u \in S \land v \in S \}
  4. Edge-Induced Subgraph (G[Eโ€ฒ]G[E']): Given a subset of edges Eโ€ฒโІEE' \subseteq E, the subgraph induced by Eโ€ฒE' contains Eโ€ฒE' and all vertices incident to at least one edge in Eโ€ฒE'.

๐Ÿชž Graph Isomorphism: Structural Equivalenceโ€‹

๐Ÿ“–Definition 9.3: Graph Isomorphismdefinition

Two simple graphs G1=(V1,E1)G_1 = (V_1, E_1) and G2=(V2,E2)G_2 = (V_2, E_2) are isomorphic (denoted G1โ‰…G2G_1 \cong G_2) if there exists a bijective function:

f:V1โ†’V2f: V_1 \to V_2

such that for all pairs of vertices u,vโˆˆV1u, v \in V_1:

{u,v}โˆˆE1โ€…โ€ŠโŸบโ€…โ€Š{f(u),f(v)}โˆˆE2\{u, v\} \in E_1 \iff \{f(u), f(v)\} \in E_2

The mapping ff is called an isomorphism. It preserves adjacency, non-adjacency, and all structural graph invariants.

  • Matrix Permutation Test: G1โ‰…G2G_1 \cong G_2 if and only if there exists an nร—nn \times n permutation matrix PP such that: A(G2)=Pโ‹…A(G1)โ‹…PTA(G_2) = P \cdot A(G_1) \cdot P^T
โœ“ Isomorphic Invariants: |V|=4, |E|=5, Degrees: (3, 3, 2, 2)Graph Gโ‚ (Planar Diamond)Graph Gโ‚‚ (Crossed Square)1deg = 22deg = 33deg = 34deg = 2bdeg = 3cdeg = 3adeg = 2ddeg = 2โ‰…f: Gโ‚ โž” Gโ‚‚
Isomorphism Bijection: f(1)=a, f(2)=b, f(3)=c, f(4)=d preserves all 5 adjacency relations despite contrasting planar drawings.
Architecture Flow

The 5-Filter Graph Isomorphism Verification Pipeline

Systematic invariant checklist to prove or disprove structural equivalence

๐Ÿ”ขFilter 1

Cardinality Invariants

Verify that |Vโ‚| = |Vโ‚‚| and |Eโ‚| = |Eโ‚‚|. If counts differ โŸน NOT ISOMORPHIC!

โ†’
Pass: Sizes Match
๐Ÿ“ŠFilter 2

Degree Sequence Invariant

Sort degrees of both graphs. Degree sequences must be IDENTICAL. If sequences differ โŸน NOT ISOMORPHIC!

โ†’
Pass: Degrees Match
๐Ÿ”„Filter 3

Cycle & Subgraph Spectrum

Count cycles of length 3 (triangles), 4, 5... Girth and cycle counts must match identically in both graphs.

โ†’
Pass: Cycles Match
๐ŸชžFilter 4

Complement Graph Invariant

If Gโ‚ โ‰… Gโ‚‚, then their complements must also be isomorphic: Gฬ„โ‚ โ‰… Gฬ„โ‚‚.

โ†’
Pass: Complements Match
๐ŸŽฏFilter 5

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 C3C_3 with vertices {v1,v2,v3}\{v_1, v_2, v_3\} and edges {{1,2},{2,3},{1,3}}\{\{1, 2\}, \{2, 3\}, \{1, 3\}\}.

  1. Construct the adjacency matrix AA.
  2. Compute A2A^2 and A3A^3.
  3. How many walks of length 3 exist from vertex v1v_1 to itself (v1โ†’v1v_1 \to v_1)? Verify the Triangle Counting Theorem via Tr(A3)\text{Tr}(A^3).

Step-by-Step Solution:

  1. Step 1: Construct Adjacency Matrix AA

    A=(011101110)A = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix}
  2. Step 2: Compute A2A^2 and A3A^3

    • Compute A2=Aร—AA^2 = A \times A: A2=(011101110)(011101110)=(211121112)A^2 = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix} \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix} = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix} (Interpretation: Entry (1,1)=2(1, 1) = 2 means there are 2 walks of length 2 from v1v_1 to v1v_1: v1โ†’v2โ†’v1v_1 \to v_2 \to v_1 and v1โ†’v3โ†’v1v_1 \to v_3 \to v_1).
    • Compute A3=A2ร—AA^3 = A^2 \times A: A3=(211121112)(011101110)=(233323332)A^3 = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix} \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix} = \begin{pmatrix} 2 & 3 & 3 \\ 3 & 2 & 3 \\ 3 & 3 & 2 \end{pmatrix}
  3. Step 3: Closed Walks & Triangle Verification

    • Number of walks of length 3 from v1v_1 to v1v_1: (A3)1,1=2(A^3)_{1, 1} = 2.
    • The two walks are the two traversal directions around the triangle:
      1. v1โ†’v2โ†’v3โ†’v1v_1 \to v_2 \to v_3 \to v_1 (clockwise)
      2. v1โ†’v3โ†’v2โ†’v1v_1 \to v_3 \to v_2 \to v_1 (counter-clockwise)
    • Verifying the Triangle Trace Theorem: Tr(A3)=(A3)1,1+(A3)2,2+(A3)3,3=2+2+2=6\text{Tr}(A^3) = (A^3)_{1, 1} + (A^3)_{2, 2} + (A^3)_{3, 3} = 2 + 2 + 2 = 6 Totalย Triangles=16Tr(A3)=66=1ย triangle\text{Total Triangles} = \frac{1}{6} \text{Tr}(A^3) = \frac{6}{6} = 1 \text{ triangle}
    • Matches the graph structure exactly!

Key Takeaway: (Ak)i,j(A^k)_{i, j} counts walks, not simple paths. The trace Tr(A2)=2โˆฃEโˆฃ\text{Tr}(A^2) = 2|E|, and 16Tr(A3)\frac{1}{6}\text{Tr}(A^3) 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 G1G_1 (vertices {1,2,3,4}\{1, 2, 3, 4\}) and G2G_2 (vertices {a,b,c,d}\{a, b, c, d\}).

  • E(G1)={{1,2},{1,3},{2,4},{3,4},{2,3}}E(G_1) = \{\{1, 2\}, \{1, 3\}, \{2, 4\}, \{3, 4\}, \{2, 3\}\}
  • E(G2)={{b,c},{b,a},{c,d},{b,d},{c,a}}E(G_2) = \{\{b, c\}, \{b, a\}, \{c, d\}, \{b, d\}, \{c, a\}\} Prove that G1โ‰…G2G_1 \cong G_2 by constructing an explicit isomorphism bijection ff.

Step-by-Step Solution:

  1. Step 1: Check Invariants

    • Vertices: โˆฃV1โˆฃ=4|V_1| = 4, โˆฃV2โˆฃ=4|V_2| = 4 (Match).
    • Edges: โˆฃE1โˆฃ=5|E_1| = 5, โˆฃE2โˆฃ=5|E_2| = 5 (Match).
    • Degree sequence in G1G_1: degโก(2)=3,degโก(3)=3,degโก(1)=2,degโก(4)=2โ€…โ€ŠโŸนโ€…โ€Š(3,3,2,2)\deg(2) = 3, \deg(3) = 3, \deg(1) = 2, \deg(4) = 2 \implies (3, 3, 2, 2).
    • Degree sequence in G2G_2: degโก(b)=3,degโก(c)=3,degโก(a)=2,degโก(d)=2โ€…โ€ŠโŸนโ€…โ€Š(3,3,2,2)\deg(b) = 3, \deg(c) = 3, \deg(a) = 2, \deg(d) = 2 \implies (3, 3, 2, 2).
    • Both graphs contain exactly 2 triangles (K3K_3) and 1 cycle of length 4 (C4C_4).
  2. Step 2: Construct Candidate Bijective Mapping ff

    • High-degree vertices (degโก=3\deg = 3):
      • In G1G_1, {2,3}\{2, 3\} have degree 3 and are adjacent ({2,3}โˆˆE1\{2, 3\} \in E_1).
      • In G2G_2, {b,c}\{b, c\} have degree 3 and are adjacent ({b,c}โˆˆE2\{b, c\} \in E_2).
      • Set f(2)=bf(2) = b and f(3)=cf(3) = c.
    • Lower-degree vertices (degโก=2\deg = 2):
      • In G1G_1, vertex 11 connects to {2,3}\{2, 3\}.
      • In G2G_2, vertex aa connects to {b,c}\{b, c\}.
      • Set f(1)=af(1) = a.
      • In G1G_1, vertex 44 connects to {2,3}\{2, 3\}.
      • In G2G_2, vertex dd connects to {b,c}\{b, c\}.
      • Set f(4)=df(4) = d.
  3. Step 3: Edge-Preservation Verification

    • {1,2}โˆˆE1โ€…โ€ŠโŸบโ€…โ€Š{f(1),f(2)}={a,b}โˆˆE2\{1, 2\} \in E_1 \iff \{f(1), f(2)\} = \{a, b\} \in E_2 (Preserved).
    • {1,3}โˆˆE1โ€…โ€ŠโŸบโ€…โ€Š{f(1),f(3)}={a,c}โˆˆE2\{1, 3\} \in E_1 \iff \{f(1), f(3)\} = \{a, c\} \in E_2 (Preserved).
    • {2,3}โˆˆE1โ€…โ€ŠโŸบโ€…โ€Š{f(2),f(3)}={b,c}โˆˆE2\{2, 3\} \in E_1 \iff \{f(2), f(3)\} = \{b, c\} \in E_2 (Preserved).
    • {2,4}โˆˆE1โ€…โ€ŠโŸบโ€…โ€Š{f(2),f(4)}={b,d}โˆˆE2\{2, 4\} \in E_1 \iff \{f(2), f(4)\} = \{b, d\} \in E_2 (Preserved).
    • {3,4}โˆˆE1โ€…โ€ŠโŸบโ€…โ€Š{f(3),f(4)}={c,d}โˆˆE2\{3, 4\} \in E_1 \iff \{f(3), f(4)\} = \{c, d\} \in E_2 (Preserved).
    • Non-edges: {1,4}โˆ‰E1โ€…โ€ŠโŸบโ€…โ€Š{a,d}โˆ‰E2\{1, 4\} \notin E_1 \iff \{a, d\} \notin E_2 (Preserved).

Conclusion: ff is a valid bijection preserving all adjacencies and non-adjacencies. Hence, G1โ‰…G2G_1 \cong G_2.

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โ€‹

Core Conceptual Questions

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 G1G_1: Cycle of length 6 (C6C_6). Degree sequence is (2,2,2,2,2,2)(2, 2, 2, 2, 2, 2).
  • Graph G2G_2: Two disjoint triangles (2C32 C_3). Degree sequence is also (2,2,2,2,2,2)(2, 2, 2, 2, 2, 2). Both graphs have 66 vertices, 66 edges, and identical degree sequences. However, G1G_1 is connected with girth 6, while G2G_2 is disconnected with 2 triangles. Hence, G1โ‰…ฬธG2G_1 \not\cong G_2!

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:

G1โ‰…G2โ€…โ€ŠโŸบโ€…โ€ŠGห‰1โ‰…Gห‰2G_1 \cong G_2 \iff \bar{G}_1 \cong \bar{G}_2

When analyzing dense graphs with many edges (e.g., โˆฃEโˆฃโ‰ˆ(n2)|E| \approx \binom{n}{2}), inspecting the complement graphs Gห‰1\bar{G}_1 and Gห‰2\bar{G}_2 is vastly simpler because the complements have very few edges (โˆฃE(Gห‰)โˆฃ=(n2)โˆ’โˆฃE(G)โˆฃ|E(\bar{G})| = \binom{n}{2} - |E(G)|), making structural discrepancies instantly visible!

Common Interview Traps: Architectural Trade-Offs

Trap 1: Confusing walks with paths in matrix powers Why it fails: (Ak)i,j(A^k)_{i, j} counts all walks of length kk, NOT simple paths! A walk can revisit vertices and re-traverse edges (e.g., v1โ†’v2โ†’v1โ†’v2v_1 \to v_2 \to v_1 \to v_2). If an interview question asks for the number of simple paths, you cannot simply read off (Ak)i,j(A^k)_{i, j}.

Trap 2: Forgetting the 1/6 factor when counting triangles from Tr(Aยณ) Why it fails: In Tr(A3)\text{Tr}(A^3), each triangle {u,v,w}\{u, v, w\} is counted 6 times (3 choices for the starting vertex ร—\times 2 traversal directions: clockwise and counter-clockwise). Forgetting the 16\frac{1}{6} factor will overestimate the triangle count by 600%600\%!

๐Ÿ’ฌ

Discussion & Doubts