4
V IQ, number 4.5 INFORMATION PZ XESSING LETTERS 5 July 1980 TCHINGS AND TREES ala SAVAGE mputer Science Department, North CarolinaState University, Raleigh, NC 27607, U.S.A. ed 6 November 1979; revised version received 4 March 1980 ~ombjRatoria1 problems, computational complexity, algorithms, matching, graphs, trees in a graph G = (V, E) is a subset M of vertex of V is incident with more than A maximum matching is a matching of inality. It has been shown by I-Iopcroft and Marp [2] that a maximum matching in a bipartite graph G can be found in time O((m + nM), where m is the number of edges of G and n the number of ver- tices. Even and Kari*,r 113 hwe shown how to find a maximmm matching in time 0(n2as) or O(m+ .‘og n), depending on the choice of data structure. If G is a tree, the algorithm of Hopcroft and Karp will fmd a maximum matching in time O(n’*‘). In this paper we introduce the concept of a ‘proper matching’ in a tree and use it in Section 2 to find a maximum matching in a tree in time O(n). In Section 3 we use proper matchings to show that if T is any depth-first search spanning tree f3] of G, then a maxi- mum matching in T is at least half the size of a maxi- mum matching in G. This bo:lnd is shown to be tight. It is interesting that, akhough the ratio of the number of edges in G to the number of edges in a spanning tree of G can be as large as (G(n)), the ratio of the size of a matimum matching m G to the size of a axinum matching in any depth first search spanning ee of G is constant, of this se&on is devoted to definitions ology needed for Sections 2 and 3. a matching of 6. A vertex if v is not incident ting path in G is a path ich the edges are alternately in M and not in 202 M. An augmenting path relative to M is an alternating path in G which joins two vertices which are free with respect to M. M is a maximum matching in G if and only if G has no augmenting paths relative to kI. A rooted tree T = (V, E, r) is a tree with a vertex r of V distinguished as the root. For v E V, let d(v) denote the distance from v to r, If w E V and (v, w) E E and d(w) = d(v) + 1, then v is the father of w and w is the son of v. Note that every vertex w, distinct from r, has a father, which we denote by F(w). Vertex wr is a brother of vertex w2 if there is a vertex v such that v = F(urr ) = F(w2). If there is a path in T joining v and w and. d(v) < d(w), then v is an ancestor of w and w is a descendant of v. If v # w, then v is a proper ancestor of w and w is a proper descendant of V. 2. Maximum matchings in trees Let T = (V, E, r) be a tree rooted at r. Defane a proper matching of T to be a matching M S. E which satisfies the following property: If a vertex v # r of T is free with respect to M, then for some brother, w, of v in T the edge (w, F(v)) is in M. (I) Note in particular that if M is a proper matching for T and v is a vertex distinct from r, then both v and F(v) cannot be free with respect to is a proper matching of the tree T = (V, E, r), then M is a maximum matching of T.

Maximum matchings and trees

Embed Size (px)

Citation preview

Page 1: Maximum matchings and trees

V IQ, number 4.5 INFORMATION PZ XESSING LETTERS 5 July 1980

TCHINGS AND TREES

ala SAVAGE mputer Science Department, North Carolina State University, Raleigh, NC 27607, U.S.A.

ed 6 November 1979; revised version received 4 March 1980

~ombjRatoria1 problems, computational complexity, algorithms, matching, graphs, trees

in a graph G = (V, E) is a subset M of vertex of V is incident with more than A maximum matching is a matching of inality. It has been shown by I-Iopcroft

and Marp [2] that a maximum matching in a bipartite graph G can be found in time O((m + nM), where m is the number of edges of G and n the number of ver- tices. Even and Kari*,r 113 hwe shown how to find a maximmm matching in time 0(n2as) or O(m+ .‘og n), depending on the choice of data structure.

If G is a tree, the algorithm of Hopcroft and Karp will fmd a maximum matching in time O(n’*‘). In this paper we introduce the concept of a ‘proper matching’ in a tree and use it in Section 2 to find a maximum matching in a tree in time O(n). In Section 3 we use proper matchings to show that if T is any depth-first search spanning tree f3] of G, then a maxi- mum matching in T is at least half the size of a maxi- mum matching in G. This bo:lnd is shown to be tight. It is interesting that, akhough the ratio of the number of edges in G to the number of edges in a spanning tree of G can be as large as (G(n)), the ratio of the size of a matimum matching m G to the size of a

axinum matching in any depth first search spanning ee of G is constant,

of this se&on is devoted to definitions ology needed for Sections 2 and 3.

a matching of 6. A vertex if v is not incident

ting path in G is a path ich the edges are alternately in M and not in

202

M. An augmenting path relative to M is an alternating path in G which joins two vertices which are free with respect to M. M is a maximum matching in G if and only if G has no augmenting paths relative to kI.

A rooted tree T = (V, E, r) is a tree with a vertex r of V distinguished as the root. For v E V, let d(v) denote the distance from v to r, If w E V and (v, w) E E and d(w) = d(v) + 1, then v is the father of w and w is the son of v. Note that every vertex w, distinct from r, has a father, which we denote by F(w). Vertex wr is a brother of vertex w2 if there is a vertex v such that v = F(urr ) = F(w2). If there is a path in T joining v and w and. d(v) < d(w), then v is an ancestor of w and w is a descendant of v. If v # w, then v is a proper ancestor of w and w is a proper descendant of V.

