A Polynomial Time Algorithm for Graph Isomorphism and Automorphism

This paper describes a polynomial time algorithm for solving graph isomorphism and 1 automorphism. We introduce a new tree data structure called Walk Length Tree. We show that such 2 tree can be both constructed and compared with another in polynomial time. We prove that graph 3 isomorphism and automorphism can be solved in polynomial time using Walk Length Trees. 4


Introduction
The graph isomorphism (GI) problem is one of the most famous open problems 7 in theoretical computer science. Two graphs are isomorphic if there exists a bijective 8 function between their vertex sets that preserves adjacency relationship. Two Graphs, 9 with n vertices each, have n! possible one to one correspondences between the vertex sets. 10 So, checking all such correspondences for large n is impractical. Graph automorphism is 11 a similar problem like GI, where the input is a single graph and we have to find out all 12 possible mappings to itself. In other words, automorphism means graph isomorphism 13 with itself. 14 GI is an important tool for a number of areas including computer vision, pattern 15 recognition, bioinformatics, mathematical chemistry and electronic design automation. 16 As an example, chemists use graphs to model chemical compounds, where vertices and 17 edges represent atoms and chemical bonds respectively. A new synthesized chemical 18 compound is required to be checked with other potential molecular graphs from a 19 database to see whether the molecular graph of the new compound is the same as one 20 already known. 21 It can be shown that these problems are in NP and it is unknown whether it has 22 polynomial time algorithm or they are in NP-complete [13]. In this paper, we propose 23 a new polynomial time algorithm for solving graph isomorphism problem. In other 24 words, in this paper, we prove that they are in P. 25 Two isomorphic graphs must have same number of vertices and edges. The degrees 26 of the corresponding vertices in isomorphic graphs must be the same. They must also 27 have simple circuits of same length. It is possible that these invariants are same for 28 two graphs that are not isomorphic. There are no useful sets of invariants currently 29 known that can be computed in polynomial time to determine whether two graphs are 30 isomorphic [21]. 31 The list of published algorithms that attempt to solve GI is long [13]. We are 32 listing a few of those. The best currently accepted theoretical algorithm, which has 33 e O( √ n log n) time complexity, is due to [2]. Later, the author claimed that GI is in quasi-  The diameter d of a graph is the greatest distance between any pair of vertices. For 99 a disconnected graph, the distance between two unreachable vertices is ∞.

100
Suppose that the vertices of a graph G are listed arbitrarily as v 0 , . . . , v n−1 . So, the 101 i-th vertex in the list is v i . The adjacency matrix of G, denoted by A G , with respect to 102 this listing of the vertices, is the n × n integer valued matrix, such that: is the number of edges between v i and v j .
[j] is the number of edges from v i to v j .

105
The adjacency matrix of graphs in Figure 1 for the vertex listing [a, b, c, d, e, f , g, h] is 106 given in Eqation 1.
For an adjacency matrix A G and a positive integer r > 0, we define the power of 108 a matrix by repeating matrix multiplication; that is A r G = A G × · · · × A G r times . We define 109 M(n), as the time complexity of matrix multiplication routine for two dense square 110 matrices of order n. From literature, we know M(n) is polynomial, with respect to n [9].

111
Theorem 1 (Counting walks among vertices as stated in [21]). Let G be a graph with vertex v i ∈ V. This classification is important in Walk Length Tree construction. We 120 then describe a suitable data structure to store edge weights and parallel edges. This 121 data structure is useful for our proposed algorithms. Moreover, we simplify problem 122 statement by using this data structure. We provide two other simplifications in subsection  where s a ≤ s b . We will call e is an edge of (s a + 1)-radius from v i . If any vertex is not reachable 138 from v i , then any edge connected with it is called an edge of ∞-radius from v i . In Figure 1, the 139 length of the shortest paths from a to b and c are 3 and 2 respectively. So, the edge (b, c) is an 140 edge of 3-radius from vertex a.

