CONSTRUCTING AN ALGORITHM OF QUADRATIC TIME COMPLEXITY FOR FINDING THE MAXIMAL MATCHING

By advancing the idea of finding width in bipartite graphs and basic definitions in matching theory, this paper shows that the task on establishing a maximal matching in an arbitrary graph can be reduced to its bipartite case. It has been proven that each current matching in an arbitrary graph is mutually consistent with the matching in a bipartite graph. It is demonstrated that each of the current solutions to the problem on establishing a maximum matching in an arbitrary graph is not lost when moving to the iterative scheme of establishing the maximum matching in a bipartite graph. To find a prolonged path relative to the fixed matching of power k, it has been proposed a modification to known algorithm for finding paths from this a given vertex to all attainable vertices of the arbitrary graph. Performance of the proposed modification has been illustrated using an example. Based on the ideas outlined, the proven statements, the proposed algorithms and their modifications, an algorithm has been constructed for finding the maximum matching with an improved time estimate compared to the known Edmons algorithm, which possesses a temporal assessment of complexity O(n 4 ). The main drawback of the Edmons algorithm is the use of laborious procedure for compressing the odd-length cycles called "flowers", which renders the algorithm unsuitable for use in real-scale systems. Other known algorithms differ from the Edmons algorithm only by a better data storage and computational organization, while maintaining complex actions in detecting and packaging the odd-length cycles. The proposed approach of moving from an arbitrary graph to a bipartite graph prevented the occurrence of odd-length cycles, which has made it possible to significantly improve the algorithm efficiency. Further performance improvement is possible by building parallel versions of the algorithm and the optimal arrangement of data storage


Introduction
Numerous problems, known as routing tasks, are characterized by an ever-expanding list of practical applications, occupying a traditionally important place in the study of combinatorial optimization problems.The routing task in a broad sense is the problem on current planning, the process of which involves the selection of movable objects and the determination of trajectories and schedules of their movement.
The tasks on routing in road transportation, as well as the methods to solve them, are studied within the framework of a scientific fieldtransport logistics, whose mathematical apparatus is represented by the theory of graphs and the study of operations.Most routing tasks are NP-complete [1] and can be solved only by combinatorial sorting methods [1,2].These methods often require the use of significant computing resources and, as a result, a long time to solve the problem.
The most commonly used methods for solving NP-complete routing problems are the branch and boundary methods [2], which employ relaxation to calculate the lower and upper bounds.Relaxation is generally understood as a combinatorial optimization problem, the set of whose valid solutions are injected with a set of valid solutions to the original problem [3].Typically, the original NP-problem is complete, and its relaxation is solved over a polynomial time [3].
One of the problems that can be used as a relaxation to an NP-complete salesman problem [3,4] is the problem about matching (MP).
A solution to MP could also be used as a lower bound in the branch and boundary methods used to solve closed-route problems.In most implementations of the branch and boundary method, the vertices of the solution tree are matched with a distance matrix that excludes some of the elements, or some rows and columns are removed.Thus, another important area of research is the construction of an algorithm that, based on an existing solution to MP, finds a new solution to MP for the matrix, which differs from the original one by the absence of some elements.

