Searching isomorphic graphs

To determine that two given undirected graphs are isomorphic, we construct for them auxiliary graphs, using the breadth-first search. This makes capability to position vertices in each digraph with respect to each other. If the given graphs are isomorphic, in each of them we can find such positionally equivalent auxiliary digraphs that have the same mutual positioning of vertices. Obviously, if the given graphs are isomorphic, then such equivalent digraphs exist. Proceeding from the arrangement of vertices in one of the digraphs, we try to determine the corresponding vertices in another digraph. As a result we develop the algorithm for constructing a bijective mapping between vertices of the given graphs if they are isomorphic. The running time of the algorithm equal to $O(n^5)$, where $n$ is the number of graph vertices.


Introduction
Let L n is the set of all n-vertex undirected graphs without loops and multiple edges.
Let, further, there is a graph G = (V G , E G ) ∈ L n , where V G = {v 1 , v 2 , . . . , v n } is the set of vertices and E G = {e 1 , e 2 , . . . , e m } is the set of edges of the graph G. Local degree deg(v) of the vertex v ∈ V G is the number of edges, that is incident to the vertex v. Every graph G ∈ L n can be characterized by the vector D G = (deg(v i 1 ), deg(v i 2 ), . . . , deg(v in )) of the local vertex degrees, where deg(v i ) ≤ deg(v j ) if i < j.
Graphs G = (V G , E G ), H = (V H , E H ) ∈ L n are called isomorphic if between their vertices there exists one-to-one (bijective) mapping ϕ : V G ↔ V H such that if e G = {v, u} ∈ E G then the corresponding edge is e H = {ϕ(v)ϕ(u)} ∈ E H , and conversely [2]. We say that the mapping ϕ converts the graph G into the graph H and conversely.
The problem of determining the isomorphism of two given undirected graphs is used to solve chemical problems, and to optimize programs [3] - [6] and others. Effective (polynomial-time) algorithms for solving this problem were found for some narrow classes of graphs [7,8]. However for the general case, effective methods for determining the isomorphism of graphs are not known [10].
The purpose of this article is to propose the polynomial-time algorithm for searching isomorphic graphs.

Basic definitions
Let there be a graph G ∈ L n .
Choose some vertex v ∈ V G . The set of all vertices of the graph G, adjacent to vertex v, we call the neighborhood of this vertex of the 1st level.
Suppose that we have constructed the neighborhood of the vertex v of (k − 1)-th level. Then the set of all vertices adjacent to at least one vertex (k − 1)-th level, we call the neighborhood of the vertex k-th level (0 ≤ k ≤ n − 1). Such neighborhood we denote N (k) G (v). For convenience, we assume that the vertex v forms the neighborhood of the zero level.
Found neighborhoods allow us to construct for the vertex v of the auxiliary directed graph G(v) in the following way.
Each neighborhood N (k) G (v) of the graph G forms k-th line of the digraph. If the edge of the graph G connects the vertex v 1 of k 1 -th level with the vertex v 2 of k 2 level, and k 1 < k 2 , then this edge is replaced by the arc (v 1 , v 2 ). If k 1 = k 2 , then this edge is replaced by two arcs (v 1 , v 2 ) and (v 2 , v 1 ). We say that the constructed digraph is induced by the vertex v of the graph G. Each vertex of an auxiliary graph will be characterized by two vectors. The input characteristic of the vertex v of the digraph G(v) is called the vector I v = (i 1 , . . . , i q ), where the elements i 1 , . . . , i q are the line numbers of the digraph, written in order of increase. These numbers indicate the lines, from which arcs come into the vertex v. If into the vertex v several arcs come from the same line, the line number is recorded in the vector I v the corresponding number of times.
The output characteristic of a vertex v of the digraph G(v) is called the vector O v = (i 1 , . . . , i q ), where the elements i 1 , . . . , i q are the line numbers of the digraph, also written in order of increase. These numbers indicate those lines, in which arcs come from vertex v. If from the vertex v several arcs come into vertices of the same line, then the line number are recorded in the vector I v the corresponding number of times.
Characteristic of vertex v of the digraph G(v) will be called the input and output characteristics of this vertex. The characteristics of the two vertices v 1 , v 2 are equal if them the input and output characteristics are equal, respectively.
Find the vertex characteristics of the digraph G(v 1 ), is shown in Fig.  2 I v 2 = (0, 1, 1); I v 3 = (0, 1); Let there are auxiliary directed graphs G(v 1 ) and G(v 2 ), induced by the vertices v 1 and v 2 , possibly belonging to different graphs. The directed graphs G(v 1 ) and G(v 2 ) are called positionally equivalent if the lines of digraphs of the same level contain the same number of vertices having respectively equal (input and output) characteristics.
A vertex x ∈ V G will be called unique if the digraph G(v) does not exist another vertex with characteristics equal to the characteristics of the vertex x.
Note that the vertex v ∈ V G , that induces the auxiliary digraph G(v), is always unique in this digraph.