141
Definition 2 (Edge distance from v i of a directed graph G(V, E)). Let e ∈ E be an edge 142 that is connecting from vertex v a ∈ V to vertex v b ∈ V. The length of the shortest path from 143 v i ∈ V to v a is s a . We will call e is an edge of (s a + 1)-radius from v i . If any vertex is not 144 reachable from v i , then any edge connected with it is called an edge of ∞-radius from v i . In 145 Figure 10, the length of the shortest paths from u 1 to u 4 is 2. So, the edge (u 4 , u 3 ) is an edge of 3 146 radius from vertex u 1 .
to find all pair shortest paths [9]. We first compute the shortest path between all pair 158 of vertices. We then classify any edge from the perspective of any vertex following (ii) between v a and v b (for undirected graph). 168 We store q and the edge weights (for weighted graphs) in ascending order.

3.
For weighted multigraphs, we apply multi-criterion sorting described below to 180 sort the edge weights.

181
• We consider the ordering of the vertices as given in the adjacency matrix that 182 represents the graph in the following way.

183
• For directed graph, the weight of edge (v x , v y ) appears before the weight of

Simplification
We describe all properties, theorems, and our proposed algorithms (in section 4) for 206 connected undirected graphs and weakly connected directed graphs only.

207
Let G(V, E) be a disconnected undirected graph that has N connected components, 208 where N is a finite positive number and |V| ≥ N > 1. Any disconnected undirected 209 graph G (V , E ), which is isomorphic with G(V, E), must have N connected components.

210
Suppose we know two polynomial time algorithms to detect graph automorphism and 211 isomorphism for connected components. We need to call those algorithms N and 212 N(N + 1)/2 times to detect graph automorphism and graph isomorphism respectively.

213
Thus, the time complexity of graph automorphism and isomorphism checking for 214 undirected graph remains polynomial. 215 We define weakly connected components of a directed graph as the subgraphs of a di-216 rected graph G that are weakly connected but not contained in larger weakly connected 217 subgraphs, that is, the maximal weakly connected subgraphs, are called the weakly 218 connected components of G. Let G(V, E) be a directed graph that has N weakly con-219 nected components, where N is a finite positive number and |V| ≥ N > 1. Any directed We define this tree by the way it is 230 constructed.

231
• T v i (G) is a rooted tree of height n.We call v i as the reference vertex of T v i (G).

232
• A node at the l-th level of the tree denoted as N(l, j), where j is the position of the node from 233 left, contains a tuple (W, p, Z), where W ⊆ V, p is positive integer, and Z ⊆ E.

4.
if (v a , v b ) is an edge of l-radius edge from v i , it is assigned to the Z set of a node 257 N(r, j), where r = l and j is chosen in the following way. 258

5.
for a directed graph, this edge is an element of the Z set of the same node N(l, j), 259 whose W set contains v b . 260 6.
for an undirected graph,

261
(case 1) Let both v a , and v b be in the W set of a node N(l, j), it is assigned to the Z 262 set of N(l, j).

263
(case 2) If v a and v b be in the W set of N(l, j) and N(l, j 1 ) respectively, where j 1 > j, 264 it is assigned to the Z set of N(l, j).

265
The WLT of the graph in Figure 1 from vertex a is given in Figure 3. It can be 266 verified by raising the adjacency matrix (in equation 1) to power of 2, . . . , 8. We insert 267 the node information N(l, j) with each node of this WLT.

268
The WLT of the graph in Figure 2 from vertex B is given in Figure 4.    the same node at level l. Now, we assign each part to the W set of the appropriate node 282 at level l + 1. We implement a multi-criterion based comparator function and use it 283 in a comparison based sorting algorithm to do this partition. This sorting is done in 284 polynomial time with respect to n.

285
For a WLT, we have n levels. So in total, we have n 2 levels over n such trees.

286
Thus the complexity of constructing trees, without Z sets, from A r G , for r = 2, . . . , n is 287 polynomial with respect to n. 288 We store all W sets in a hash table, such that we can get a particular W set by calling 289 a hash function with N(l, j). We also need to know the list of nodes at each level, where 290 a vertex is assigned to their W set. We store it by a list of n integers. So a n × n integer 291 matrix can store this information.