Literature review and problem statement
Paper [1] summarizes the problems on combinatorial optimization related to the construction of vehicle routes.It shows that most routing problems are NP-complete problems of discrete optimization, deriving solutions to which employs sorting methods.This is the method that is considered in work [2], which proposes the use of the branch and boundary method to solve various combinatorial problems on processing big data.Study [3] proposes the use of relaxations as the elements of algorithms and methods for solving the problems on building closed routes, including within the methods of branches and boundaries.Work [4] proposes to use the 2-factor of the minimum weight as a relaxation to the salesman problem within the branch and boundary method.Article [5] reports analysis of the approximate algorithm for solving the metric problem of a salesman with an accuracy estimate of 1.5, using the algorithm for obtaining the perfect matching combination.
The above works [1][2][3][4][5] suggest solving auxiliary subproblems in order to speed up calculations in accurate, and improve accuracy in approximate, methods for solving the problems on building closed routes, at the steps of the relevant algorithms.At the same time, the cited studies do not address issues related to better implementations or lower computational complexity of existing algorithms, which could speed up the construction of closed routes.
A subset of the graph's edges, which do not have common vertices, is termed the M matching [6].An MP implies finding the M max matching of maximal power (maximal matching) in a given graph H=(V, E) with the set of vertices V and the set of edges U).
Paper [7] established that MPs belong to the class of effectively solvable tasks by proposing the algorithm to solving MP with a temporal assessment of complexity O(n 4 ), |V|=n, when using a labor-intensive procedure for compressing certain odd cyclesflowers.Other known M max derivation algorithms, whose authors are listed in [8,9], differ from the algorithm described in [7] only by a better organization of memory and computation, while maintaining the difficult actions to detect and "cut" flowers.Work [10] gives the statement of an assignment problem with additional conflict constraints, which comes down to the task of finding the maximum perfect matching of minimum cost.The problem under consideration is solved by a labor-intensive algorithm, as well as a salesman problem's variant, which is considered in [11], that uses the search for matching in the graph.The complexity of solving the specified problems is related to the presence of flowers in the graph [8].
A flower is a simple cycle of odd length with 2k+1 vertices, containing k matching edges [7].Flowers are not included in a bipartite graph, therefore, for a bipartite graph the task on finding the maximum matching is significantly simplified.In addition, a flower in an arbitrary graph H is determined with respect to a certain fixed M matching as a subgraph with the maximum density of the edges forming a subset M M ′ ⊆ [7].Obviously, the less matching power at which activities start aimed at increasing it, the fewer flowers are found in H.If |M|=1, there are no flowers in H, or all the flowers are the cycles with three vertices and a common edge of M matching (buds).
The methods discussed in the above studies that are related to the construction of prolonged paths include additional steps to pack the flowers.This is because the algorithms listed in papers [3,5,7,8] are performed on arbitrary graphs that allow the existence of odd-length cycles.Therefore, a transition to a bipartite graph would make it possible to avoid the evolution of flowers, and, as a result, could give an opportunity to improve the speed of the algorithm.
Our considerations suggest it must be a relevant idea worth considering to find the maximum matching in arbitrary graph H=(V, U) by using the simpler structure of a bipartite graph D=(X, Y, E).In a bipartite graph, D under X and Y denotes the sets of vertices, |X|=|Y|=|V|=n, Ethe set of edges ( )

The aim and objectives of the study
The aim of this study is to develop an algorithm for solving an MP, which derives a solution to the MP over a time outperforming the existing algorithms for solving an MP.
To accomplish the aim, the following tasks have been set: -to reduce the problem on matching, solved on an arbitrary graph, to a bipartite case and to justify the correctness of such a reduction; -to devise and substantiate the linear procedure of building a prolonged path in a bipartite graph relative to the fixed matching; -to suggest an algorithm for deriving the maximum matching in an arbitrary graph over a quadratic time.

