AN ALGORITHM TO FIND A MAXIMUM

7 downloads 0 Views 157KB Size Report
AN ALGORITHM TO FIND A MAXIMUM MATCHING OF A. TRAPEZOID GRAPH. PRABIR K. GHOSH AND MADHUMANGAL PAL. Abstract. The computation of ...
AN ALGORITHM TO FIND A MAXIMUM MATCHING OF A TRAPEZOID GRAPH PRABIR K. GHOSH AND MADHUMANGAL PAL Abstract. The computation of maximum matching is an important task in graph √ theory. For general graph an O( n.m) time algorithm is available to solve this problem. In this paper, an efficient algorithm is presented which takes O(n2 ) time and O(n + m) space for a trapezoid graph, where n and m represent the number of vertices and the number of edges of the graph.

1. INTRODUCTION A trapezoid Ti is defined by four corner point [ai , bi , ci , di ], where ai < bi and ci < di with ai , bi lie on the top line and ci , di lie on the bottom line of a rectangular channel. An undirected graph G = (V, E) with vertex set V = {v1 , v2 , . . . , vn } and edge set E = {e1 , e2 , . . . , em } is called a trapezoid graph if a trapezoid representation can be obtained such that each vertex vi in V corresponds to a trapezoid Ti and (vi , vj ) ∈ E iff the trapezoids Ti , Tj corresponding to the vertices vi and vj intersect. For simplicity, the vertices v1 , v2 , . . . , vn are represented respectively by 1, 2, . . . , n. Then (i, j) is an edge iff Ti and Tj intersect. It is interesting that if ai = bi and ci = di then corresponding trapezoid Ti reduces to a straight line. In this way if all the trapezoid reduce to straight lines then the corresponding trapezoid graph reduces to nothing but a permutation graph. Similarly, the trapezoid graph reduces to an interval graph if ai = ci and bi = di for all i. In addition to this we assume that these n trapezoids are in increasing order of their right corner points on the top line, i.e., for two trapezoids Ti and Tj , bi is on the left of bj iff i < j. In graph theory, it is a fundamental problem to find a maximum matching of a graph. This problem has various applications in the field of computer science. In the following we introduce some definitions. Definition 1. Matching. A matching in a graph is a set of edges in which no two edges are adjacent. A single edge in a graph is obviously a matching. 2000 Mathematics Subject Classification: 05C85. Key words and phrases: Design and analysis of algorithms, trapezoid graph, maximum matching. c The Korean Society for Industrial and Applied Mathematics, 2005 °

PRABIR K. GHOSH AND MADHUMANGAL PAL