292
We apply edge classification method discussed in Lemma 1 to know the edge and v b , we know the nodes in level l whose W sets contain these two vertices. have two nodes N(l 1 , j 1 ) and N(l 2 , j 2 ) from two different WLTs. We say N(l 1 , j 1 ) and N(l 2 , j 2 ) 304 are shallow equivalent if and only if all of the following assertions are true:

307
• the p value of both nodes are equal.

308
• the cardinality of W sets of both nodes are equal.

309
• the cardinality of Z sets of both nodes are equal.

310
• both nodes have equal number of child nodes.

311
• if the W set of N(l 1 , j 1 ) contains the reference vertex of its WLT, the W set of N(l 2 , j 2 ) must 312 contain the reference vertex of its WLT and vice versa.

313
Definition 6 (Shallow equivalent between two Walk Length Trees). Two WLTs,       Thus, we can create n different WLTs from a graph that has n vertices.

345
Lemma 4 (Reconstructing of a graph from a Walk Length Tree). Given a WLT T v (G) and 346 the data structure as described in Definition 3 that stores parallel edges with weights, we can 347 reconstruct G.

348
All l-radius edges, where n ≥ l > 0, from v can be found in the Z sets of all nodes in 349 level l of the WLT T v (G). In this paper, we show that how WLTs are used to distinguish 350 each vertices and edges.
defined as a subgraph of G(V, E), whose edge set E l ⊆ E contains edges of k-radius from v i , 353 where k = 1, . . . , l.

354
For example, Figure 5, Figure 6 are leveled graphs G 1 (V, E 1 ) and G 2 (V, E 2 ) respec-355 tively of graph in Figure 1 considering WLT in Figure 3. It should be noted that of the graph in Figure 1 considering WLT in Figure 3 has all edges of the graph.  Figure 6. Leveled graph G 2 (V, E 2 ) of graph in Figure 1 considering WLT in 3.
vertex v ∈ V is called shallow equivalent to a vertex v ∈ V if their ranks are same.

372
The reference vertices of these two WLTs are called shallow equivalent as they are 373 in the W set of two shallow equivalent leaf nodes.

374
From Definition 9, the following shallow vertex equivalencies between the Walk 375 Length Trees in Figure 3 and Figure 4 can be found.

376
• vertex a and b are shallow equivalent to vertex B and C respectively.
Let v a and v a be two shallow equivalent vertices from 383 G(V, E) and G (V , E ) respectively with respect to these WLTs. If v a and v a are in the W sets 384 of node N(l, j) and N(l, j ) respectively, for l ≥ 0 then j = j .

385
Proof. We prove it by contradiction. Suppose, j < j . If we visit the vertices in the W 386 sets of the leaves of any of the WLTs from left to right we will see vertices in the W set 387 of N(l, j) before those of N(l, j ). So the rank of any vertices in the W set of N(l, j) is 388 smaller than the rank of all vertices in the W set of N(l, j ). So the rank of v a is smaller 389 than the rank of v a . This is a contradiction as they are shallow equivalent. So j = j and 390 these two nodes are shallow equivalent.

391
The ordering of vertices based on the rank is not enough when we check the 392 equivalency between two WLTs. Because two vertices having same rank might be 393 different considering their edges. Given a graph G(V, E) and a WLT T v i (G), we sort the Algorithm 1 Comparator function to sort the vertices Input: vertices u and v along with their ranks with respect to a WLT 1: if u has greater rank than that of v w.r.t the WLT respectively then 2: return TRUE 3: else if v has greater rank than that of u w.r.t the WLT respectively then 4: return FALSE 5: else if u has more loop edges than that of v then 6: return TRUE 7: else if v has more loop edges than that of v then 8: return  20: return FALSE 21: else 22: We need to sort all edges that have u or v as endpoints separately in the following way.
in sorted order based on the comparator function given in 1 end if 8: end for Definition 10 (Comprehensive rank of vertices). Given a graph G(V, E) and a WLT T v i (G), 407 we sort the vertices as described above. We call Algorithm 2 with the sorted list of vertices and 408 T v i (G) to assign a positive integer C(v) for each vertex v ∈ V in the graph. We call C(v) as the 409 comprehensive rank of vertex v with respect to T v i (G).

