Share This Article:

An o(n2.5) Algorithm: For Maximum Matchings in General Graphs

Abstract Full-Text HTML XML Download Download as PDF (Size:569KB) PP. 1773-1782
DOI: 10.4236/jamp.2018.69152    198 Downloads   469 Views  
Author(s)    Leave a comment

ABSTRACT

This article extend the John E. Hopcroft and Richart M. Karp Algorithm (HK Algorithm) for maximum matchings in bipartite graphs to the non-bipartite case by providing a new approach to deal with the blossom in alternating paths in the process of searching for augmenting paths, which different from well-known “shrinking” way of Edmonds and makes the algorithm for maximum matchings in general graphs more simple.

1. Introduction

A matching in a graph is a set of edges, no two of which share a vertex. Given a graph, it is a well-known problem to find a matching of maximum carnality. All these algorithms for maximum matching, by berge’s theorem in 1957 [1], are led to search for augmenting paths. In the case of bipartite graphs, it is easier to search for augmenting paths using of bread-first search. These algorithms require o ( m n ) steps. But in the non-bipartite case, the problem becomes even more difficult so that until 1965 only exponential algorithm for finding a maximum matching in general graphs were known. The reason was that one did not know how to deal with odd cycles (Blossoms) in alternating paths in the process of searching for augmenting paths. Edmonds [4] defined the key notion of blossoms and finessed this difficulty in non-bipartite graphs by “shrinking” blossom. The straightforward implementation of his approach led to an o ( n 4 ) algorithm for maximum matching in general graphs. After further improvement there are o ( n 3 ) or o ( n m ) algorithms [2] [3] for it.

In 1973 Hoperoft and Karp [5] proved the following fact. If one computes in one phase a maximal set of shortest augmenting paths, then o ( n ) such phases would be sufficient. For the bipartite case they showed that a phase can be implemented by a breath-first search followed by a depth-first search. This led to an o ( n + m ) implementation of one phase and hence to an o ( n m ) algorithm for maximum matching in bipartite graphs. The HK Algorithm for maximum matching in bipartite graphs [1] is still the most efficient known algorithm for the problem.

The success of Hopcroft and Karp algorithm in bipartite graphs has made many people attempt to extend it to non-bipartite case. In fact ,in their paper almost all the results are derived for general graphs. The specialization to the bipartite case occurs in computing in one phase a maximal set of shortest augmenting paths only.

In 1980 Mieali and Vijay Vazirani [6] stated a matching algorithm in pseudocode, claimed to have an o ( m ) implementation of a phase in general graphs. Although their result led to a most efficient general graph maximum matching algorithm running time of o ( n m ) and is cited in many papers and also in some textbooks but no proof of correctness was available. Also the paper of Peterson and Loui [7] does not clarify the situation.

In this article a new approach to deal with the blossom is proved, which makes a phase can be implemented by a breath-first search followed by a depth-first search.

After summarizing basic theory of matched problem and introducing the HK algorithm in bipartite graph in Section 1, we discuss the obstacle to extend the HK algorithm to the non-bipartite case, that is blossom, in Section 2. The theoretical basis of the new approach is established in Section 3 and then we construct the new algorithm, which extend HK algorithm in bipartite graph to non-bipartite case in Section 4.

2. The Basic Theory and Contribution of Hopcroft and Karp

Let G = { V , E } be a finite undirected graph (without loops or multiple edges) having the vertex set V ( G ) and the edge set E ( G ) . An edge e E ( G ) incident with vertices u and v is written e = u v . A path in G is a sequence of vertices and edges (without repeated vertices)

P = ( u 0 , u 1 , u 2 , ... , u r , u r + 1 )

In which e i = u i u i + 1 E ( G ) (i = 0, 1, ∙∙∙, r). Two vertices u 0 and u r + 1 are called end-poinds of the path. Especially, when u 0 = u r + 1 , i.e. two end-poinds overlap then

c = ( u 0 , u 1 , ... , u r , u 0 )

Is a circuit.

Let u V (G)

N ( u ) = { v : u v E ( G ) }

is called neighborhood of u.