Designate [ ]
n that if a solution to MP was built for D, the solution is built for H, too.
In graph H, the edge {v, u} of the M matching is denoted [v, u].In it, the vertex u is the partner of the vertex v. Edges that are not included in a matching are called free.The vertex, which belongs to the edge of the matching, is defined as saturated.The rest of the graph's vertices are termed unsaturated or free.The power of the maximum matching of graph H with n vertices is limited by the magnitude / 2 .n     A simple path in graph H is called alternating relative to M if the edges of the path through one are present in M [6][7][8].An alternating path, which begins and ends with edges that do not belong to the M matching, is termed increasing relative to the M matching.
We shall define the arbitrary edge {v i , v j } taken in H as the original matching M={[v i , v j ]}.Then, if |V|=|U|=3, then M is the solution to the MP.Assume |V|=4, and the graph H includes a single cycle of odd length.Obviously, in this case, the number of edges |U| is minimal and equals 4. Graph H min of four vertices and four edges, forming the odd cycle Z, is shown in Fig. 1, a).
does not form a bud (Fig. 1, c).In Fig. 1, and all the following figures, the edges of matching are represented by thickened lines.It is clear from Fig. 1 that M max is derived either by adding, to M={[v i , v j ]}, an edge that has no common vertices with edge [v i , v j ] (Fig. 1, a) or by building, from any free vertex (v 1 or v 4 ) (Fig. 1, b), the prolonged path relative to M.
Each vertex v k ÎV of graph H will be represented by a pair of vertices (i k , j k ) of the bipartite graph D=(X, Y, E), where i k ÎX is the beginning of edge (i k , j l )ÎE, and j k ÎY is the end of edge (i m , j k )ÎE.Then, in D, any prolonged path relative to a fixed matching begins in some free vertex i r and ends in some loose vertex , .s j r s ¹ In graph H, it is matched with a path from v r to v s .Obviously, any technique for building a maximal matching in the bipartite graph D, which is simultaneously a solution to the MP for arbitrary graph H, does not imply flower detection activities.Fig. 2, a shows graph D min , built based on graph H min , in which the matching M= ={[v 2 , v 3 ]} forms bud (v 1 , v 3 , v 2 , v 1 ) (Fig. 1b).In D min , the bud is represented by a path from i 1 to j 1 , composed of edges (i 1 , j 3 ), [i 2 , j 3 ], (i 2 , j 1 ).The beginning and end of the path, which increases the power {[i 2 , j 3 ]} by unity, is, respectively, the vertex i 4 and j 1 .This path includes edges (i 4 , j 3 ), [i 2 , j 3 ], (i 2 , j 1 ), which determine the matching {[i 2 , j 1 ], [i 4 , j 3 ]} (Fig. 2, b), which in graph H min is matched with the maximal matching Thus, it has been shown that the problem on finding the maximal matching in arbitrary graph H=(V, U) could be reduced to the problem on finding the maximal matching on the bipartite graph D=(X, Y, E).In the bipartite graph D, X and Y denote the sets of vertices of graph D, |X|=|Y|=|V|=n, E is the set of edges ( ) , , , , , , , ) prolonged relative to M. Assume that D, built from H, includes no any alternating path ( j 1 , j 2 , j 3 , …, j 2k , j 2k+1 , j 2k+2 ).However, building graph D implies the inclusion of edges ( ) , , , , and edges ( ) , , , , , , containing a combined prolonged path ( j 2k+2 , j 2k+1 , j 2k , …, j 3 , j 2 , j 1 ) from the vertex 2 2 k i + to the vertex 1 j relative to matching , , , , , , , The proof of statement 1 indicates that none of the current solutions M in the arbitrary graph H is lost when moving to the iterative scheme for building M max (D) in the bipartite graph D.

Development of a linear procedure for building a prolonged path in a bipartite graph relative to the fixed matching
Let the matching be built in graph D, where l i is the beginning l j is the end of the l-th i j is the subset of mappings of vertices , is the subset of mappings of vertices I k .
To determine whether the matching M k (D) is maximal or is converted into the matching M k+1 (D), one finds the first free vertex ( ) which is considered to be the beginning of a prolonged path .
It is known that the matching M of graph H is maximum then and only when there is no prolonged path in H relative to M [6,7].Let the set ( ) includes not a single vertex i r that connects it to at least one of the vertices from the set { } ( ) We propose a PATH procedure for building The procedure is the modification of a known algorithm for finding paths from a given vertex to all achievable vertices of arbitrary graph H [6].The PATH procedure consists of the following steps: S0.Q is the set of marked vertices, R is the set of unmarked vertices; , , , , ,..., .
Then the induction based on the number of cycle executions that forms steps S1-S3 establishes that On the other hand, let there be a found edge ( ) , .
Then the induction for l yields a simple path ( ) , , , , , , , , , which is built at step S5, from the vertex s j to the vertex 1 ., , Vertex 3 j is incident to vertices 2 i and 3 , i between which we shall choose, for example, 3 .

R i i =
The vertex 4 , Î After adding 4 i to the current set of marked vertices, we derive { } 5 2 3 4 , , , .
, i j is such an edge that { } ( ) The path 5 i p from vertex 5 i to vertex 6 j is built as a result of execution of steps S4-S6.Since 6 j is adjacent to 4 , i we put , , , , , , The vertex 3 i is adjacent to 2 , j therefore, ( ) , , , , , , i then the desired path ( ) , , , , , , , .
i p i j i j i j i j =