410
The comprehensive ranks of vertices in the graph given in Figure 1 with respect to 411 the Walk Length Tree in Figure 3 are the same as their rank.
(for directed graph) v x , and v y are shallow equivalent to v x , and v y respectively.

416
(for undirected graph) v x , and v y are shallow equivalent to either v x , and v y respectively or v y , 417 and v x respectively.

Algorithm 3 Comparator function to order edges
Input: edges (u, v) and (u , v ) and a WLT 1: (u, v) is a l-radius edge with respect to the reference vertex of its WLT 2: (u , v ) is a l -radius edge with respect to the reference vertex of its WLT 3: if the WLT is created based on a undirected graph, we assume that C(u) ≤ C(v) and C(u ) ≤ C(v ) 4: if l > l then 5: return TRUE 6: else if l < l then 7: return FALSE 8: else if C(u) > C(u ) with respect to their respective WLTs then 9: return TRUE 10: else if C(u ) > C(u) with respect to their respective WLTs then 11: return FALSE 12: else if C(v) > C(v ) with respect to their respective WLTs then 13: return TRUE 14: else if C(v ) > C(v) with respect to their respective WLTs then 15: return FALSE 16: else if the q value of (u, v) is greater than that of (u , v ) [as described in Definition 3] then 17: return TRUE 18: else if the q value of (u , v ) is greater than that of (u, v) [as described in Definition 3] then 19: return FALSE 20: end if 21: for weighted multigraphs, the sorted edges weights are extracted from hash table as described in Definition 3 as two separate lists 22: for i = 0, 1, . . . , q − 1 do 23: if the weight of the i-th edge of (u, v) pair is greater than that of (u , v ) pair then

450
• E s contains all edges of E c , whose at least one endpoint is v.

451
• for each edge e s ∈ E s , we add both of its endpoints in V s .
We call G s (V s , E s ) the star subgraph of G(V, E) centered at v ∈ V for the edge set E c ⊆ E. 453 We denote v ∈ V as the center vertex of this star subgraph.

454
The star subgraph of the undirected graph in Figure 7 centered at c for an arbitrary 455 edge set {(a, c), (a, b), (b, c), (c, d), (e, f )} is given in Figure 9. respectively. Given two edge sets E g ⊆ E and E g ⊆ E , we create two star subgraphs G s (V s , E s ) 462 and G s (V s , E s ) centered at u ∈ V and u ∈ V for E g ⊆ E and E g ⊆ E respectively. 463 We call u ∈ V and u ∈ V are equivalent for the given edge sets E g and E g with respect to 464 the given shallow equivalent WLTs, if G s (V s , E s ) and G s (V s , E s ) are isomorphic and the bijective 465 function that shows their isomorphism must satisfy the following constraints.

466
• u must map to u and C(u) = C(u ).

467
• if any vertex v ∈ V s maps to vertex v ∈ V s , then C(v) = C(v ).

468
• if any edge e ∈ E s maps to edge e ∈ E s , then B(e) = B(e ).

469
Furthermore, we call u ∈ V and u ∈ V are equivalent with respect to the given shallow The vertex a of Figure 1 is equivalent with the vertex B of Figure 2 with respect to 482 WLTs in Figure 3 and Figure 4 respectively.

Algorithm 5 Checking if two given star graphs are isomorphic
Input: (i) star subgraph G s (V s , E s ) and G s (V s , E s ) as discussed in Definition 14, (ii) the comprehensive ranks of all vertices and all edges of the subgraphs with respective to some WLTs, and (iii) the center vertices u ∈ V and u ∈ V of G s (V s , E s ) and G s (V s , E s ) respectively.
return FALSE 3: end if 4: mark all vertices in V s and V s as unchecked except u and u . mark u and u as checked 5: for each vertex v ∈ V s that are unchecked do 6: if there exists an unchecked vertex v ∈ V s such that (i) C(v) = C(v ), (ii) B(u, v) = B(u , v ), these two edges are equivalent considering the parallel edges and weights as described in Definition 3 and (iii) B(v, u) = B(v , u ) these two edges are also equivalent considering the parallel edges and weights as described in Definition 3. then 7: 8: mark v and v as checked  Tree of a directed graph). Let G n (V, E n ) be the leveled graph of a WLT T v i (G) for a directed 508 graph G(V, E). The neighbor edge set E g of T v i (G) is a set of edges such that (i) E g ⊆ E, (ii) 509 E g ∩ E n = ∅, and (iii) for an edge e ∈ E g , it is ∞-radius from v i and exactly one endpoint of e 510 is not reachable from v i .

