Open In App

Difference between Graph Isomorphism and Automorphism using Python NetworkX

Last Updated : 28 Jun, 2024
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

Graph isomorphism and automorphism are important concepts in graph theory. Graph isomorphism checks the equivalence of two graphs, while graph automorphism deals with the symmetry within a single graph. Using Python NetworkX, we can easily explore and visualize these concepts, making it a valuable tool for studying complex networks.

Difference between Graph Isomorphism and Automorphism

Characteristics

Graph Isomorphism

Graph Automorphism

Definition

A bijective mapping between the vertices of two graphs preserving the adjacency.

A re-labeling of the graph's vertices that maps the graph onto itself.

Relationship

Between the two different graphs.

Within the same graph.

Purpose

To check if two graphs are structurally identical.

To find symmetries within the graph.

Example Code Usage

nx.is_isomorphic(G1, G2)

nx.algorithms.isomorphism.GraphMatcher(graph, graph).isomorphisms_iter()

Real-world Example

Checking if two social networks are identical.

Finding symmetrical properties in the molecular structures.

What is Graph Isomorphism?

Graph isomorphism is a concept where two graphs G_1 and G_2 are considered isomorphic if there is a bijection (one-to-one correspondence) between their vertex sets that preserves adjacency. In simpler terms, if you can relabel the vertices of G_1 to make it identical to G_2​, the two graphs are isomorphic.

Graph isomorphism is important in various fields, including chemistry (for comparing molecular structures), network theory, and computer science (for pattern recognition and data structure analysis).

Formal Definition

Two graphs G_1 = (V_1, E_1) \text{ and } G_2 = (V_2, E_2) are isomorphic if there exists a bijection f: V_1 \rightarrow V_2 such that any two vertices u \text{ and } v are adjacent in G_1 if and only if f(u) \text{ and } f(v) are adjacent in G_2​.

Example:

Python
import networkx as nx

def are_isomorphic(graph1, graph2):
    return nx.is_isomorphic(graph1, graph2)
# Example usage:
G1 = nx.Graph()
G1.add_edges_from([(0, 1), (1, 2), (2, 0)])
G2 = nx.Graph()
G2.add_edges_from([(10, 11), (11, 12), (12, 10)])
print("Are G1 and G2 isomorphic?", are_isomorphic(G1, G2))

Output:

Are G1 and G2 isomorphic? True

What is Graph Automorphism?

Graph automorphism is a special case of graph isomorphism where a graph GGG is mapped onto itself in a way that preserves its structure. An automorphism of a graph is a permutation of the vertices that preserves adjacency.

Graph automorphisms are significant in studying the symmetries of graphs, which has applications in chemistry (studying molecular symmetries), network theory (analyzing symmetrical structures in networks), and combinatorial design.

Formal Definition

A graph G = (V, E) has an automorphism if there exists a bijection f: V \rightarrow V such that any two vertices u \text{ and } v are adjacent if and only if f(u) \text{ and } f(v) are adjacent.

Example:

Python
import networkx as nx

def automorphisms(graph):
    return list(nx.algorithms.isomorphism.GraphMatcher(graph, graph).isomorphisms_iter())
# Example usage:
G = nx.Graph()
G.add_edges_from([(0, 1), (1, 2), (2, 0)])
auto_list = automorphisms(G)
print("Automorphisms of G:", auto_list)

Output:

Automorphisms of G: [{0: 0, 1: 1, 2: 2}, {0: 0, 2: 1, 1: 2}, {1: 0, 0: 1, 2: 2}, {1: 0, 2: 1, 0: 2}, {2: 0, 0: 1, 1: 2}, {2: 0, 1: 1, 0: 2}]

Next Article
Article Tags :
Practice Tags :

Similar Reads