A set M E is a matching if no vertex is incident with more than one edge in M. A matching of maximum cardinality is called a maximum matching. We say the maximum matching is complete, or perfect when | v | = 2 m and | M | = m . We make the following definitions relative to a matching M. Edges in M are called matched edges; the others are free. A vertex v is free if it is incident with no edge in M otherwise it is matched.

A path

P = ( v 0 , v 1 , v 2 , ... , v 2 r , v 2 r + 1 )

is called M-alternating path if its edges are alternately in E-M and in M; i.e.

P M = { v 1 v 2 , v 3 v 4 , v 5 v 6 , ... , v 2 r 1 v 2 r } (1.1)

P ( P M ) = { v 0 v 1 , v 2 v 3 , ... , v 2 r v 2 r + 1 } (1.2)

A path with odd length 2r + 1 (without repeated vertices) is called an M-augmenting path if its end vertices v 0 and v 2 r + 1 are both free.

It is easy to result in the lemma by Equation (1.1) and Equation (1.2):

Lemma 1.1. M ' = P M = ( P M ) ( P M ) is a new matching and | M ' | = | M | + 1 .

And the following theorem is also well known.

Theorem 1.1. (Berge) M is not a maximum matching if and only if there is an augmenting path relative to M.

According to above theorems, the algorithm for finding the maximum matching in a graph boils down repeatedly to search for a augmenting path P relative to current matching M and augment current matching to M P .

The contribution of Hopcroft and Karp is to compute in one phase a maximal set of shortest vertex-disjoint augmenting paths with a same length P 1 , P 2 , ... , P k and augment current matching to M P 1 P 2 ... P k and proved that the number of phases at most 2 [ n ] + 2 .

Algorithm A: Maximum Matching Algorithm (Hopcroft and Karp).

1) M φ

2) Let l ( M ) be the length of a shortest M-augmenting path. Find a maximum set of paths { P 1 , P 2 , ... , P t } with the properties that:

a) For each i, P i is an M-augmenting path and | P i | = l ( M ) ;

b) The P i ( i = 1 , 2 , ... , t ) are vertex-disjoint.

3) M M P 1 P 2 ... P t ; go to step 1.

Theorem 1.2. (Hopcroft and Karp). [5] If the cardinality of a maximum matching is S then Algorithm A constructs a maximum matching within 2 [ s ] + 2 executions of step 1.

This way of describing the construction of a maximum matching suggests that we should concentrate on the efficient implementation of an entire phase (i.e., the execution of Step 1 in Algorithm A).

For the bipartite case,Hopcroft and Karp showed that a phase can be implemented by a breath-first search followed by a depth-first search,which has time complexity o ( m ) . Hence, by theorem 1.2, the algorithm A has time complexity o ( n m ) .

3. Nonbipartite Matching: Blossoms

Unfortunately, in non-bipartite graphs, the lack of bipartite structure makes one might be fail of searching augmenting path by breath-first search in the execution of Step 1 in Algorithm A and this situation makes the task of implementing a phase far more difficult.

The problem remains how to deal with blossoms in computing in one phase a maximal set of shortest augmenting paths in non-bipartite case.

Definition 2.1. A odd circuit with 2 k + 1 vertices having k matched edges is called a blossom.

In Figure 1 (the matched edge are drawn with heavy line, the free vretices are drawn with small cycle). The odd circuits,

c 1 = ( v 4 , v 5 , v 6 , v 4 )

c 2 = ( v 2 , v 3 , v 4 , v 5 , v 6 , v 7 , v 8 , v 2 )

c 3 = ( v 11 , v 1 , v 2 , v 8 , v 7 , v 6 , v 5 , v 4 , v 3 , v 9 , v 10 , v 11 )

are blossoms. The only vertex incident with no matched edges in the blossom is called basis of the blossom, as v 4 , v 2 and v 11 .

The Hopkroft and Karp’s Algorithm [5] of implementation of step 1 of Algorithm A might fail when using it in the non-bipartite graph if which contains a blossom, because one alternating path at the basis of a blossom traverses this blossom and starts “folding” on itself, with a disastrous consequence .

Edmond’s method of dealing with blossoms are also not adequate for the task of finding shortest augmenting paths since by “shrinking” them, length information is completely lost.