Definition 2. Maximum matching. A maximum matching is a matching with the maximum cardinality. The cardinality of the maximum matching is called a matching number. Several applications of maximum matching are available in literature. One of them is presented here. Suppose, in a village there are an equal number of boys and the girls of marriageable age. Each boy dates a certain number of girls and each girls dates a certain number of boys. This situation is represented by the graph shown in Figure 1. The boys and the girls represented by vertices. The edges represent the dates of each boy of a certain number of girls and vice-versa. Under what condition is it possible that every boy and girl gets married to one of their dates ? This is a problem of maximum matching of one set of vertices to another. ¾» ¾» s s ( ( ³ ³ g1 ((( b1 HH ( ³ ( ( ³ H(( ³ s( h((H ³³ ((³ ³s g2 ³ hH hH ³( ( b2 hh³ ³ h( ( h ³ h ( hhh ³(( HH ³³ ³( hs s( ³( ³³ H ((( g3 ( b3 hhh³ h³ ( H h ( h ³ ((hhhhH ((( Hs hH s³ (³ h g

b4

½¼

boys

4

½¼

girls

Figure 1: An illustration of maximum matching. Let G = (V, E) be a graph and M be a matching in G. If the vertex v of the graph G is the end vertex of some edge in the matching M then v is said to be M -saturated and we say that M-saturates v. Otherwise v is M -unsaturated. An M -alternating path in G is a path whose edges are alternating in M and E − M . An alternating path whose origin and terminus are both M -unsaturated is called an M -augmenting path. 2.5 For general graphs, Even and Kariv [4] √ presented an O(n ) time algorithm and Micali and Vazirani [8] presented an O( nm) time algorithm for finding maximum matching. Schieber and Moran [9] gives a parallel algorithm for finding maximum matching which runs in O(n log n) time with O(n2 ) processors. Restricting the problem to the cograph (given a parse tree), Lin and Olariu [7] presented an O(log n) time using O(n/ log n) processors parallel algorithm. Uehara and Chen [10] solve the maximum weighted matching (MWM) problem for a general graph. The maximum cardinality matching (MCM) problem is the special case of the MWM problem where all edges of the input graph have the same weight. For the MWM problem, Edmonds’ algorithm [3] has stood as one of the paradigms in the search of polynomial time algorithm for integer programming problem (See [6]). Some sophisticated implementations of his algorithm have improved its time complexity, for example, Gabow [5] has given an algorithm using O(n(m + log n)) time and O(m) space.

MAXIMUM MATCHING ON TRAPEZOID GRAPHS

To the best of our knowledge, no algorithm is available to find maximum matching on trapezoid graphs. In this paper, we designed an efficient algorithm to find a maximum matching of a trapezoid graph. The proposed algorithm takes O(n2 ) time and O(n+m) space. 2. PRELIMINARIES In this section, we present the preliminaries of trapezoid graph and some results necessary to develop the algorithm. For a given trapezoid graph G = (V, E) with V = {1, 2, . . . , n} there are n trapezoids T1 , T2 , . . . , Tn in the trapezoid representation. Each j ∈ V corresponds to a trapezoid Tj with corner points as aj , bj on the top line and cj , dj on the bottom line. Let us consider an example of a trapezoid graph and its trapezoid representation consisting of eight trapezoids T1 , T2 , . . . , T8 are given in Figure 2. 7l 8l a # la A # · A l aaa A · A l aa # aa A # · A l aAa # l · A a # l A a l · A 1l l » »3 A Z · # l»»»A»# T Z· A A »»l # T Z » A» » l# A T· Z »»» A # l A · T » Z » # »»Z l AA A » ·· » # » T Z l l A 2l Z # ! 4 T ! A Z # ! ¡ T Z # A !! ¡ ! T Z # !! A ¡ T # !Z !Z A #! ¡ TT Z ZA l # !! 5l 6¡

(a) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ³ ³ ³³ ³l b b ³ l C ³³ ³ S b C³ ¢ b ³ ¤ l ³ ³C £ b b S ³³ ¢l C ¤ ³³ b b ³ ³ ³ S ³³ bC£ b ¢ l C¤ b b ³³ ³ l¤ C ³³S ³ ³³ £C b bb¢ £ C b ¢b CC S ¤ l b¢ b C l b S

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 (b) Figure 2: (a) a trapezoid graph, (b) its trapezoid representation.

PRABIR K. GHOSH AND MADHUMANGAL PAL

Definition 3. Right spread. The right spread f (i) of a trapezoid Ti on the vertex i is max{bi , di }, i.e., f (i) = max{bi , di }, i ∈ V. That is, the array f (i) is the right spread of all vertices i ∈ V . The arrays ai , bi , ci , di and f (i) of the graph of Figure 2 are shown in Table 1. vertex i 1 2 3 4 5 6 7 8 ai 1 2 3 5 7 9 11 13 bi 4 6 8 10 12 14 15 16 ci 4 2 3 12 8 9 1 14 di 11 6 7 15 10 13 5 16 f (i) 11 6 8 15 12 14 15 16 Table 1: The arrays ai , bi , ci , di and f (i). Some results on trapezoid graphs are presented below. Lemma 1. [1] Two vertices i and j of a trapezoid graph are not adjacent iff either (i) bi < aj and di < cj or (ii) bj < ai and dj < ci . Observation: Let u, v, w be any three vertices of G such that f (u) < f (v) < f (w) and (u, v) 6∈ E. Then there may be an edge between u and w. This statement is justified in the following. We consider Figure 2. Let u = 2, v = 6, w = 7. It is obvious that f (2) < f (6) < f (7) and (2, 6) ∈ / E but (2, 7) ∈ E. Again, let u = 2, v = 5, w = 8 then f (2) < f (5) < f (8) and (2, 5) ∈ / E also (2, 8) ∈ / E. Theorem 1. [2] Let M1 and M2 be two matchings in a simple graph G. Let H be the subgraph of G induced by the set of edges M1 4M2 = (M1 − M2 ) ∪ (M2 − M1 ), Then each connected component of H is of one of the following two types: (i) a cycle of even length whose edges are alternately M1 and M2 , (ii) a path whose edges are alternately M1 and M2 and whose end vertices are unsaturated in one of the two matchings. Theorem 2. [2] A matching M in a graph G is a maximum matching if and only if G contains no M −augmenting path. 3. THE METHOD Deletion of a vertex from the graph means, deletion of that vertex and its adjacent edges. Let M be the set of edges which form a matching of the graph G. Find the maximum of bi and di , i.e., f (i) = max{bi , di }, for all i. Arrange all the elements of f (i) in ascending order. After that, select two minimum values from the array f (.). Let these minimum values be f (i) and f (j). If (i, j) ∈ E then take it as a member of the set M and remove the vertices i and j from the trapezoid represents and mark the

MAXIMUM MATCHING ON TRAPEZOID GRAPHS

corresponding elements of f (.). If (i, j) ∈ / E then drop j (if i < j) and select the next minimum element from the array f (.). Let it be k. If (i, k) ∈ E then put (i, k) to M otherwise take next minimum from f (.) and so on. All the selected edges in which no two edges are adjacent is called a matching (a single edge in a graph is obviously a matching). Count all the edges of the subset M which is the cardinality of the maximum matching of the graph. The pseudocode of the proposed method is presented as follows: Algorithm MM Input: A trapezoid graph T with its trapezoid representation Ti (ai , bi , ci , di ), i = 1, 2, . . . , n. Output: Maximum matching M . Initialization, set V 0 = V, M = φ (the null set). Step 1: Compute the array f (i) = max{bi , di }, for all i ∈ V . Step 2: Sort the array f (i) in ascending order. Step 3: Select the first minimum among f (i), i ∈ V and let it be f (u). Set X = {u}. Step 4: Select next minimum among f (i), i ∈ V 0 − X and let it be f (v), v ∈ V 0 − X, goto Step 4.2. Step 4.1: (i) If V 0 − X 6= φ then find minimum among f (i), i ∈ V 0 − X and let it be f (v). (ii) if V 0 − X = φ, then let V 0 = V 0 − {u} and if |V 0 | ≥ 2 then goto step 3 else stop. Step 4.2: If (u, v) ∈ E then M = M ∪ {(u, v)}, V 0 = V 0 − {u} − {v}; If |V 0 | ≥ 2 then goto step 3 else stop; else X = X ∪ {u} and goto step 4.1; endif Step 5: The cardinality of M is the size of the maximum matching. end MM. For the graph of Figure 1 the maximum matching is M = {(2, 3), (1, 5), (6, 7), (4, 8)} and |M | = 4. 4. CORRECTNESS AND COMPLEXITY OF THE ALGORITHM In this section, we establish that the proposed algorithm MM correctly computes the maximum matching of a trapezoid graph. Also, here the time and space complexities are calculated. Lemma 2. The set M obtained from the algorithm MM is a matching.

PRABIR K. GHOSH AND MADHUMANGAL PAL

Proof. An edge (u, v) of M is selected at step 4.2 of the algorithm M M and deleted the vertices u and v from the graph, i.e., from the array f (.). So, V is free from u, v and also its adjacent vertices. Therefore, there is no scope to select u and v in the next subsequent iteration. Thus, each edge of M has distinct end vertices. So, M is a matching. 2 Lemma 3. The set M obtained from the algorithm MM is a maximum matching. Proof. The array f (i) is ordered in increasing value of the right endpoints bi and di of the trapezoid Ti . In the algorithm M M we select two vertices u and v corresponding to the trapezoids Tu and Tv such that their right spread is minimum. If (u, v) ∈ E then we choose (u, v) as a member of M and delete the vertices of u and v. If (u, v) ∈ / E then we select another new vertex whose right spread is minimum among all other vertices except first two vertices u and v. If we select (u, v) as a member of M , with right spread of u is minimum but right spread of v is maximum then maximum number of vertices are deleted during the execution of the algorithm. So, there is no chance to select more edges for M . Thus, the selection of the vertices whose right spread minimum is essential. During the execution of the algorithm we select the edges for M as soon as they occur in the array f . Hence, the set M is maximum. 2 The time and space complexity of the algorithm M M are given below. Lemma 4. The worst case time complexity of the algorithm MM is O(n2 ) and space complexity is O(n + m), where n and m represent respectively the number of vertices and edges. Proof. The step 1 and step 2 of the algorithm M M takes only O(n) time. In the process of finding maximum matching, let f (i) be the minimum among the all elements of the array f (.) and compare the vertex i to remaining (n − 1) vertices out of n vertices. Suppose f (j) is the next minimum element and (i, j) ∈ E. Then the edge between the vertices i and j is selected. The remaining vertices are (n − 2). Out of the remaining (n − 2) vertices two minimum elements corresponding to the vertices are adjacent and the remaining vertices of the array f (.) becomes (n − 4). This process is continue until the number of vertices of the array becomes less then 2. To find minimum among O(n) elements takes O(n) time. The steps 3 and 4 repeat at most n/2 times. The steps 3 and 4 takes O(n).n/2 = O(n2 ) time. Hence, the worst case time complexity is O(n2 ). Here the size of the array f and each set V, V 0 , M, X are O(n). Size of each N [u] is equal to deg(u), P deg(u) represents the degree of the vertex u. Then the sum of size of all N [u] is u∈V deg(u) which is equal to the O(m). Hence, the total space required by the algorithm M M is O(n + m). 2 Form the above lemma we have the following result. Theorem 3. A maximum matching of a trapezoid graph of n vertices and m edges can be computed in O(n2 ) time using O(n + m) space. Theorem 4. The best time complexity of the algorithm MM is O(n), where n is the number of vertices.

MAXIMUM MATCHING ON TRAPEZOID GRAPHS

Proof. If all the elements of the array f (i) occurred in such a way that the consecutive two elements are selected as the member of M , then the time complexity of the algorithm M M is obviously O(n). 2 5. CONCLUSION In this paper, we designed an efficient algorithm to find a maximum matching of a trapezoid graph. The time complexity of the algorithm is O(n2 ) and the space complexity is O(n + m). But, the time complexity is not optimal. So, there is a scope to design an algorithm with optimal time complexity. References [1] D.Bera, M.Pal and T.K.Pal, An efficient algorithm to generate all maximal cliques on trapezoid graphs, Intern. J. Computer Math., 79 (10)(2002) 1057-1065. [2] J.Clark and D.A.Holton, A first look at graph theory, (World Scientific publishing Co. Pte. Ltd., 1991). [3] J.Edmonds, Paths, trees and flowers, Canad. J. Math, 17 (1965) 449-467. [4] S.Even and O.Kariv, An O(n2.5 ) algorithm for finding maximum matching in general graphs, in: proc-16th IEEE Symp. on Foundations of computer Science (1975) 100-112. [5] H.N.Gabow, Data structures for weighted matching and nearest common ancestors with linking, in: Proc. 1st Ann. ACM-CIAM Symp. on Discrete Algorithms, (1990) 434-443. [6] Z.Galil, Efficient algorithms for finding maximum matching in graphs, Comput. Serveys, 18 (1)(1986) 23-38. [7] R.Lin and S.Olariu, An optimal parallel matching algorithm for cographs.J.Parallel Distributed Computing, 22 (1994) 26-36. p [8] S.Micali and V.V.Vazirani, An O( |V |.|E|) algorithm for finding maximum matching in general graphs, in: FOCS (1980) 17-27. [9] B.Schieber and S.Moran, Slowing sequential algorithms for obtaining fast distributed and parallel algorithms: maximum matchings, in 15th Annual Symposium on principles of distributed computing, (1986) 282-292. [10] R.Uehara and Z.Z.Chen, Parallel approximation algorithms for maximum weighted matching in general graphs, Information Processing Leters, 76 (2000) 13-17. Prabir K. Ghosh and Madhumangal Pal: Dept. of Applied Mathematics with Oceanology and Computer Programming, Vidyasagar University, Midnapore-721102, INDIA E-mail : [email protected] (Madhumangal Pal)

Suggest Documents