Algorithm for finding the maximal matching
Our considerations are detailed in the description of the following algorithm.
S0.The algorithm for finding in the arbitrary graph H=(V, U) the maximal matching M max , [h ij ] n is the symmetrical adjacency matrices of graph H.The solution M max is mutually unambiguously consistent with the maximal matching As a result of the application of heuristics with a temporal difficulty estimate not higher than where l i is the number of the initial vertex, and l j is the number of the final vertex of edge , , is the matching in a bipartite graph D corresponding to M k .

{ }
| 1, , where r x X Î is the beginning, and s j Y Î is the end of path ; { }, Theorem.The maximal matching in an arbitrary n-vertex graph H is correctly derived over time O(n 2 ).
Proof.Because the bipartite graph D does not contain odd-length cycles, the reduction of MP in the arbitrary graph H to a bipartite case excludes flower detection and removal operations.By building, the subgraph r x D contains each edge corresponding in graph H to that that may belong to the prolonged path relative to matching ( ) k M -then, after building at step S5 a path r x p , at steps S6-S7 we determine the matching M k (D).Excluding a vertex r x from the list of free vertices R when there is no , D is based on the consequence from the theorem proven in [7].If at some stage of the algorithm for solving MP there is no prolonged path from vertex v, then v cannot be considered as the starting vertex of the prolonged path at all other stages.
The algorithm terminates at / 2 in the second case, the necessary and sufficient condition is met under which the matching ( ) Let us assess the time complexity of the algorithm presented.
Finding at step S1 in graph H the original matching M k could be performed over time O(n 2 ), for example, by choosing each time in the matrix [h ij ] n the element h ij and by excluding the rows and columns with numbers i and j.The resulting matching leaves in graph H not a single edge incident to two free vertices.The bipartite graph D, which includes the matching M k (D), is formed over n 2 references to the elements of matrix [ ] .

ij n h
Therefore, step S1 is executed over time O(n 2 ).
The starting phase for solving MP is step S2 that builds the subgraph D k , in which the matching M k (D) corresponds to the original matching M in graph H.The first subgraph , , p Building k D requires no more than k(k-1) comparison operations with elements from the matrix [h ij ] n .To assess the laboriousness in solving MP, it would suffice to consider two extreme cases of the algorithm's termination.
In a first case, the algorithm terminates when the matching M k (D) is returned, corresponding to the original matching M k in graph H. Then each subgraph , , does not include the prolonged path Example 2. Fig. 4, a shows the graph H=(V, U), for which, by applying the algorithm from [7] set out in [6], the maximal matching was derived The presented algorithm finds a matching of the same power (Fig. 4, b).
At step S1, a rapid heuristic builds the original matching in matrix 17  , , , , , , J j j j j j j = { } i is isolated.Therefore, the PATH procedure establishes that there is no path from 13 x to the vertex of the set { } 13 , S y -  , , , , , , , , , , , , ., , , , , , , , , , , , J j j j j j j j = coinciding with an accuracy to designations with the matching max 8 , M M = shown in Fig. 4, b).

Discussion of results of constructing an algorithm with a quadratic time complexity to find the maximal matching
Known methods from [5][6][7][8] make it possible to derive a solution to the similar problem over time О(n 4 ).The algorithm for solving the matching problem outlined in work [8] could be implemented as a computer software with a temporal complexity of О(n 3 ) provided data structures are optimally utilized.
Existing algorithms from studies [5][6][7][8] are based on the execution of the algorithm for bypassing the graph in width, at the steps of which the detection and packaging of flowers are made (cycles of odd length).
The results reported in our article provide a solution to the matching problem over time О(n 2 ).Winning in speed is achieved by moving from an arbitrary to a bipartite graph, on which there is no need to find and pack flowers.Thus, the algorithm that we proposed would provide for the acceleration in solving the problem by at least n times.
However, in practice, there is often a need to solve the problem on a weighted graph.In this case, one should talk about the problem of weighted matching.The approach proposed in this article cannot be applied directly to solve the problem of weighted matching.Therefore, we plan to advance the ideas proposed in the current paper to build an algorithm to solve the specified problem.Solving a problem of weighted matching could be used as a lower estimate of the cost in accurate and approximate methods for finding Hamilton cycles on graphs and routing problems, which are reduced to the problem of a salesman, which would make it possible to bring down computational costs and speed up the time it takes to find solutions to these problems.