We attempt to find a way to through the barrier of blossom keeping length information in finding augmenting paths and then extend the John E. Hopcroft and Richart M. Karp Algorithm (HK Algorithm) for maximum matchings in bipartite graphs to general graphs.

4. Equivalent Digraph

A digraph Γ is defined by a set V ( Γ ) of elements called vertices, a set W ( Γ ) of elements called directed edges or darts, and two relations of incidence. These associate each dart d, the one with a vertex h ( d ) called its head and the other with a vertex t ( d ) called its tail. A dart d W ( Γ ) incident with h ( d ) = v , t ( d ) = u is written d = u v and d = v u is called inverse of d.

Figure 1. M-matched graph.

For a vertex, the number of darts sharing the vertex as head is called the indegree of the vertex and the number of darts sharing it as tail is called its outdegree.

The in degree of v is denoted by deg ( v ) and its out degree is denoted by deg+(v).

A path in digraph Γ is a sequence of r 1 darts,

P = ( d 0 , d 1 , ... , d r 1 ) (3.1)

Or

P = v 0 v 1 ... v r (3.2)

where d j = v j v j + 1 of Γ , not necessarily all distinct. It requires that the t ( d k + 1 ) = h ( d k ) , whenever 0 k r 1 . The first and last vertices of path P, that is t ( d 0 ) and h ( d r 1 ) , are called the tail t ( P ) and head h ( P ) of path P, respectively. The number r is called the length | P | of path P.

p = v r v r 1 v r 2 ... v 2 v 1 v 0 = ( d r 1 , d r 2 , ... , d 2 , d 1 , d 0 )

Is called inverse of path P, where d j = v j + 1 v j .

Consider two paths P and Q in Γ , if h ( P ) = t ( Q ) , there is a path PQ, called the product of P and Q, formed by writing down the terms of P, in their order in P, and continuing with the terms of Q, in their order in Q. It is easy to verify that t ( P Q ) = t ( P ) , h ( P Q ) = h ( Q ) and P Q R = ( P Q ) R = P ( R Q ) , ( P Q R ) = R Q P , | P Q | = | P | + | Q | .

One dart is a path with length 1. One path P = ( d 0 , d 1 , ... , d r 1 ) is the product of r darts d 0 , d 1 , ... , d r 1 , i.e. P = d 0 d 1 ... d r 1 .

We say that P is dart-simple if no dart repeated in it.

For a given graph G, we associate with each edge e = u v of G two distinct elements d = u v and d = v u called the opposite darts on e. We form an equivalent digraph G of G from the given graph G.

V ( G ) = V ( G ) and W ( G ) = { d , d : e E ( G ) , d , d are opposits darts on e }

A path in G is edge-simple if no two of its terms are darts on the same edge of G. Thus an edge-simple is necessarily dart-simple.

Let M be a matching in G. Edges in M and the darts on them are called matched. The other edges and darts on them are free. A path in G is M-alter- nating if its darts are alternately free and matched and the first dart is necessarily free.

Let P = d 0 d 1 ... d i ... d r be M-alternating then d i is free when i is even and d i is matched when i is odd.

Lemma 3.1. Let

P = d 0 d 1 ... d r ( d i = v i v i + 1 ; 0 i r )

be a M-alternating path in equivalent digraph G of G from a free vertex v 0 = t ( d 0 ) to another free vertex v r + 1 = h ( D r ) . If P is edge-simple in G then the alternating path P ' = ( v 0 , v 1 , ... , v r + 1 ) is a M-augmenting path in G.

Proof: Each vertex in P is the head or tail of a matched dart, except v 0 , v r + 1 , but v 0 v r + 1 , so if 0 < i < t < r + 1 ; v i = v t then the matched darts, which incident with v i , v t , are on the same edge of G, because no two of matched edges share an vertex. This would conflict with that P is edge-simple. Then the vertices v 0 , v 1 , ... , v r , v r + 1 in P are all distinct. P ' is a M-augmenting in G. We call a edge-simple path P a M-augmenting path, for simple.

Definition 3.1. Assume i is odd, t. is even and i < t , the M-alternating path P = d 0 d 1 ... d i 1 d i ... d t 1 d t ... d r meet the condition that d t = d i 1 . We call P b ( i , t ) = d i d i + 1 ... d t 1 a blossom and d i 1 in-dart, d t out-dart of the blossom.