511
The neighbor vertex set V g of T v i (G) is a set of vertices such that (i) V g ⊂ V, (ii) any vertex 512 v ∈ V g is not reachable from v i , and (iii) there exists at least one neighbor edge of T v i (G), where 513 v is the initial vertex.  WLT, (iv) v and v are equivalent with respect to their respective WLTs, so, they are equivalent 528 for the Z edge sets of any two shallow equivalent nodes. We put one more requirements to the 529 bijective function between their edge sets, which is used to prove the isomorphism between the 530 star graphs centered at v and v , that is if one edge maps to another edge, their other endpoints 531 must be equivalent with respect to the given WLTs.

532
If we compute all WLTs of the directed graphs in Figure 10 and Figure 11, we can 533 see the following equivalent WLTs of first degree.

535
• WLTs T u 9 (G), and T v 9 (G ) are equivalent of first degree.

536
• WLTs T u 2 (G), T u 6 (G), T u 10 (G), T v 2 (G ), T v 6 (G ), and T v 10 (G ) are equivalent of first 537 degree.   between neighbor edges of the form (u, u x ) and the neighbor edges of form (u , u x ) such that 552 C(u x ) = C(u x ) considering T v (G) and T v (G ) WLTs.

553
Given the equivalent WLTs of first degree of the directed graphs in Figure 10 and 554 Figure 11, we can see the following equivalent WLTs of second degree.

555
• WLTs T u 1 (G), and T v 1 (G ) are equivalent of second degree.

556
• WLTs T u 5 (G), and T v 5 (G ) are equivalent of second degree.

557
• WLTs T u 9 (G), and T v 9 (G ) are equivalent of second degree.

558
• WLTs T u 10 (G), and T v 10 (G ) are equivalent of second degree.

559
• WLTs T u 2 (G), and T v 2 (G ) are equivalent of second degree.

573
Given the equivalent WLTs of second degree of the directed graphs in Figure 10 574 and Figure 11, we can see the following equivalent WLTs of third degree.

575
• WLTs T u 1 (G), and T v 1 (G ) are equivalent of third degree.

576
• WLTs T u 5 (G), and T v 5 (G ) are equivalent of third degree.

577
• WLTs T u 9 (G), and T v 9 (G ) are equivalent of third degree.

578
• WLTs T u 10 (G), and T v 10 (G ) are equivalent of third degree.

579
• WLTs T u 2 (G), and T v 2 (G ) are equivalent of third degree.

580
• WLTs T u 6 (G), and T v 6 (G ) are equivalent of third degree.

581
• WLTs T u 3 (G), and T v 3 (G ) are equivalent of third degree.

582
• WLTs T u 7 (G), and T v 7 (G ) are equivalent of third degree.

583
• WLTs T u 11 (G), and T v 11 (G ) are equivalent of third degree.

584
• WLTs T u 4 (G), and T v 4 (G ) are equivalent of third degree.

585
• WLTs T u 8 (G), and T v 8 (G ) are equivalent of third degree.

586
• WLTs T u 12 (G), and T v 12 (G ) are equivalent of third degree.   T v (G) or the WLTs, where these vertices are reference vertices are not equivalent.

630
For example, for the Walk Length Tree given in Figure 3, we need the following 631 information.

632
• the graph which is given in in Figure 1. And, for the Walk Length Tree given in Figure 4, we need the following information.

