Testing for equality between maximum matching and minimum node covering

Testing for equality between maximum matching and minimum node covering

Volume 6, number 6 lNFORMATlON PKWESSING LFTTERS December 1977 TESTING FOR EQUALITY BETWEENMAXIMUMMATCHiNGAND MINIMUMNODE COVERING l , F&M GAVR...

451KB Sizes 0 Downloads 54 Views

Volume 6, number 6

lNFORMATlON

PKWESSING

LFTTERS

December 1977

TESTING FOR EQUALITY BETWEENMAXIMUMMATCHiNGAND MINIMUMNODE COVERING l

,

F&M GAVRIL Computer Science Department, Tzl-A uiv University. Tel-Aviv, Israel Received 28 January 1977. revised version received 22 August 1977

Maximum

matching, minimum

node covering, algorithm

i . Introduction

We consider finite undirected graphs G(I/, E) with no parallel edges and no self-loops, where V is the set of the graph vertices and E is the set of its edges. Two vertices U, u of C connected by an edge are called adjacent vertices and we denote the edge by (u, v); the edge is said to be incident to its two vertices. The set of vertices adjacent to a vertex v will be denoted by f’u and for a subset Y C V we will denote r(Y) =U,E~I?~.For a subset V, of V, the subgruph G(V,) of G(&‘,E) is the graph whose set of vertices is V, , two vertices being adjacent if and only if they are adjacent in G(V, E). For a subset E, C E we will denote by V(EI) the set of vertices incident to the edges of E, and we will denote by G(E ,) the subgraph G(v(E,)) of G(v, E). We will denote the size (number of elements) of a set X by 1x1. For two sets X, Y we wiu denote by X - Y the set of elements of X which are not in Y. A set of vertices of G called independent if no two of its elements are adjacent. A set of vertices is called a node covering if every edge of G is incident to a vertex of the set. The size of a minimum nude covering will be denoted by a,(G). A set of edges is called a matching if no two of its elements have a

‘Y

* Tha work was supported in part by the National Research Council of Canada while the author was visiting the DEpartement d’informati<;ue,

UnivcrsitC de Montkal.

vertex in common. The size of a maximum matching will be denoted by 0, (G). For a given matching, a vertex which is not incident to any edge of the matching is called frtc relative to the matching. Clearly a set C is a node covering of G if and only if V-C is 3-n independent set (see 141). Polynomial time algorithms for finding a maximum matching are well known. The earliest ape is due to Edmonds [2], The best one presently known is the algorithm of Even and Kariv [3] which works m O( I V12.5) steps. Let us call a graph G semiparticle if q,(G) = 0 I (G). As proved by Konig (5 1, the bipartite graphs.are semipartite. But there are semipartite graphs which are not bipartite. For example hte graph of Fig. I(a) has the maximum matching { (uI, uz): (~3, VQ), (us, v6)} and the minimum node covering iv,, ul, us I. Hence it is semipartite. 51-t it is not bipartite since it has triangles. The semipartite graphs were characterized by Harary and Plummer (see [4]) as the graphs having nonempty line-con and point-core. They als:, provided a structural chan.cterization. Some very special cases of semipartite gra,,hs appear also in a book of Berge [ 1, p. 1841. But to t:?e best of my knowledge no polynomial time algorithm to recognize them is known. The purpose of the present paper is to describe a polynomial time algorithm for testing if a given graph G has a,,(G) = 0, (G), i.e. for recognizing whether or not, it is semipartite. If the graph is semipartite, the algorithm will also find a minimum node covering and a maximum independent set. 199

December 1977

INFORMATIOMPROCESSINGLETTERS

Volume 6, number 6

C

v-c (b)

ta) Fig. 1.

2. Properties and allgorithms

The iollowing lemmas give some properties of the semipartite graphs. Lemma 1. A graph G( V, E) is semipartiteif and onIy if for every minimum node covering C and every maxirnur~ ,natching M, C is a subset of V(M) and every edge of M is irrciderrtto exactly ,3ze vertex of C. Roof. Let C be a minimum node covering and M a

maximum matchiq of a graph C. Then, every edge of M must be incident to at leas! one vertex of C. Hence ICI = IMIif and onl,y if every edge of Icf is incident to exactly one vertex of C and Cc V(M). Lemma 2. Consider a semipartitegraph G(V, E). Let M be a maximum matching and let C be a minimum node covering of G. Then: (i) every free vertex is in V-C; (ii) every vertex u adjacent to a vertex I)E V-C, is in C; (iii) every vertex g adjacent to a vertex v E C by an ,edge (u. v) E M is in V-C; (iv) for every subset MI of M the subgraph G L = G(rM, ) is semiparti’le. Proof. Conditions (iI1and (iii) are implied by Lemma 1, and (ii) is implied by the fact that C must cover the edge (II, v). Let jVI be a subset ofM and let G, = G(M,). Then, c:=cnvtj4f) I is a minimum node covering of GI and every edge ofMI is incident to exactly one vertex of Cl . Since G I has no free vertices relative to MI it follows that lM1I = IC, I. Hence (iv) is true.