The basics of the algorithm
Next, we will consider pairs of graphs G, H ∈ L n , having equal number of vertices n, equal number of edges m and equal vectors of the local degrees D G = D H . It needs to determine the isomorphism of the given graphs and, if they are isomorphic, then find the bijective mapping ϕ between their vertices.
The idea of finding bijective mapping ϕ between the vertices of the vertex set of graphs G, H ∈ L n is the following. We assume that the graphs G and H are isomorphic. Naturally that the required mapping can only be found when graphs G and H is indeed isomorphic. If in the process of finding the mapping ϕ cannot be found, then the given graphs are not isomorphic.
Theorem 3.1 Let the graphs G and H are isomorphic. Then there exist at least two vertices v ∈ V G and u ∈ V H such that induce two auxiliary positionally equivalent digraphs G(v) and H(u).
Proof. The construction of the auxiliary directed graphs depends only on the location of graph vertices relative to the neighborhood of the induced vertex v or u and does not depend on the vertex names of the graphs G and H. Therefore, because graphs G and H are isomorphic and we have the identical procedure of constructing the auxiliary digraphs, we will be found the auxiliary positionally equivalent digraphs G(v) and H(u).♦ Theorem 3.2 If graphs G and H are isomorphic and two auxiliary positionally equivalent digraphs G(v) and H(u) are found, then any bijective mapping ϕ, which convert the graph G into the graph H (and conversely), is determined by pairs of vertices of the digraphs with equal characteristics.
Proof. The assertion of the Theorem 3.2 is true as if to assume contrary, we will get that the mapping ϕ converts one vertex to another with different characteristics. This is contrary to the concept of isomorphism of graphs.♦ Corollary 3.1 Let the graphs G and H are isomorphic and two auxiliary positionally equivalent digraphs G(v) and H(u) are constructed. Let, further, it was found t unique vertices in these digraphs, the corresponding pairs of which have equal characteristics. Then, the pairs of these vertices belong to the mapping ϕ.
It is easy to understand that the search of vertex pairs that belong to the binary mapping ϕ, the equality of the vertex characteristics in the auxiliary digraphs are not sufficient if these vertices have incoming and/or outgoing arcs, connecting vertices of the same line of the auxiliary digraph.
In the isomorphic graphs G and H, we can find vertices v ∈ V G and u ∈ V H such that induce auxiliary positionally equivalent digraphs G(v) and H(u) respectively. In accordance with the Theorem 3.1, these vertices always exist.
The desired bijective mapping ϕ can be represented as the perfect matching in the bipartite graph, induced by the vertices of the auxiliary positionally equivalent digraphs G(v) and H(u). This bipartite graph we will call the virtual. In this bipartite graph, any vertex x ∈ V G is connected by the virtual edge with all vertices of the digraph H(u), which have same characteristics as x. It is clear that the bijective mapping will correspond to virtual perfect matching in the bipartite graph. Unfortunately, it is not every perfect matching corresponds to the bijective mapping ϕ.  We find the vertex characteristics of the auxiliary digraph H(u 1 ). The results shown in the table 3.2. Table 3.2: The vertex characteristics of the digraph H(u 1 ) It is easy to see that the auxiliary digraphs G(v 1 ) (see Fig. 2.1) and H(u 1 ) are positionally equivalent. In these digraphs, there are only two unique vertices v 1 and u 1 . Other vertices with equal characteristics form the virtual bipartite graphs, induced by the following vertex pairs:  In this case, we have one unique vertex in each of the digraphs G(v) and H(u). Therefore, the pair of vertices {v, u} belongs to the desired mapping ϕ. Remove these vertices from the corresponding graphs. We will get graphs G 1 and H 1 .  Thus, we again have the problem of finding the bijective mapping ϕ 1 ⊂ ϕ, which converts the graph G 1 to the graph H 1 and conversely.
In the graph G 1 we choose the vertex v 2 , and construct the corresponding auxiliary digraph (see Fig. 3.5). We find the vertex characteristics of the digraph G 1 (v 2 ). The result of the calculation is placed in the table 3.3.
In the graph of H 1 we choose the vertex u 4 , and construct the corresponding auxiliary graph (see Fig. 3.5). Find the vertex characteristics of the digraph H 1 (u 4 ). The result of the calculation is placed in the table 3.4.
Comparing the vertex characteristics of auxiliary digraphs, we see that the digraphs G 1 (v 2 ) and H 1 (u 4 ) is the positional equivalent. Moreover, in each of the constructed digraph, each vertex is unique.
At once, we can construct the mapping ϕ 1 , choosing vertex pairs of the digraphs G 1 (v 2 ) and H 1 (u 4 ) with equal characteristics. Adding to ϕ 1 of the previously found pair (v 1 , u 1 ), we get the required mapping To perform the verification of the obtained result, consider the matching edges of graphs G and H defined found the bijective mapping.