636
• the graph which is given in in Figure 2.  return FALSE 3: end if 4: mark all neighbor vertices of T v (G ) as unchecked 5: for each neighbor vertex u of T v (G) do 6: let V A be the list of host vertices of u that are sorted considering their comprehensive ranks with respect to T v (G) 7: for each unchecked neighbor vertex u of T v (G ) such that T u (G) and T u (G ) are two equivalent WLTs of i-th degree do 8: let V A be the list of host vertices of u that are sorted considering their comprehensive ranks with respect to T v (G ) Theorem 4 (Isomorphic undirected graphs and one to one correspondence between 646 vertices). Let G(V, E) and G (V , E ) be two isomorphic undirected graphs that are connected.

647
That means there exists a bijective function between V and V that preserves adjacency relation- 648 ship. If that bijective function maps between v ∈ V and v ∈ V then T v (G) and T v (G ) are 649 equivalent.

650
Proof. Suppose, the bijective function maps between u ∈ V and u ∈ V . Both u and 651 u have equal number of l length paths from v and v respectively, for l ≥ 1. Suppose 652 node N(l, j) in T v (G) contains u in its W set. If u has a 1 , . . . , a l number of 1, . . . , l length 653 paths from v respectively then u also has a 1 , . . . , a l number of 1, . . . , l length paths from 654 v respectively. So, N(l, j) node in T v (G ) must contain u in its W set.

655
First, we claim that these two nodes are shallow equivalent.

667
Theorem 5 (Isomorphic directed graphs and one to one correspondence between ver-668 tices). Let G(V, E) and G (V , E ) be two isomorphic directed graphs that are weakly connected.

669
That means there exists a bijective function between V and V that preserves adjacency relation-  return FALSE 6: end if 7: pick any part that has more than one WLTs 8: possibleMapping := number of WLTs in the chosen part 9: pick any two WLTs T u (G) and T v (G) from the chosen part 10: mark all vertices as both unmappedL and unmappedR 11: MAP undir automorphism (T u (G), T v (G)) 12: while there is unmappedL vertices do 13: choose a set of equivalent unmappedL vertices A and unmappedR vertices B with respect to T u (G) and T v (G) respectively, s.t all WLTs are equivalent where these vertices are reference vertices. 14: for each unmappedL vertex u a ∈ A do 15: choose an unmappedR vertex v a ∈ B 16: MAP undir automorphism (T u a (G), T v a (G)) 17: end for 18: possibleMapping := possibleMapping * |A| 19: end while 20: return TRUE Proof. We prove it by contradiction. Suppose G has automorphism and u ∈ V maps to 717 v ∈ V. So, T u (G) and T v (G) are equivalent and they are kept in the same part, which 718 creates the contradiction.

719
Algorithm 8 ROUTINE MAP undir automorphism (T u (G), T v (G)) 1: declare: u maps to v 2: mark u and v as mappedL and mappedR respectively. They are no more marked as unmappedL or unmappedR 3: while in T u (G), there is an unmappedL vertex u a , for which there is no equivalent unmappedL vertex (w.r.t T u (G)) s.t their WLTs are equivalent do 4: let v b be the equivalent unmappedR vertex in T v (G) s.t T u a (G) and T v b (G)) are equivalent 5: MAP automorphism (T u a (G), T v b (G)) 6: end while Lemma 21 (Automorphism). Given a graph G(V, E), we partition all WLTs, so that each part 720 contains equivalent WLTs and two WLTs from two different parts, are not equivalent. Suppose, 721 one part contains more than one WLTs. We take two of such equivalent WLTs: T u (G) and T v (G), 722 we claim that G has automorphism and we can map between u and v.

723
Proof. We can reconstruct the same graph from T u (G) and T v (G) separately. Suppose, 724 we create leveled graphs from these two WLTs. Consider, the leveled graphs are isomor- partition all WLTs, so that each part contains equivalent WLTs and two WLTs from two different 736 parts, are not equivalent. Suppose, one part contains more than one WLTs. We take two of 737 such equivalent WLTs: T u (G) and T v (G). Let there exist two vertices u a , u b ∈ V such that 738 they are equivalent with respect to T u (G) and T v (G). Let u a and u b be from T u (G) and T v (G) 739 respectively. Let T u a (G) and T u b (G) be equivalent and there exists no such vertex pair. If we 740 map between u and v, we must map between u a and u b .