2. Maximum matchings in trees

Let T = (V, E, r) be a tree rooted at r. Defane a proper matching of T to be a matching M S. E which satisfies the following property:

If a vertex v # r of T is free with respect to M, then for some brother, w, of v in T the edge (w, F(v)) is in M.

(I)

Note in particular that if M is a proper matching for T and v is a vertex distinct from r, then both v and F(v) cannot be free with respect to

is a proper matching of the tree T = (V, E, r), then M is a maximum matching of T.

Page 2: Maximum matchings and trees

Voh ae 10, number 4,s INFORMATION PROCESSING LETTERS 5 July 1980

fieof- It suffices to show that T has no augmenting path relative to M. Suppose there were a simple aug- menting path p joining free vertices a and b in T. Let w be an ancestor in T of both a and b such that no proper descendant of w is an ancestor of both a and b. Then p consists of the two paths pa, joining a and w, and pb , joining b and w. Since p has odd length, 1 p f, assume, without loss of generality, that I pa 1> I pb 1.

If 1 p 1 z 1, then b = F(a), but since both a and b are then free, this contradicts the assumption that M is a proper matching. If I pl > 1, then I p,l 2 2. Thus (a, F(a)) and (F(a), F(F(a))) both lie on pa and since pa is an alternating path, (F(a), F(F(a))) E M. How- ever since M is a proper makhing, (F(a), x) E M for some brother x of a. Sine,: x # F(F(a)), we have two distinct edges of M incident on the vertex F(a), a con- tradiction.

Below, we present an algorithm to find a proper matching in a tree T = (V, E, r). We assume a data structure which maintains for each vertex a list of its sons and which allows the following operation to be performed efficiently:

NEXTSON( returns next unscanned son of V if there are any; otherwise returns NIL.

-‘n addition, we maintain a Boolean array FREE which determines whether a vertex is currently free, and a set, M, of edges. We verify in Lemma 2 that upon ter- mination of the algorithm M is a proper matching for T. The algorithm uses the recursive procedure MATCH which follows it.

Tree matching algorithm //Finds a proper matching M in a tree T = (V, E, r)l/ begin for x E V do FREE[x] := true; MATCH (r, M, FREE) end

procedme MATCH (x, M, FREE): begin M := 8; w := NEXTSON (x);

NIL do

MATCH (w, S, FREE); M := M + S;

if FREE[wJ and FREE[xJ then begin M := M + {(x, w)); FREE[x] := false end

w := NEXTSON -

end end

h+Jote that if M and S are maintained as linked lists, then M := M + S can be performed in time O( IS I).1

For a vertex v in a rooted tree ‘I’ = (V, E, r), let T, = (&, E,, x) be the subtree of T rooted at x.

Lemma 2. Let x be a vertex of T. If FREE[v] is ini- tially true for each v in T,, then after executing MATCH (x3 M, FREE), M is a proper matching in T, and FREE[x] is true if and only if x is free with respect to M.

Proof. We use induction on the number of vertices of T,. If IV, I = 1, then MATCH (x, M, FREE) leaves FREE[x] true and sets M = $. Assume that IV, I > 1 and the lemma is true for subtrees with fewer than lV, I vertices. The procedure MATCH (x, M, FREE) initializes M to empty and for each son w of x, finds a proper matching M, for Tw and adds those edges to M. In addition, if some son w is found to be free with respect to M, (FREE[w] = true), then the first such son encountered is matched with x, the correspond&: edge is added to M and FREE[x] becomes false. Otherwise, FREE[x] remains true. To see that M is ia proper matching of T,, let y # x be a vertex of T, which is free with respect to . Then y is in Tw for some son w of x. If y # w, then F(y) is matched with a brother of y, since by the induction hypothesis, Mw = M n Tw is a proper matching in al,. If y = w, then F(y) = x and x has been matched with some other son b, irl, JCH (x, is proper.

mma 2 shows tha

0( IV I ) algorithm for finding a maximum matching in a tree.

Page 3: Maximum matchings and trees

Votumc 10, number 4, S INFORMATiON PROCESSING LETTERS 5 July 1980

T is a spanning tree of a graph G and and M(G) are maximum matchingsi.n T and G,

ratio IM(G) I/ I M(T)1 can be as large G is a complete graph with n) and T is the spanning tree

in 1. However, we can show search scanning tree of G . The proof relies on the fol-

3. Let G = (V, E) be an undirected graph with and let T = (V, E’, r) be a depth-first search

tree of G, Let M(G) be a maximum matching G and let M(T) be a proper matching of T. Then if

e with respect to M(T), IM(G)I < 2IM(T)I. se, IM(G)I < 2IM(T)I - 1.

Prsaf. We use induction on the number of vertices of G. if n = I, then M(G) = M(T) = $9. In this case, V = {I) and I is free, so the lemma is true. If n > 1, assume inductively that the lemma holds for graphs G’ = (V’, E’) with 1 G IV’1 C n.

*Let w be a descendant of r such that (i) w has k sons where k = 0 or k > 2 and (ii) every proper ancestor of w has exactly one son.

LRt p be the path

vo = r, vr , . . . . v, = w

ningrz.ndwinT.NoteO<t=IpI<n-landpis ahernating path with respect to M(T). If Ipl=

then lM(T)l= Ip n M(T)I = ri(n - l)]. No a graph with n vertices can have more 1) 1 edges, thus IM(T)I = I M(G)1 and the