Vertex characteristics of the digraphs
The example above illustrates our approach to solving problem of finding the bijective mapping ϕ between the vertices in isomorphic graphs G and H.
The essence of this approach consists in the following steps.
• In the graph G, choose the vertex v.
• In the graph H, choose the vertex u such that the auxiliary digraph H(u), which is positionally equivalent to the digraph G(v). If such vertex is not found, then terminate computation as graphs G and H are not isomorphic.
• In the positionally equivalent digraphs G(v) and H(u), find all unique vertices. Form vertex pairs (v, u), having equal characteristics, and record them. Delete all unique vertices from the graphs G and H.
• If the graphs are obtained after the removal of unique vertices is not empty, then repeat the above procedure again. Otherwise, recorded vertex pairs form the desired bijective mapping ϕ.
The conception of positional equivalence of auxiliary digraphs requires clarification in the conditions when the algorithm at each iteration is dealing with the changed set of vertices of the graph. This concept is due to the vertex characteristics of the considered digraphs. In the process of work of the search algorithm of the bijective mapping, we have to take into account the history of the choice of vertices for mapping ϕ in the previous iteration of the algorithm.
Let us explain the above by the example. Suppose there are two graphs G and H (see Fig. 4.6), bijective mapping the vertices of which we want to find. In the graph G, we choose the vertex v 1 and construct the corresponding auxiliary graph G(v 1 ). On form, it coincides with the figure of the graph G. Therefore, we immediately find the vertex characteristics of the digraph G(v 1 ).
The results are presented in the table 4.5.
Further, when we construct the auxiliary directed graph for the vertices of the graph H, we find the digraph H(u 4 ), induced by the vertex u 4 . It is Table 4.5: The vertex characteristics of the digraph G(v 1 ) easy to see that it will coincide with the figure of the digraph G(v 1 ). Find the vertex characteristics of this digraph.
The results are presented in the table 4.6. It is easy to see that the auxiliary digraphs G(v 1 ) and H(u 4 ) positionally equivalent. They have by the single unique vertex of v 1 and u 4 , respectively.
Remove the vertices v 1 and u 4 of graphs G and H. We obtain disconnected graphs G 1 and H 1 is shown in Fig. 4.7. Figure 4.7: Graphs G 1 and H 1 .
In the subgraph of G 1 , we choose the vertex v 2 and construct the auxiliary digraph G 1 (v 2 ). His form is the same as the first connected component of the graph. We find vertex characteristics of the digraph G 1 (v 2 ).
The results are presented in the table 4.7.
In the graph H 1 , we choose the vertex u 1 and construct the auxiliary digraph H 1 (u 1 ). It is easy to see that its form will be coincide with the digraph G 1 (v 2 ). We find vertex characteristics of the new digraph.
The results are presented in the table 4.8.
The resulting digraphs are positionally equivalent. Here vertices v 2 and u 1 are the unique, having equal characteristics. However, these pair of vertices (v 2 , u 1 ) will not belong to the bijective mapping ϕ of graphs G and H.
It happened because when considering graphs G 1 and H 1 we did not take into account the previous stage of calculations, when it was found the couple of unique vertices v 1 , u 4 , remote subsequently of the graphs G and H.
Each vertex of the auxiliary graph let's characterise by the old and new input and output characteristics in the following way.
Let in the given graphs G and H, positionally equivalent digraphs G(v) and H(u) were found. The calculated characteristics of the vertices of the digraphs, we fix for graph vertices G and H. Subsequently, after removing the unique vertices of the graphs, the vertex characteristics for new digraphs are finding and they join previously found and fixed characteristics.
For definiteness, we assume that the new vertex characteristics of the digraphs are always located on the first "floor" of the building from the vectors of input and output characteristics. The previously found characteristics moved on one "floor" up.
We assume vertex characteristics of the digraphs equal if their vector characteristics are equal on the respective "floors". Similarly, two of the digraph call positionally equivalent if the line digraphs of the same level contain the same number of vertices having respectively equal to (input and output) characteristics.
We will write characteristics of vertices of the digraphs G 1 (v 2 ) and H 1 (u 1 ), obtained earlier.
We have the following characteristics for the digraphs G 1 (v 2 ).
In the graph of H 1 , we choose the vertex u 3 , and construct the auxiliary digraph H 1 (u 3 ) and find the vertex characteristics of the digraph.
The results are presented in the table 4.11. Table 4.11: The vertex characteristics of the digraph H 1 (u 3 ) I u 1 = (1, 2); I u 2 = (1, 2); I u 3 = (0); In this case, we see that the digraphs G 1 (v 2 ) and H 1 (u 3 ) are positionally equivalent. The characteristics of pairs of vertices (v 2 , u 3 ), (v 4 , u 1 ) and (v 5 , u 2 ) are equal, and the pair of vertices (v 2 , u 3 ) belongs to the bijective mapping ϕ between the vertices in the given graph G and H. Proof. For comparison of the vertex characteristics of the auxiliary digraphs, consisting of the single "floor", it required, obviously, O(n 2 ) time units. Therefore, for comparison of the vertex characteristics of the auxiliary digraphs, using the history of the graph changes, which consists of O(n) "floors", it required O(n 3 ) time.♦