741
Proof. Like the proof of Lemma 21, we reconstruct G from T u (G) and T v (G) separately.

742
Both leveled graphs from these two WLTs are isomorphic at any level. As u a and u b are 743 equivalent with respect to T u (G) and T v (G), the edges, that are incident to them, are we partition all WLTs, so that each part contains equivalent WLTs and two WLTs from two 748 different parts, are not equivalent. Suppose, one part contains more than one WLTs. We take 749 two of such equivalent WLTs: T u (G) and T v (G). In both WLTs, there exists a vertex u a ∈ V 750 such that it is equivalent with respect to T u (G) and T v (G). And there is no other vertices that is while SUCCESS == FALSE and the stack is not empty do 16: pop from stack. let (u, v) be the pair from the stack. 17: if both T u (G) and T v (G) are marked as incomplete then 18  RETURN 3: end if 4: declare: u maps to v 5: mark u and v as mappedL and mappedR respectively. they are no more marked as unmappedL or unmappedR 6: partition all incomplete WLTs, whose reference vertices are not in the stack and are neighbor vertices of u and v, s.t each part contain equivalent WLTs and two WLTs from two different parts are not equivalent. 7: for each part that contains more than one WLTs do 8: possibleMapping := possibleMapping * 0.5 * the number of WLTs in the part 9: create ordered pairs of vertices with the reference vertices of the WLTs in the part s.t in each ordered pair (u c , u d ), u c and u d are neighbor vertices of u and v respectively. and each vertex participates in one of such pair only. push all such pairs in the stack. 10: end for 11: while in T u (G), there is an unmappedL vertex u a , for which there is no equivalent unmappedL vertex (w.r.t T u (G)) s.t their WLTs are equivalent do 12: let v b be the equivalent unmappedR vertex in T v (G) s.t T u a (G) and T v b (G)) are equivalent 13: MAP dir automorphism (T u a (G), T v b (G)) 14: end while equivalent to u a with respect to T u (G) and T v (G). If we map between u and v, u a must map to 752 itself.

754
Lemma 24 (Further mappings in Automorphism). Given a graph G(V, E) with automor-755 phism, we partition all WLTs, so that each part contains equivalent WLTs and two WLTs from 756 two different parts, are not equivalent. Suppose, one part contains more than one WLTs. We take 757 two of such equivalent WLTs: T u (G) and T v (G). Let there exist two vertices u a , u b ∈ V such 758 that (i) they are equivalent with respect to T u (G) and T v (G) and (ii) T u a (G) and T u b (G) are 759 equivalent. Let u a and u b be from T u (G) and T v (G) respectively. If we map between u and v, 760 there exists a valid mapping between u a and u b .

761
Proof. Like the proof of Lemma 21, we reconstruct G from T u (G) and T v (G) separately.

762
Both leveled graphs from these two WLTs are isomorphic at any level. The edges from 763 any equivalent vertex pair with respect to T u (G) and T v (G) like u a and u b , that are 764 incident to them, are adding with the leveled graph exactly the same way. As T u a (G) 765 and T u b (G) are equivalent, u a has a valid mapping with v b . So, if we map u with v, we 766 can map u a with u b . 767 Remark 2 (Every vertex must be mapped in a graph with automorphism). Given a graph 768 G(V, E) with automorphism, we partition all WLTs, so that each part contains equivalent WLTs 769 and two WLTs from two different parts, are not equivalent. Suppose, one part contains more 770 than one WLTs. We take two of such equivalent WLTs: T u (G) and T v (G). Every vertex must 771 be mapped with another vertex or itself. Suppose, we map u with v. We have the following 772 mappings: (i) for each vertex in T u (G), there must exist an equivalent vertex with respect to 773 T u (G) and T v (G) such that the WLTs, where they are the reference vertices, must be equivalent,

774
(ii) if any two vertices are mapped they must be equivalent with respect to T u (G) and T v (G) 775 and the WLTs where they are the reference vertices must be equivalent, (iii) if two vertices are Algorithm 13 Graph Isomorphism (GI) between directed graph G, and G Input: two graphs and their adjacency matrix: G(V, E), G (V , E ), A G , and A G Output: TRUE or FALSE 1: compute A r G and A r G , where r = 2, . . . , n. compute all WLTs of both G and G and all WLTs as incomplete. partition all WLTs, s.t all equivalent WLTs are in one partition and no two WLTs from two different parts are not equivalent 2: if any part has odd number of WLTs or more than half of its WLTs are from one of the graph then 3: return FALSE 4: end if 5: mark all vertices as unmapped and mark all WLTs as incomplete. create a stack, where each item is an ordered pair of vertices. choose any part that has more than one WLTs. choose any two WLTs T u (G) and T u (G ) from the part. push (u, u ) in the stack 6: if MAP dir (T u (G), T u (G )) returns FALSE then 7: return FALSE 8: end if 9: while the stack is not empty do 10: while SUCCESS == FALSE and the stack is not empty do 12: pop from stack. let (v, v ) be the pair from the stack. 13: if both T v (G) and T v (G ) are marked as incomplete then 14: end if 16: end while 17: if SUCCESS == FALSE then 18: BREAK 19: end if 20: while there is unmapped vertices in T v (G) do 21: create two equivalent and unmapped vertex sets A and B w.r.t T v (G) and T v (G ) respectively, s.t all WLTs are equivalent where these vertices are reference vertices. 22: if |A| = |B| then 23 The i-th vertex in the first list maps to the i-th vertex in the second list, where 0 ≤ i < 8.

813
Consider, any pair of vertices, where we have a mapping from these lists. Let, b and c. 814 We can verify this mapping from the two WLTs, where they are the reference vertices. In considering their respective WLTs. This is true for any pair of vertices that has mapping. 818 Now, we need to count how many ways the vertices of a graph that has automorphism 819 can be mapped. 820 Algorithm 14 ROUTINE MAP dir (T v j (G), T v j (G )) 1: if T v j (G) and T v j (G ) are not equivalent then 2: return FALSE 3: end if 4: declare: v j maps to v j 5: mark both v j and v j as mapped 6: partition all incomplete WLTs, whose reference vertices are neighbor vertices of v j and v j and their reference vertices are not in the stack, s.t each part contains equivalent WLTs and two WLTs from two different parts are not equivalent. 7: for each part do 8: if the part contains odd number of WLTs or more than half of WLTs are from one graph then 9: return FALSE 10: end if 11: create ordered pairs of vertices with the reference vertices of the WLTs in the part s.t in each ordered pair (u, u ), u and u are neighbor vertices of v j and v j respectively and each vertex participates in one of such pair only. push all such pairs in the stack. 12: end for 13: while in T v j (G), there is an unmapped vertex u a , for which there is no equivalent unmapped vertex (w.r.t T v j (G)) s.t their WLTs are equivalent do 14: let u a be the equivalent unmapped vertex in T v j (G ) s.t T u a (G) and T u a (G ) are equivalent 15: if no such vertex found then 16: return FALSE 17: end if 18: if MAP dir (T u a (G), T u a (G )) returns FALSE then 19: return FALSE

832
Let G(V, E) and T u (G ) be two isomorphic graphs. We can make the following 833 remarks on the WLTs of G(V, E) and G (V , E ).

834
Remark 3. All WLTs of both graph can be partitioned in such a way that in all equivalent 835 WLTs are in the same part. Any two WLTs from two different parts are not equivalent. Each 836 part contains even number of WLTs and exactly half of WLTs are from one graph. We take two 837 equivalent WLTs: T u (G) and T u (G ) from such a part. Every vertex in T u (G) must be mapped 838 to a vertex in T u (G ) and u can be mapped to u . Suppose, we map u with u . We have the 839 following mappings: (i) for each vertex in T u (G), there must exist an equivalent vertex with 840 respect to T u (G) and T u (G ) such that the WLTs, where they are the reference vertices, must 841 be equivalent, (ii) if any two vertices are mapped they must be equivalent with respect to T u (G)