holds. If Ipl< n - 1, then w has k > 2 sons sk. Lt Ti be the subtree of T with root Si

et Gi be the vertex subgraph of G induced by the ote th3t M(T) t? Ti is a proper

(G) n Gi is B matching (not urn) in Gi. Since

ng tree of @, an edge G is either a tree ge joining a vertex wi

(6) either lies in scme

Gi (1 < i < k) or else joins a vertex of some Gi with a vertex of p. No vertex of p can be incident with more than one edge of M(G), thus

k

IM(G)I < g IM(G) n GiI + t + 1.

We divide the remainder of the proof into two cases. &e 1: Either IpI= 0 (i.e. w = r) and r is not free with respect to M(T) or Ip I > 0 and (v+ 1, w) $ M(T).

M(T) is proper, so w is not free with respect t\, M(T). Thus (w, Sj) E M(T) for some j with 1 < j f k. Then sj is free with respect to M(T) n Tj. SO, by the induction hypothesis, for 1 < i f k,

IM(G)n GiI<2IM(T)nTiI.

Thus,

k

IM(c)l<z$M(T)nT,)+t+l.

Since

k

MUI = @KV n P) ” 2 (M(T) n Tib) u CCW, Sj)ll

and these sets are pairwise disjoint, we get

6 IM(T)nTiI= IM(T)I- IM(T)npI - 1. i=l

Thus,

lM(G)l< 2(IM(T)I - IM(T) n pl- 1) + t + 1.

NOW, if r is free with respect to M(T), IM(T) n pl = l(t - 1). Thcs, IM(G) I < 2 IM(T) I. ‘If r is not free with respect to M(T), then IM(T) n pl = ft, thus M(G)1 < 2iM(T)I - 1. Case 2: Either Ipl= 0 (i.e. r = w) and r is free with respect to M(T) or lp I > 0 and (vt._r , w) E M(T).

Since M(T) is proper, no son of w is free with respect to M(T). Thus, for 1 <i < k, si is not free with respect to M(Ti). By the induction hypothesis, for 1 < i<k

IM(G)nGiI<2IM(T)nTiI-1.

Thus,

k

(T)n%iI--1)-t-t+l.

Page 4: Maximum matchings and trees

Volume 10, number 4,5 INFORMATION PROCESSING LETTERS 5 July 19rfUo

Since

M(T)=(M(T)np)U ;I (M(T) n Ti)) 3

ve hiwe

5 IM(T) n TiI= IM(YjI - IM(T) n PI. i=l

Thus,

IM(G)K2(lM(T)l- IM(T)npl)-k+t + 1.

Whether or not r is free in this case,

lM(T) n pl= [it 12 it.

Thus,

lM(G)l< 2lM(T)l+ (1 - k).

Since k > 2, we have IM(G)I G 2 IM(T)l - I. This com- pletes the proof of Lemma 3.

Theorem. Let G be an undirected graph and T, a depth-first search spanning tree of 6. If M(G) and M(T) are maximum matchings of G and T, respectiv- ely, then IM(G) I < 2 IM(T) I.

Proof. Let N be a proper matching of T. By Lemma 3, IM(G)I < 2lNl and by Lemma 1, INI = IM(T)I.

The lemma below shows that for the general case, this bound is tight.

Lemma 4. For any k 2 1 there is a graph G and a depth-first search spanning tree T of G such that IM(G)I = 2 IM(T)I = 2k for maximum matchings M(T) of T and M(G) of G.

hoof. I&t V = {al, . . . . a2k, br, . . . . bk, cr, . . . . ck) and let

A = ((ai,ai+r) I1 <K2k- l},

B z {(bi, a2i) I I < i < k},

Cr = {(ci, a2i) I 1 <i <k),

C2 = {(ci, azi_1) I 1 < i < k).

Let G=(V,E),whereE=AUBUCr UC2.0ne depth-first search spanning tree of G is T = (V, A U B U Cr , al j and the edges of C2 are back edges of T. B is a maximum matching of T, B U Ca is a maximum matchingofGand lBUC21=2lBl=2k,

[ 1] S. Even and 0. Kariv, An O(n205) algorithm for mwimum matching in general graphs, Proc. 16th Annual IEEE Sym- posium on Foundations of Computer Science (1975) 100-112.

[2] J.E. Hopcroft and R.M. Karp, An $1’ algorithm for max- imum matching in bipartite graphs, SIAM J. Comput. 2 (1973) 225-231.

[ 31 R.E. Tarjan, Depth first search and linear graph algo- rithms, SIAM J. Comput. 1 (2) (1972) 146-160.