It is easy to see:

1) d i 1 , d t are matched therefore d i , d t 1 are free, because i 1 , t are even.

2) P b ( i , t ) = d t 1 d t 2 ... d i is also a blossom in P = d r d r 1 ... d t P b ( t , i ) d i d i 1 ... d 0 and d t , d i 1 are in-dart and out-dart of it respectively.

The M-alternating path P from a free vertex v to a free vertex u is called shortest if P is of least carnality among these M-alternating paths.

Lemma 3.2. Let P = d 0 d 1 ... d r ( d i = v i v i + 1 , i = 0 , 1 , ... , r ) be a shortest M-alternating path in G from a free vertex v 0 = t ( d 0 ) to an another free vertex v r + 1 = h ( d r ) ( v r + 1 v 0 ) , then either P is a M-augmenting path or P pass though a blossom.

Proof: If P be not M-augmenting then there is i < t , v i = v t . Let t be as small as possible, so that v i 1 v t 1 then d i 1 d t 1 , but d i 1 , d t 1 share vertex v i = v t as their head, so d t 1 is necessarily free, because d i 1 d i is alternating. If d i M then d t = d i . We can obtain a shorter alternating path from v 0 to v r + 1 by deleting d i , d i + 1 , ... , d t 1 from P. This is contradict with that P is shortest.

Can only be the case that d t = d i 1 , because they share v t as their tail. The d i d i + 1 ... d t 1 is a blossom and d i 1 is in-dart, d t is out-dart of it. □

5. The Algorithm to Implement Step 1 of Algorithm A in General Graph

We construct a directed graph

G = ( V , D ) (4.1)

from the equivalent digraph G of G, which exhibits conveniently all shortest M-augmenting paths in G .

Let G be the equivalent digraph of G. D is a set of darts. Define:

h ( D ) = { h ( d ) : d D }

t ( D ) = { t ( d ) : d D }

t ( D 0 ) = { v : v V ( G ) & v is M f r e e }

For i = 0 , 1 , 2 , ...

D 2 i = { u v : ( u t ( D 0 )( i = 0 ) ; u h ( D 2 i 1 ) ( i > 0 ) ) & u v E ( G ) M }

D 2 i + 1 = { u v : u h ( D 2 i ) , u v M }

The construction continues until for the first time a set D 2 I * is constructed so that there is a d D 2 I * and h ( d ) is M-free. Then

V = t ( D 0 ) j = 0 2 I * h ( D j ) D = j = 0 2 I * D j

For example, the G shown by Figure 2 (the direction of all darts as shown by the big arrow) is constructed from the equivalent digraph G of the graph G shown by Figure 1. Figure 2 exhibit all of the shortest M-alternating paths from free vertex to free vertex in Figure 1.

The following properties of G is easy to see:

1) Each path from a free vertex u D 0 to a free vertex v D 2 I * in G is a shortest M-alternating path with length 2I*+1.We call it regular M-alternating path in G

2) If a M-alternating path P G , u = t ( P ) D 0 and v = h ( P ) D 2 I * then P G and t ( P ) = h ( P ) = v , h ( P ) = t ( P ) = u . P is also a regular M-alter- nating path in G .

3) Let be the set all regular M-alternating paths in G then t ( ) t ( D 0 ) , h ( ) h ( D 2 I * ) and t ( ) = h ( ) , by (b).

4) If | h ( ) | = 1 then there is no augmenting path in G because there is only one M-alternating path P in G and t ( P ) = h ( P ) . In this case we remove the vertex h ( P ) from h ( D 2 I * ) , and continue to construct.

Let | h ( ) | > 1 Then it’s a matter of finding out the shortest M-augmenting paths in G , i.e. to implement the step 1 in Algorithm A .

Let d D 2 I * and v = h ( d ) h ( D 2 I * ) is M-free. We construct a directed graph

J ( L 0 , v ) (4.2)

which is set of all shortest M-alternating paths with length 2I* + 1 from a set L 0 t ( D 0 ) of M-free vertices to the free vertex v h ( D 2 I * )

D 2 I * f = { d : d D 2 I * & h ( d ) = v }