The search algorithm
We describe now the algorithm in more detail.
The input of the algorithm: graphs G = (V G , E G ), H = (V H , E H ) ∈ L n , isomorphism of which it is necessary to determine if it exists. We assume that these graphs have the same number of vertices and edges, as well as their vectors of local degrees D G and D H are equal.
The output of the algorithm: the determining the one-to-one correspondence P between the vertex sets of V G and V H , if it exists.
The algorithm for determining the bijective mapping between the vertices in the isomorphic graphs.
Step 2. Choose the vertex v i ∈ V Q in the graph Q.
Step 3. Construct the auxiliary digraph Q(v i ), using the graph Q.
Step 4. Find vertex characteristics of the auxiliary digraph Q(v i ).
Step 5. Choose the vertex u j ∈ V S in the graph S.
Step 6. Construct the auxiliary digraph S(u j ), using the graph S.
Step 7. Find vertex characteristics of the auxiliary digraph S(u j ).
Step 8. Compare the vertex characteristics of the digraphs Q(v i ) and S(u j ) in the neighborhood of the vertices v i and u j of the same level.
Step 9 If the graphs Q(v i ) and S(u j ) are not positionally equivalent then if j < N then j := j + 1 and go to Step 5 else stop the computations, as the graphs G and H are not isomorphic.
Step 10. If the digraphs Q(v i ) and S(u j ) are positionally equivalent then find the vertex sets {v i 1 , . . . , v it }, {u j 1 , . . . , u jt }, unique in each of the digraphs.
Step 11. Put P : Step 12. If N = 0, put i := i, j := 1 and go to Step 2. Otherwise, stop the computations, because the bijective mapping between the vertices in isomorphic graphs G and H has constructed, the pairs of the respective vertices are stored in the set P .
Theorem 5.1 The algorithm for determining the bijective mapping the vertices in isomorphic graphs finds the mapping if it exists.
Proof. By Theorem 3.2 if graphs G and H are isomorphic then any bijective mapping ϕ, which convert the graph G into the graph H (and conversely), is determined by vertex pairs of the auxiliary positionally equivalent digraphs G(v) and H(u), having equal characteristics. If it is found t such vertices, then they explicitly define the elements of the bijective mapping ϕ. Note that among the vertices of the auxiliary positionally equivalent digraphs at least one vertex is unique in each of the digraphs. These are vertices, which induce the digraphs G(v) and H(u).
Deletion of the unique vertices from the graphs G and H reduces to obtaining the graphs which are also isomorphic. Therefore, the repetition of the above procedure to the obtained graphs will lead to the exhaustion of the vertex list of isomorphic graphs G and H.♦ Proof. We define the running time of the algorithm when performing steps 5-9.
Steps 5, 9 require to expend one unit of time for each step.