Suppose we want to check whether a graph G( V, E)

is semipartite or not. Without loss of generality we can assume that G is connected. First we construct a maximum matching M of G. According to Lemma 1, our pro;9em is to partition V into two subsets C and V-C such that V-C is Independent, every element of C is incident to an edge of M and no edge of M is incident to two vertices of C. We construct this partition by making the vertices of V by “+” and ‘I-” according to whether they must be in C or in V-C. Roughly speaking the algorithm works as follows: We mark the free vertices by “-*’ and we set t

= true. Then, we apply alternatively the following two rules until no new vertices are marked: i

Rule 1. Mark by “t” all the unmarked vertices adjacent to the vertices marked “-“; if two vertices u, v newly marked “+” have (u, IJ)EM, set t = false. Rule 2. Mark by “-” every unmarked vertex u such that for some vertex v marked 9” we have (u, v) EM,

if two vertices newly marked “-” are adjacent, set t = false.

If t = false then we stop; in this case G is not semi-

partite. If t = true and there are yet unmarked vertices, then we pick an edge (u, u) such that u and v are unmarked. Relative to (u, v) there are two possibilities: {Pl)uECandvE V-C, (P2)uE V-CandvEC. We check the two possibilities as follows, For checkitg (Pl) we mark u by “t” and v by “-” and apply ahe,nately Rules 1 and 2 until no new vertices are marked. If t remains “true”, we continue in the same way on the remaining unmarked vertices. If t = false then we

Volume 6, number 6

llNFQRMATiON PROCESSING LETTERS

must chl*:k (P2). For this, we mark v by “+“, u by 6‘- 99and apply the two rules until no new vertices are marked. If also in this case we obtain P = false then G is not semipartite. Otherwise we continue in the same way on the remaining unmarked vertices. In our algo-’ rithm we will check the above two posJ;oilities simultaneously. We do this by alternatel:r performing a constant number of steps for every one of them. The validity of the algorithm will be proved in Theorem 3. The algorithm appears below in Algol-like notation. We assume that the graph is given by the adjacency lists of its vertices. That is for every vertex v of G, we are given the list L(v) of its adjacent vertices. We use two pointers T, , Tz which move on these adjacency lists. When 7’imoves after the last element of an adjacency list its value is set to be “A”. The algorithm uses two queues Q 1, Q2 in which we insert the vertices newly marked “-” and from which we apply Rule 1. Since in procedure PART we check simultaneously the two possibilities (Pl) and (P2), we use “-I”, “+l” for the first possibility and “-2”, “+2” for the second, instead of “t” and “-“. Algorithm COV: procedure PART (X,, X2): begin t1 := true; t2 := true;sl := false, s2 := false; ifX2 = 0 then t2 := false; mark every element of Xt by “- 1” and “+2”; mark every element of X2 by “+l” and “-2”; 2:=x, ux2; ifX2 = 0 thenj := 1 elsej := 2; for i := I until] do begin put the elements of Xi into Qi; let ui be the first element of Qi; remove us from Qt; Ti to point to the fist element cf Uu;); end; while not (SI or s2 or t 1 = t2 = false) do besb for i := 1 until 2 do begin wh@ tt do begin ifTi=hthenbegin let ul be the first element of Qi; remove ul from Qi; set Ti to point to the first element of L.(q); end; let ui denote the vertex pointed by Ti in L(q); if rq is marked “4” then ti := false else if ui is not marked “+i”, ‘*+‘*or “-*’ then begin mark ui by “+f, and add it to 2; take the vertex w such that (ui, w) EM; comment: since by t!x :X;T algorithm UI is not free and ti = true, there is such

December

1977

:, vertex w which is not marked I‘+‘*, “-“, ,,+i”

or

,,_i”;

mark w by ” --i’ ~,uAadd it to % and Qi;