D j f = { d D j & h ( d ) t ( D j + 1 f ) } ( j = 2 I * 1 , ... , 2 , 1 , 0 )

J ( L 0 , v ) = ( V , D )

where

L 0 = D 0 f { v } , V = L 0 j = 0 2 I * D j f , D = j = 0 2 I * D j f

Case 1: L 0 = φ . In this case there is no augmenting path with V as a end- vertex.

Figure 2. Directed graph including shortest M-alternating paths.

Case 2: L 0 φ . In this case there is at least one M-alternating path from a free vertex u (other than V) to V in J ( L 0 , v ) .

For example, Figure 3 is J ( 11 , 0 ) constructed from Figure 3, in which,. L 0 = { 11 } , D 5 f include two darts ( 5 , 6 ) and ( 6 , 5 ) . D 9 f include only one dart ( 2 , 1 ) called Cut-dart . General, if d i D i f is a only one of D i f we call d i a cut-dart in J ( L 0 , v ) . If d i is a cut-dart then all of the paths in J ( L 0 , v ) pass d i .

Claim 4.1. Each path P J ( L 0 , v ) , either P is a M-augmenting path or P pass through a blossom, by lemma 3.2.

Claim 4.2. If di is a cut-dart and there is a M-augmenting path in J(L0, v) then d i is not a cut-dart.

Claim 4.3 Each path P J ( L 0 , v ) is a M-augmenting path if there is no blossom in J ( L 0 , v ) .

Claim 4.4. Let P be a M-alternating path in J ( L 0 , v ) and u = t ( P ) t ( D 0 ) , v = h ( P ) ( D 2 I * ) then P is in G and v = t ( P ) t ( D 0 ) ; u = h ( P ) ( D 2 I * ) therefore P J ( L 0 u , u ) , where u L 0 u t ( D 0 ) .

Claim 4.5. If P J ( L 0 , v ) pass through a blossom and dart d is the in-dart (out-dart) of the blossom then P J ( L 0 u , u ) is also pass through a blossom and d is the in-dart (out-dart) of it.

A blossom will be broken if to remove the in-dart or out-dart from a path P J ( L 0 , v ) , which traverse the blossom .

Following theorem is the basis of the Algorithm to implement step1 of algorithm A.

Theorem 4.0 Let P be a augmenting path in J ( L 0 , v ) and

u = t ( P ) t ( D 0 ) , v = h ( P ) ( D 2 I * )

d is a in-dart(out-dart) of a blossom in J ( L 0 , v ) and d isn’t a cut-dart then P J ( L 0 , v ) or P J ( L 0 u , u ) can’t be broken after removing d.

Proof: If d is not on P then it can’t be broken after removing d. If pass through d is on P then d is on P J ( L 0 u , u ) and d is not on P . Therefore d isn’t a cut-dart and it is a in-dart(out-dart) of a blossom in P J ( L 0 u , u ) .

Algorithm A1. The algorithm to implement step 1 of Algorithm A

1) to construct G by (4.1). Let D 2 I * ο = { d : d D 2I * & h ( d ) isM-free }

2) If | h ( D 2 I * ο ) | = 0 then end

3) For a v h ( D 2 I * ο ) to construct J ( L 0 , v ) by (4.2)

Figure 3. In-dart (1,2) being not cut-dart.

4) If J ( L 0 , v ) = φ then remove v from h ( D 2 I * ο ) go to 1.

5) Get a M-alternating path P in J ( L 0 , v ) .

6) If P is edge-simple then get a M-augmenting path and remove P and P from G , go to 1.

7) P Traverse a blossom and d is in-dart of it: if d isn’t cut-dart then remove d else remove d from J ( L 0 , v ) , go to 3.

To remove such vertices or darts (as in algorithm A1) may render certain other vertices useless, in the sense that they cannot be in any M-alternating paths. These vertices and darts must also be deleted; for, these dead-ends will make searching for an augmenting path more complicate. Hence we need an algorithm which deletes these dead-ends.

This is achieved as follows:

B: Deletion algorithm

For i = 2 I * to 0 step −1

For each v h ( D i ) if deg ( v ) = 0 then remove v from Di

For j = 0 to 2I*

For each v t ( D j ) if deg + ( v ) = 0 then remove v from Dj in J ( 11 , 0 ) (Figure 3).

For example, to get a M-alternating path P = ( 11 , 1 , 2 , 3 , 4 , 5 , 6 , 4 , 3 , 2 , 1 , 0 ) in J ( 11 , 0 ) (Figure 3). Dart ( 1 , 2 ) on P is a in-dart and isn’t a cut-dart To remove ( 1 , 2 ) from J ( 11 , 0 )

The digraph after removing ( 1 , 2 ) from J ( 11 , 0 ) is shown by Figure 4, to get a M-alternating path P = ( 11 , 10 , 9 , 3 , 4 , 5 , 6 , 4 , 3 , 2 , 1 , 0 ) in it, d = ( 3 , 4 ) is a in-dart and is a cut-dart. We remove out-dart d 1 = ( 4 , 3 ) and get a M-augmenting path P = ( 11 , 10 , 9 , 3 , 4 , 5 , 6 , 8 , 7 , 2 , 1 , 0 ) in the result digraph.

The implementation of a phase consists of the construction of a digraph G , followed by an iteration which alternately finds an augmenting path and executes the deletion algorithm. The iteration stops when D 2 I * ο = ϕ . It is easy to see that each dart of G is examined once when G is first constructed, and once more if the h ( d ) or t ( d ) of that dart d is deleted.

The execution time of a phase is o ( 2 m + n ) , where m is the number of edges in G, and n is the number of vertices. Hence the execution time of the entire algorithm is o ( ( 2 m + n ) s ) , where s is the carnality of a maximum matching.

If G has n vertices then m n 2 4 and s n , so that the execution time is bounded by o ( n 5 / 2 ) .

Figure 4. Out-dart being not cut-dart.

6. Conclusion

In this paper an algorithm running time of o ( m ) to implement step 1 of Algorithm A in general graph has been proved. Different from the way of “shrinking” blossoms, which need to store the shrinked blossoms, the removed darts don’t need to be stored when run this algorithm, because they can never be on any augmenting paths. The space complexity of this algorithm is also o ( m ) . The proved algorithm is very easy to program. The Mieali and Vijay Vazirani [6] algorithm, by contrast, is quite elaborate and its pseudo code is extensive.

Conflicts of Interest

The authors declare no conflicts of interest.

Cite this paper

Xie, Y. (2018) An o(n2.5) Algorithm: For Maximum Matchings in General Graphs. Journal of Applied Mathematics and Physics, 6, 1773-1782. doi: 10.4236/jamp.2018.69152.

References

[1] Berge, C. (1957) Two Theorems in Graph Theory. Proceedings of the National Academy of Sciences of the USA, 43, 449-844. https://doi.org/10.1073/pnas.43.9.842
[2] Balinski, M.L. (1969) Labelling to Obtain a Maximum Matching, in Combinatorial Mathematics and Its Applications. In: Bose, R.C. and Dowling, T.A., Eds., University of North Carolina Press, Chapel Hill, 585-602.
[3] Witzgall, C. and Zahn Jr., C.T. (1965) Modification of Edmond’s Maximum Matching Algorithm. Journal of Research of the National Bureau of Standards, 69B, 91-98.
[4] Edmonds, J. (1965) Paths, Trees, and Flowers. Canadian Journal of Mathematics, 17, 449-467. https://doi.org/10.4153/CJM-1965-045-4
[5] Hopcroft, J. and Karp, R.M. (1973) An n5/2 Algorithm for Maximum Matching in Bipartite Graphs. SIAM Journal on Computing, 225-231. https://doi.org/10.1137/0202019
[6] Micali, S. and Vazirani, V.V. (1980) An Algorithm for Finding Maximum Matching in General Graphs. IEEE Annual Symposium on Foundations of Computer Science.
[7] Peterson, P.A. and Lout, M.C. (1988) The General Matching Algorithm of Micali and Vazirani. Algorithmica, 511-533. https://doi.org/10.1007/BF01762129

  
comments powered by Disqus

Copyright © 2019 by authors and Scientific Research Publishing Inc.

Creative Commons License

This work and the related PDF file are licensed under a Creative Commons Attribution 4.0 International License.