Conclusion
The results, presented in this article, show the fruitfulness of the method of positioning vertices of the given graphs.
One can allocate two features of our method.
1. Each of the given graphs G, H ∈ L n is represented in the single form -in the form of the auxiliary digraph.
2. The vertices of every digraph are positioned relative to each other without become attached to the vertex names of graphs.
It is possible that this approach will be used to solve other problems.  It is easy to see that the constructed auxiliary digraphs G(v 1 ) and H(u 1 ) are positionally equivalent. The digraph G(v 1 ) has two unique vertices v 1 and v 4 . They correspond to the unique vertices u 1 , u 5 in the digraph H(u 1 ). Therefore, vertex pairs (v 1 , u 1 ), (v 4 , u 5 ) can be saved in the set P .
Delete from the graphs G and H the unique vertices. We get graphs G 1 and H 1 (see Fig. 7.3). Figure 7.3: Graphs G 1 and H 1 .
Choose the vertex v 2 in the graph G 1 and construct the auxiliary digraph G 1 (v 2 ) (see Fig. 7.4). Choose the vertex u 2 in the graph H 1 and construct the auxiliary digraph H 1 (u 2 ) (see Fig. 7.4).
The calculated characteristics of vertices of the newly constructed digraph are located to the table 7.4.
Removing the unique vertices of the graphs G 1 and H 1 , we obtain respectively the graphs G 2 and H 2 consisting of two isolated vertices each. It is clear that it will be obtained auxiliary positionally equivalent digraphs G 2 (v 3 ) and H 2 (u 3 ). Inducing vertices form the pair (v 3 , u 3 ) of unique vertices that can be saved in the set P .
We also find that the pair of vertices (v 6 , u 4 ) belongs to the set P . Thus, the binary relation between vertices of isomorphic graphs G and H is: