Algorithms for computing the Automorphism Group of a Graph and

Algorithms for computing the Automorphism Group of a Graph and Sub Graph
Isomorphism
Vamsi Kundeti
([email protected])
CSE Department
University of Connecticut
Storrs,CT
Abstract
In this report we present a brief survey of the existing algorithms for Computing the Automorphism Group of a
graph, algorithms to compute Sub Graph Isomorphism(SGI) and also present some important results on Spectrum
of a Graph. Graph Isomorphism(GI) has been a great interest of computer scientists the problem of SGI has been
proved to be a NP-Complete problem however the complexity class of GI is still unknown. Several polynomial
time algorithms were given in the literature for the restricted version of the GI problem but the problem of finding a
polynomial time algorithm for GI is still open. GI algorithms can be classifed into two categories the first category
of algorithms are based on algebraic group theory and second category of algorithms are based on computing
the specturm of the adjacency matrix of the graph. In this report we present the key ideas for computing the
automorphisms of a graph in [McK78] and algorithms for computing the sub graph isomorphism in [Ull76], these
two papers are based on key ideas presented in [CG70].
1 Introduction
Two graphs G1 (V, E1 ) and G2 (V, E2 ) are said to be isomorphic if there exists a permutation π such that when
the nodes of G1 are permuted using π the resultant graph is the same as G2 . Checking if two given graphs are
isomorphic is an important problem (called the graph isomorphism problem) and has numerous applications. A
brute force algorithm may try all the n! possible permutations to figure out if two graphs are isomorphic, it was
shown by Unger [Ung64] that even on a powerful computer the graph isomorphism problem with the brute force
approach may not work beyond graph of size (n ≥ 10). So it is very important to find out an efficient algorithm
for graph isomorphism problem.
Many scientists have been interested in knowing if there exist polynomial time algorithms for graph isomorphism and it is not known if this is indeed the case. Numerous algorithms have been proposed for solving this
problem (that take superpolynomial time in the worst case). Some of these algorithms work well in practice. If
two given graphs are isomorphic, we may be interested in finding such an isomorphism. Finding an isomorphism
is also an important problem addressed by most of the algorithms in the literature. Let G be a simple graph whose
adjacency matrix is A. The eigen values of A constitute the spectrum of G. The characteristic polynomial of
G is the characteristic polynomial of A (and is equal to det(xI − A)). Two graphs are said to be cospectral or
isospectral if they have the same charecteristic polynomial (and hence the same spectrum).
In [Har62], Haray points out that his conjecture that isospectral graphs are isomorphic was disproved by Bose.
Bose constructed a pair of isospectral nonisomorphic graphs (PING) with 16 vertices. In addition, Harary mentions
that Bruck and Hoffman also found 16-node PINGs. If Harary’s conjecture were true, we will have a cubic time
1
algorithm for graph isomorphism. Since then numerous PINGs have been identified in the literature (see e.g.,
[CRS97] and [GM01]). For example, Schwenk [Sch73] has shown that almost all trees are cospectral. In other
words, the proportion of trees on n vertices characterized completely by their spectra tends to zero as n tends to
∞. Restricted families of graphs that are completely characterized by their spectra are also known. For example,
any regular graph of degree 2 is characterized by its spectrum (see e.g., [CRS97]). In [GM01], Godsil and McKay
present a method for constructing PINGs.
Several algorithms have been proposed for graph isomorphism. The algorithm of McKay [McK81] is based
on the idea of canonically labelling a graph and finding generators for its automorphism group. This algorithm,
called NAUTY, has been demonstrated to be very effective in practice. It can handle many graphs with thousands
of vertices and is perhaps the most effective algorithm in practice at present, in this report we present the key ideas
behind this algorithm these were first presented in [McK78] we also present an algorithm for subgraph isomorphism which was presented in [Ull76] both these algorithms have roots in [CG70]. Although determining graph
isomorphism is important, computing the automorphic group Aut(G)(we define this in section2) of a given graph
G is more fundamental than the graph isomorphism problem, isomorphism is one special case of automorphism
of a G. In the Sub Graph Isomorphism(SGI) problem asks if we can find a sub graph in G which is isomorphic to
a query graph H, sub graph isomorphism can be easily proved to be NP-Complete by reducing the clique problem
to the SGI problem, in this report we also discuss a classical sub graph isomorphism algorithm given by Ullmann
[Ull76].
This report is organized as follows in section2 we briefly describe all the preliminaries required for the rest
of the report, in section3 we describe the key ideas behind the cannonical labelling algorithm which computes
Aut(G) later in section4 we describe the sub graph isomorphism algorithm by [Ull76].
2 Preliminaries
Let G = (V, E) be a graph V = {1, 2, 3, . . . n} represent the vertices and E = {(v1 , v2 )|v1 ∈ V ∧ v2 ∈ V } be the
edges of graph. Let Sπ be a set of all n! permutations of integers {1, 2, 3 . . . n} , and let o be a binary operator on
two permutations πi ∈ Sπ and πj ∈ Sπ then its easy to see the closure πi oπj ∈ Sπ , also we can see that (Sπ , o)
forms a finite group let Sn = (Sπ , o), Sn is called a symmetric group. For any πi ∈ Sn we define v πi is the image
of v ∈ V under permutation πi . Let G(V ) represent all the labelled graphs with vertex set V , for every G ∈ G(V )
a relabelled graph with permutation πi ∈ Sn is defined as Gπi which is constructed from G by relabelling every
vertex v ∈ V with v πi and adding an edge between v πi and wπi only if there is a edge between v ∈ V and w ∈ V .
An automorphism of a graph G is a relabelling of the graph such that its structure is still the same, for example in
the fig1 if we exchange the labels between the vertices 1 and 3 or 4 and 7 the structure of the graph is the same,
more formally a automorphism group(Aut(G)), is the group on {πi ∈ Sn |Gπi = G}.
The Canonical Labelling Problem is to find a map(function Canon(< graph >)) from the vertices of a given
graph G on to a Canonical Graph Canon(G) such that G is isomorphic to Canon(G). More formally the function
Canon : G(V ) → G(V ) and has the statisfy the following property
∀(πi ∈ Sn , G ∈ G(V )), (Canon(G) = Canon(Gπi )) ∧ (Canon(G) is Isomorphic to G)
A partition Π of the vertex set V is a set of disjoint subsets(Ci ) of V such that the following holds, the subsets Ci
are termed as cells.
(Π = {C1 , C2 . . . C|Π| }) ∧ (C1 ∪ C2 ∪ . . . C|Π| = V )
Let Π(V ) denote all the possible partitions on the vertex set V . Let {Πi , Πj ∈ Π(V ), Πi ≤ Πj } iff every cell of
Πi is contained in some cell of Πj also Πi is said to be finer than Πj (Πj is coarser than Πi ). If Πi ≤ Πj and
Πj ≤ Πi then it is written as Πi ≃ Πj . So the operator ≤ on the set Π(V ) creates a partial order and hence
a poset(lattice) is formed. Let πi ∈ Sn and Πi ∈ Π(V ) then Πi is said to be fixed by permutation πi if it does
2
0
1
00
11
000
111
0
1
1
0
00
11
000
111
0
1
00
11
000
111
00
11
000 2
111
00
511
000
111
000
111
000
11100000000
11111111
1111111
0000000
00
11
006
11
0
1
0
1
00
11
000
111
00
11
0
1
0
1
000
111
00
11
000
111
00
11
000
111
00
11
000
111
00 4
11
0
1
3
000
111
00
11
0
1
0
1
0
1
1
00
11
04
1
00
11
000
111
0
1
1
0
00
11
000
111
0
1
00
11
000
111
00
11
000 2
111
00
511
000
111
000
111
000
11100000000
11111111
1111111
0000000
00
11
006
11
0
1
0
1
00
11
000
111
00
11
0
1
0
1
000
111
00
11
000
111
00
11
000
111
00
11
000
111
00 7
11
0
1
3
000
111
00
11
0
1
0
1
0
1
1
7
3
00
11
04
1
00
11
000
111
0
1
1
0
00
11
000
111
0
1
00
11
000
111
00
11
000 2
111
00
511
000
111
000
111
000
11100000000
11111111
1111111
0000000
00
11
006
11
0
1
0
1
00
11
000
111
00
11
0
1
0
1
000
111
00
11
000
111
00
11
000
111
00
11
000
111
00 7
11
0
1
1
000
111
00
11
0
1
0
1
0
1
Figure 1: Example showing orbits of subgroup of Aut(G), {{1,3},2,5,6,{4,7}}
not permute the elements across the cells in Πi (note two partitions are equal if both of them contain same cells
irrespective of the order of elements in the cells), more formally if Πi = Ππi i then πi fixes Πi , Ππi i is constructed
from Πi and πi as follows, let v πi be the image of v ∈ V when permutation πi is applied, then Ciπi = {v πi |v ∈ Ci }
and Ππi i = {Ciπi |Ci ∈ Πi }. Since ≤ creates a partial order among the elements of Π(V ), given a Πi and πi which
′
fixes Πi we can always find a partition such that Πi ≤ Πi ≤ . . . ≤ {1, 2, 3, . . . n} , note {1, 2, 3 . . . n} is the
′
′
corsest partition among all Π(V ) and Πi is the finest partition which is just corser than Πi , lets denote Πi by
(Πi ∨ πi ). Let W ⊂ V and v ∈ V then d(v, W ) = |{(v, vk ) ∈ E|vk ∈ W }| when G = (V, E) and E is set of
edges of G. A partition is said to be equitable if Ci , Cj ∈ Πi and v1 , v2 ∈ Ci we have d(v1 , Cj ) = d(v2 , Ci ).
Let {1, 2, 3, 4}, {2, 1, 3, 4}, {1, 2, 4, 3}, {2, 1, 4, 3} be permutation sub group then the orbit of element 1(and also
element 2) is {1, 2} and orbit of element 3 (and also element 4) is {3, 4}.
3 McKay’s algorithm for computing the Aut(G) and Canon(G)
In this section we briefly describe the algorithm given by McKay[McK78] the idea of partitioning the vertex
set V has been borrowed from [CG70]. The algorithm is uses a back tracking approach to find the Aut(G) of
the given graph G. The algorithm starts off with a equitable partition lets call this Πroot the algorithm uses a
procedure called Refinement on Πroot and generates a set of children for the partition Πroot lets call these Πchild ,
the childred of Πroot is generated by the Refinement procedure which makes sure that each partition Πchild is
the coarsest partition which is finer than Πroot , that is {(1), (2), (3) . . . (n)} ≤ . . . ≤ Πchild ≤ Πroot note that
{(1), (2), (3) . . . (n)} is the finest partition (also known as discrete) among all of Π(V ). Once a Πchild becomes
discrete this becomes a terminal node in the back track(depth first) search tree of the algorithm. Again note the
important fact that each child of the of a parent is both equitable and its the coarsest partition which is finer than
the parent (please see section2 to get this point clear), note that once we generate atleast two discrete partitions
we can relabel others relative to one of these and generate the automorphisms thats the basis for generating this
backtrack search tree from the given graph, initially when the algorithm starts the partition is the coarsest i.e
{(1, 2, 3 . . . n)} on this we apply the Refinement procedure to finer equitable partitions and this method continues.
Lets take forexample the graph in figure2 it has 6 automorphisms see the figure2, in figure3 it can be seen how
the children are generated from the root which is a equitable partition of two cells {(1, 2, 3), (0)} (at this moment
3
1
1
2
0
0
3
3
2
2
2
0
0
1
3
3
1
3
3
0
0
1
2
1
2
Figure 2: Example showing automorphisms Aut(G) = {(1, 2, 3, 0), (1, 3, 2, 0), (2, 1, 3, 0), (2, 3, 1, 0), (3, 1, 2, 0), (3, 2, 1, 0)}
lets ignore how we generated it later we will see in next section on how to generate a equitable partition which is
coarsest but finer than any given partition, using in Refinement procedure). At this stage there are two questions
we might be wondering as follows
• How do we generate the Πchild (which is both equitable and coarsest partition finer than Πroot ) from Πroot
using the Refinement procedure ?
• How can the terminal partitions can help in generating the Aut(G) ?
3.1 Generating a equitable partition which is the coarsest among all the finer partitions which are
finer than a given partition
As were were indicating in the previous section at any stage during the backtrack depth first tree similar to the
figure3 we need to make sure that the childred generated from a root node follow the below two properties.
• The child node Πchild generated from Πroot should be equitable
4
Dotted edge indicate
the children under this
edge is not generated(pruned)
{(1,2,3),(0)}
2
1
Use one of the
discrete partition and
generate automorphism
group relative
to this
{(2),(1,3),(0)}
{(1),(2,3),(0)}
{(1),(2),(3),(0)}
2
1
3
{(1),(3),(2),(0)}
{(2),(1),(3),(0)}
Figure 3: Example of the backtrack tree generated for graph in fig2
• Let F = {Πi |Πi ≤ Πroot } denote all the partitions which are finder than Πroot then Πchild is the coarsest
among all of F .
One way of generating a finer(and coarsest) equitable partition is to select a cell (Ci ) from Πroot = {C1 , C2 . . .}
such that |Ci | ≥ 2 and select a vi ∈ Ci and create a new partition with just one vertex(vi ) and use this partition
each of Cj ∈ Πroot according to value of d(vi , Cj ) this is going to create the child partition with the properties
mentioned above. For example for graph in figure2 one equitable partition is {(1, 2, 3), (0)} so if we pick vertex 1
from cell (1, 2, 3) we have split other cells on the value of d(1, Cj ) in this case it happens we need to split only cell
(1, 2, 3). So using this simple procedure we can generate child nodes in the depth first tree for the entire algorithm.
3.2 Generating Aut(G) from terminal partitions of the backtrack search tree
Lets answer the second question now, assume that the algorithm generated all the children with all the properties
which we discussed earlier and X be the set of all the terminal partitions, once we have all the terminal partitions we can pick any one of these and find all the permutations relative to this which gives all the elements
in the automorphism group Aut(G). For example take the first terminal partition(shown in the dotted border
{(1), (2), (3), (0)}) in the backtrack tree in the figure3 and now consider another terminial partition shown in
the bold border {(1), (3), (2), (0)} since we keep {(1), (2), (3), (0)} as constant so the bold border partition can
be described by a permutation π1 = {1, 3, 2, 4} that is if we apply π1 to terminal partition which is kept constant we can generate other partitions interms of the permutations, this is exactly what we are looking to have in
the automorphism group. More specifically X is the set of all the terminal partitions, lets pick a τ ∈ X then
Aut(G) = {πk |τ = ǫπk , ǫ ∈ X, τ ∼ ǫ} , τ1 ∼ τ2 iff Gτ1 = Gτ2 . Finally since we have all the terminal partitions
in X we can generate all the graphs from labellings in X lets call this set G(X) then G(X) = {Gτ |τ ∈ X}
we can sort all G(X) lexicographically and make Canon(G) = max{Gτ |τ ∈ X}. Since |X| could be O(n!)
the algorithm employs efficient pruning strategies based on automorphisms already generated, this is based on
creating orbits from the existing terminal partitions. For example in the figure3 we can see several parts of the tree
pruned since the terminal partitions can be generated from already know automorphisms, lets take for example
after we generate the first two terminal partitions {(1), (2), (3), (0)} and {(1), (3), (2), (0)} the orbits of this sub
group is θ = {1, [2, 3], 0} during any expansion of a root partition if the vertex which is going to be fixed falls
in a orbit we can safely ignore that part of the tree. Lets see how this works after finding the first two terminal
5
partitions the orbits are as in θ since in the next step we fix the element 2 and it does not fall in the first orbit of
θ we go ahead expanding it similarly at the second level 1 does not fall in the second orbit of θ i.e ([2, 3]) so we
go ahead and create a next terminal partition which is {(2), (1), (3), (0)} the algorithm always updates the current
orbit information once it reaches a terminal partition in this case if we add {(2), (1), (3), (0)} to the current orbit
list which is θ = {1, [2, 3], 0} since from {(2), (1), (3), (0)} its clear that vertex 1 could be mapped to 2(which is
already in a orbit) also we combine these to create a orbit [1, 2, 3] and thus θ becomes θ = {[1, 2, 3], 0} so when
we next expand the root node with 3 which is already in orbit we just prune that part of the tree.
4 Ullmann’s Algorithm for Sub Graph Isomorphism
In contrast to Graph Isomorphism problem, Sub Graph Isomorphism problem has been shown to be a N P −
Complete problem, with a direct reduction from the Clique problem. Let Gα be the graph which we are looking
′
for a isomorphic partner from Gβ , then if Gβ the isomorphic subgraph in Gβ for Gα then the following should
′
′
′
hold. Let Vα ,Vβ and Vβ be the vertex sets of Gα , Gβ and Gβ . Let vi ∈ Vβ corresponds to vj ∈ Vα then for
degree(vi , Gβ ) ≥ degree(vj , Gα ). A brute force algorithm for solving the sub graph isomorphism problem may
choose |Vα | vertices from |Vβ | and check if the selected vertices have the same adjacency with Gα (by trying
out all the permutations of the vertices). We can slightly do better than this brute force algorithm by having a
′
matrix M of size |Vα | × |Vβ |, this is basically a matching matrix which has only one 1 in any row or column, if
′
m′ ij ∈ M , m′ ij = 1 then vi ∈ Vα is mapped to
/*Recursive procedure Call Recursively(depth) */
if d = 0 then
Md = M ;
if d = |Vα | then
′
// Found a M (Md ) check for isomorphism
// If isomorphic print it
return ;
// Find a match at this depth
for i = 0 to |Vβ | do
if mdi 6= 0 and F illedi 6= 1 then
F illedi = 1 ;
// set all entries to 0 in row d of Md except for column i
Call Recursively(d + 1) ;
F illedi = 0 ;
// set the row d of Md to row d of M
return ;
Algorithm 1: Recursive enumeration procedure Call Recursively of ullmann
′
vj ∈ Vβ a brute force algorithm may try all possible M matrices and check for each matrix if the matching
′
vertices for a isomorphism or not. In fact we can reduce some of the useless M matrices by starting off with a
matrix M of size |Vα | × |Vβ |, ∀mij ∈ M , mij = 1 if degree(i, Gα ) ≤ degree(j, Gβ ) otherwise mij = 0 we
can also explicitly set mij = 0 if we know before hand that vi ∈ Vα cannot correspond to vj ∈ Vβ . Once we
′
′
setup M , M can be generated from M systematically by the recursive algorithm in Algorithm1, M = Md at
the depth (d = |Vα |). The algorithm given by [Ull76] is more efficient in pruning several useless nodes during
the recursive computation of the Algorithm1, note the very important fact from looking into Algorithm1 that
intermediate matrix (Md ) at any depth d differs from M in the first d rows and the bottom |Vα | − d rows of M
6
and Md are the same, the standard recursive algorithm does not use any information from the fact that first d rows
are fixed (i.e the correspondence has been established between first d vertices of Gα to Gβ ), this is were ullmanns
observation helps suppose a vertex vβi ∈ Vβ has been mapped to vαj ∈ Vα let vαx ∈ Vα all the vertices which
are adjacent to vαj ∈ Vα then vαx ∈ Vα can only be mapped to some vertex vβx ∈ Vβ such that vβx is on the
adjacency list to vβi , thus we can update the rows(in Md ) corresponding to vertices vαx ∈ Vα (note vαx is any
node adjacent to vαj in graph Gα ) as follows if md αxj = 1 and j ∈
/ {vβx |(vβx , vβi ) ∈ Eβ } then we can make
md αxj = 1 to md αxj = 0 thus reducing the number of 1’s in the matrix Md and hence pruning useless nodes.
This is example of dynamic pruning similar to pruning the nodes in the backtrack algorithm which we described
earlier (in that case pruning is based on already discovered permutations).
References
[CG70]
D. G. Corneil and C. C. Gotlieb. An efficient algorithm for graph isomorphism. In Journal of the ACM
(JACM), pages 51–64, Volume 17 , Issue 1 (January 1970).
[CRS97] D. Cvetković, P. Rowlingson, and S. Simić. Eigenspaces of graphs. In Cambridge University Press,
1997.
[GM01] C. D. Godsil and B. D. McKay. Constructing cospectral graphs. In Acquationes Mathematicae, pages
257–268, 2001.
[Har62]
F. Harary. The determinant of the adjacency matrix of a graph. In SIAM Review, pages 202–210, Vol.4,
1962.
[McK78] Brendan D. McKay. Computing automorphishms and canonical labelling of graphs. In Combinatorial
Mathematics, pages 223–232, Volume 686/1978.
[McK81] B. D. McKay. Practical graph isomorphism. In Congressus Numerantium, pages 45–87, 1981.
[Sch73]
A. J. Schwenk. Almost all trees are cospectral. In New Directions in the Theory of Graphs (Proc. Third
Annual Arbor Conference), pages 275–307, 1973.
[Ull76]
J. R. Ullmann. An algorithm for subgraph isomorphism. In Journal of the ACM (JACM), pages 31–42,
Volume 23 , Issue 1 (January 1976).
[Ung64] S. H. Unger. Git – a heuristic program for testing pairs of directed line graphs for isomorphism. In
Comm. ACM, pages 26–43, Jan, 1964.
7