end; advance Ti on L(ui); Si := (01~ 0 and ti); endendend; ifsi then delete the marks “-2” and “+2” from the elements of i! and change every “+l” to “+” dnd every “- 1” to “-*’ else delete the marks “- 1” and “+I” from the elements of % and change every “+2” to “+” and every “-2” and “-“; t := tl or t2 end; begin comment: the main algorithm; t := true; let A be the set of free vertices; PART(A)0,; while t and there are unmarked vertices d.o begin take an edge (u, u) E M such that u, LJare unmarked; comment: since all the free vertices are already marked, there must be such an edge;

PART({x}, (~1, end; let C be the set of vertices marked “+‘*; if t then G is semipartite 2nd C is a minimum node covermg else G is not semipartite end.

By the algorithm, the time spent on successful possibilities is 0( i Vi + IEI) and the time spent on unsuccessful possibilities is no more than this, so the total time required by the algorithm is 0( 1VI + El) plus the time to find a maximum matching. For example consider the graph G of Fig. l(a) with [he set of thick edges as a maximum n-latching. We start by marking v7 by “- 1”. PART( {v7 }, 0) marks v5 by “+” and vg, u7 by “-“. Now we pick (v, , v2) E M among the unmarked vertices. PART( {vI }, { v2 1) marks v1 by “-1 “, “+2” and u2 by “t l”, “-2”. Then it marks u3 by “+l ‘*$“t2” and u4 by “- 1”) “-2”, since (vJ,v4)EM.Yet,ul isine, andu2 isinQ2.During the next round, PART( {v, ) , { v2 )) will try tcl mark v4 from uI , but u4 is marked “- 1” hence it will set. t, = false. Also, it will remove v2 from Q2 and will end with t2 = true. Thus, the entire algorithm ends with t = true. Therefore c;‘ is semipartite and we see in Fig. l(b) its partition into Cand V-C’. We must remark here that the algorithm described by Berge in [ 1, p. 184) is applicable only to
Volume 6, number 6

INFORMATION PROCESSING LETTERS

Theorem 3. Algorithm COV is CYNY e*ct. Roof. Consider a graph G(v, E) with a maximum

matchingM, and let us apply Algorithm COV to G. it is easy to see that if the algorithm ends with r‘= true then C is a node covering and ICI = 1M1,hence G is semipartite. Therefore if G is not semipartite, the algorithm answers correctly. Ltt us now assume that G is semipartite and let A be the set i.4ffree vertices. By Lemma 2 all the vertices of A are not in a minimum node covering, hence PART(A) 8) marks them “- 1”. Then, PART(A) 8) continues to mark vertices by “+l” and “-1” according to whether they must or must not be in a minimum node cevering, as required by Lemma 2. Since G is . semtp&re, %RT(A 4 , 0) will end with t = true. Now, the algcvlthm takes an edge (u, u) EM, u and v unmarkc-:d,and performs PART( {u) , {u)). PART( (u), {u)) considers the two possibilities (PI) and (P2). For (Pi) it marks u by ‘W”, v by “-1” and for (P2) it marks u by “ -2”, u by “+2”. Then, for every of the two possibilities it continues to mark vertices as required by Lemma 2. Since G is semipartite, one of the two possibilities must be successful, acd PART( {u); (u)) must end with f = true. After the end of PART({u), (u)] let VI be the set of unmarked vertices, let CO be the set of vertices marked “+” and c,, the set of vertices marked “-“. Clearly, no vertex of VI is adjacent to a vertex of CO. Denote G, = G( Vi ) and let M, be the set of edges of M havialg both incident vertices in V, . Since V1 has

202

December 1977

no free vertices and there are no edges of M between vertices of VI and vertices of Co U co it follows that G: = G(M, ). Therefore, by Lemma 2(iv) GI is :semipartite. Now, Algorithm COV will continue performing on VI, and because there are no edges between vertices of Y1 and vertices of co, it will perform as if it works directly on Cl. Therefore, by induction, the algorithm on G1 terminates with t = true, hence the entire algorithm terminates with t = true.

Acknowledgement I would like to thank to the referee for his erpert suggestions which helped improve the efficiency of the algorithm.

References [ 1) C. Berge, The Theory of Graphs and its Applications, London, Methuen & Co. (John Wiley & Sons, New York, 1966). [2] J. Edmonds, Paths, trees and flowers, Canad. J. Math. 17 (1965) 449-467. 13) S. Even and 0. Kariv, An 0(n2ss) algorithm for maximum matching in general graphs, 16th Annual Symposium on Foundations of Computer Science (1975) 100-l 12. 14) F. Harary, Graph Theory (Addison-Wesley, Reading, MA, 1969). [5 ] D. Kiinig, Graphen und Matrizen, Mat. Fiz. Lapok 38 (1931) 116-119.