Conclusions
1. Reducing the problem on building the maximal matching, solved in an arbitrary graph, to the corresponding bipartite variant makes it possible to avoid the need to process flowers [7] and reduce the computational com-Fig.6. Subgraph D 14 for vertex x 14 =i 5 plexity of the algorithm to solve an MP.By reducing the complexity of the algorithm, the speed of solving an MP is increased compared to known methods.The proof of mutually unambiguous correspondence between a matching in the arbitrary graph and the matching in a bipartite graph allows us to assert the correctness of the proposed reduction.
2. The proposed PATH procedure with a linear time assessment of complexity makes it possible to build a prolonged path in a bipartite graph relative to the current matching.The procedure greatly simplifies and, as a result, accelerates the derivation of a new matching, which has one edge more than the original.
3. Based on the iterative execution of the PATH procedure, we have proposed and substantiated an algorithm for building the maximal matching, which has a quadratic temporal complexity.Solving an MP by proposed algorithm as a relaxation within the branch and boundary method makes it possible to save computing resources of computers and servers used for computations and, as a result, to gain a win in the speed of building accurate solutions to certain NP-complete routing problems.
matrices of, respectively, graphs H and D:

Fig. 1 .
Fig. 1.Graph H min of four vertices and four edges forming the odd cycle of Z: a -M max is derived by adding, to M={[v i , v j ]}, an edge that has no common vertices with edge [v i , v j ]; b -[v i , v j ]ÎZ, i, jÎ{1, 2, 3, 4}, then Z is the bud in graph H min ; c -M={[v i , v j ]} does not form a bud

Fig. 2 .
Fig. 2. Graph D min , built on graph:a -matching M={[v 2 , v 3 ]} forms a bud (v 1 , v 3 , v 2 , v 1 ); b -the beginning and end of the path that increases the power {[i 2 , j 3 ]} by unity, are respectively, vertices i 4 and j 1 .This path includes edges (i 4 , j 3 ), [i 2 , j 3 ], (i 2 , j 1 ), which determine the matching {[i 2 , j 1 ], [i 4 , j 3 ]} are the subsets of the saturated vertices of sets X and Y, respectively.In M(D), denote via l j Y Î the mapping of beginning l i of edge[ , ], is the mapping of end j l of this edge,

Fig. 3 .
Fig. 3. Subgraph of graph D, in which matching M k (D) is fixed, all the vertices from set k k I J ∪ are removed, and each edge connecting the vertex 1 k j + to the vertex from I k is removed

+
The time of procedure execution is estimated based on that in the worst case the maximum number of verone needs O(k) elementary activities.The same amount of action will be needed to build it.Therefore, the time complexity of the PATH procedure is estimated by magnitude O(k).The proof is complete.Example 1.Let us illustrate work of the PATH procedure for

D
is the matching corresponding to M max in H. S2.Form a subgraph D k of graph D that includes M k (D) and all free edges with initial vertices in k I and final vertiof graph D by adding to 1 k D -all the free edges linking the vertex r x R Î to vertices in k J and all the free edges with the initial vertex in k I and a final vertex in Perform the PATH procedure to find in the subgraph the matching that corresponds to M max in graph H. S8.

∑
takes a time of k(n-2k) 2 +c(k+2) (n-2k)+k(k-1), c<k, to check the optimality of the initial solution M k (D).Since the labor-intensity of building M k (D) is limited by magnitude O(n 2 ), then the time complexity of the algorithm in the considered case is estimated by the same magnitude.In a second case, the algorithm converts the original matching M k (D) into a matching of power / of building M k+1 (D) is estimated by magnitude 1 , k t + which includes k(k-1) and k+k(n-2k-1) elementary actions to form graphs k D and ,The total cost of converting the matching M k (D) into a matching of Since the time to build the original matching M k (D) is limited by the magnitude O(n 2 ) and T=O(n 2 ), then in this case, too, the algorithm solves the MP at labor-intensity O(n 2 ).The proof of the theorem is complete.

Fig. 4 .
Fig. 4. Graph H=(V, U): a -maximal matching derived by the Edmons algorithm; b -maximal matching derived by the proposed algorithm

6 M
i i =r=14, in the subgraph x D .Now a subgraph 14 D is built for the vertex 14 5 .xi = 14 D is shown in Fig.6.The PATH procedure builds the prolonged path D and, therefore, determines