IsomorphicGraphQ[g1,g2]
yields True if the graphs g1 and g2 are isomorphic, and False otherwise.
IsomorphicGraphQ
IsomorphicGraphQ[g1,g2]
yields True if the graphs g1 and g2 are isomorphic, and False otherwise.
Details
- IsomorphicGraphQ is also known as graph isomorphism problem.
- IsomorphicGraphQ is typically used to determine whether two graphs are structurally equivalent.
- Two graphs are isomorphic if there is a renaming of vertices that makes them equal.
- IsomorphicGraphQ[g1,g2,…] gives True if all the gi are isomorphic.
Examples
open all close allBasic Examples (1)
Test whether two graphs are isomorphic:
g = [image];h = [image];IsomorphicGraphQ[g, h]Find an isomorphism that maps g to h:
First[Normal[FindGraphIsomorphism[g, h]]]Renaming the vertices of graph g gets an equal graph as h:
Graph[VertexList[h], EdgeList[VertexReplace[g, %]], AbsoluteOptions[h, VertexCoordinates], VertexShapeFunction -> "Name"]Scope (4)
IsomorphicGraphQ works with undirected graphs:
IsomorphicGraphQ[[image], [image]]IsomorphicGraphQ[[image], [image]]IsomorphicGraphQ gives False for non-isomorphic graphs:
IsomorphicGraphQ[CycleGraph[3], CycleGraph[4]]As well as non-graph expressions:
IsomorphicGraphQ[x, y]IsomorphicGraphQ works with large graphs:
{g = GridGraph[{10, 10, 10}],
h = Graph[RandomSample[VertexList[g], VertexCount[g]], EdgeList[g]]};IsomorphicGraphQ[g, h]//Timing{VertexCount[g], EdgeCount[g]}Properties & Relations (10)
Isomorphic graphs have the same number of vertices and edges:
g = [image];h = [image];VertexCount[g] == VertexCount[h]EdgeCount[g] == EdgeCount[h]The isomorphic graphs have the same ordered degree sequence:
g = [image];h = [image];IsomorphicGraphQ[g, h]Sort[VertexDegree[g]] == Sort[VertexDegree[h]]The graphs with the same degree sequence can be non-isomorphic:
g = RandomGraph[{10, 12}];IsomorphicGraphQ[g, #]& /@ Table[RandomGraph[DegreeGraphDistribution[VertexDegree[g]]], {10}]FindGraphIsomorphism can be used to find the mapping between vertices:
{g = PetersenGraph[5, 2, VertexSize -> Large, ImagePadding -> 10], h = Graph[RandomSample[VertexList[g], VertexCount[g]], EdgeList[g], VertexSize -> Large, ImagePadding -> 10]};IsomorphicGraphQ[g, h]map = First[Normal[FindGraphIsomorphism[g, h]]]Highlight and label two graphs according to the mapping:
a = First /@ map;b = Last /@ map;highlightGraph[g_, v_] := HighlightGraph[g, Table[Style[Labeled[v[[i]], v[[i]]], ColorData["TemperatureMap"][i / VertexCount[g]]], {i, VertexCount[g]}]];{highlightGraph[g, a], highlightGraph[h, b]}Permuting the vertices in a graph produces an isomorphic graph:
{g = ButterflyGraph[2], h = Graph[RandomSample[VertexList[g], VertexCount[g]], EdgeList[g]]}g == hIsomorphicGraphQ[g, h]The graph generated by the permutation of its adjacency matrix is isomorphic to itself:
g = PetersenGraph[5, 2];Sample a permutation of the vertex list:
p = RandomSample[VertexList[g], VertexCount[g]]{g, AdjacencyGraph[AdjacencyMatrix[g][[p, p]]]}IsomorphicGraphQ@@% The line graph of a cycle graph
is isomorphic to
itself:
Table[g -> LineGraph[g], {g, Table[CycleGraph[n], {n, 3, 4}]}]Apply[IsomorphicGraphQ, %, {1}]The line graph of a path
is isomorphic to
:
g = PathGraph[Range[10]];{LineGraph[g], PathGraph[Range[9]]}IsomorphicGraphQ@@%The complement of the line graph of
is isomorphic to a Petersen graph:
{GraphComplement[LineGraph@CompleteGraph[5]], PetersenGraph[5, 2]}IsomorphicGraphQ@@%Two connected graphs are isomorphic iff their line graphs are isomorphic:
g = [image];h = [image];{IsomorphicGraphQ[g, h], IsomorphicGraphQ[LineGraph@g, LineGraph@h]}g = [image];h = [image];{IsomorphicGraphQ[g, h], IsomorphicGraphQ[LineGraph@g, LineGraph@h]}The non-isomorphic directed graphs can have undirected graphs that are isomorphic:
g = [image];h = [image];IsomorphicGraphQ[g, h]IsomorphicGraphQ[UndirectedGraph[g], UndirectedGraph[h]]See Also
Function Repository: IsomorphicHypergraphQ IsomorphicOrderedHypergraphQ
Related Guides
Text
Wolfram Research (2010), IsomorphicGraphQ, Wolfram Language function, https://reference.wolfram.com/language/ref/IsomorphicGraphQ.html (updated 2012).
CMS
Wolfram Language. 2010. "IsomorphicGraphQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. https://reference.wolfram.com/language/ref/IsomorphicGraphQ.html.
APA
Wolfram Language. (2010). IsomorphicGraphQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/IsomorphicGraphQ.html
BibTeX
@misc{reference.wolfram_2026_isomorphicgraphq, author="Wolfram Research", title="{IsomorphicGraphQ}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/IsomorphicGraphQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_isomorphicgraphq, organization={Wolfram Research}, title={IsomorphicGraphQ}, year={2012}, url={https://reference.wolfram.com/language/ref/IsomorphicGraphQ.html}, note=[Accessed: 13-June-2026]}