Popularity vs Maximum cardinality in the stable ... - Semantic Scholar

Popularity vs Maximum cardinality in the stable marriage setting∗ Telikepalli Kavitha† Abstract Given a bipartite graph G = (A ∪ B, E) where each vertex ranks its neighbors in a strict order of preference, we consider the problem of computing a largest matching in the set of popular matchings in G. A matching M is said to be popular if there is no matching where more vertices are happier than in M . The set of popular matchings is non-empty since every stable matching is popular and it is known that stable matchings always exist in G. The problem of computing a popular matching of maximum size in G = (A ∪ B, E) was considered in [8] where an O(mn0 ) algorithm was shown, where m = |E| and n0 = min(|A|, |B|). Here we show an O(m) algorithm for this problem. A largest popular matching need not be a maximum cardinality matching in G. There are many applications where maximum cardinality is one of the requirements, and so the next problem that we consider is the following: if M is the set of maximum cardinality matchings in G, compute M ∗ ∈ M that is popular within M. That is, we want a maximum cardinality matching M ∗ such that there is no matching in M that is more popular than M ∗ . We show that such a matching M ∗ always exists and can be computed in O(mn0 ) time. Though the above matching M ∗ is popular in the set of maximum cardinality matchings, in the entire set of matchings in G, its unpopularity factor could be as high as n0 − 1. On the other hand, a largest popular matching could be of size only 32 |M ∗ |. In between these two extremes, we show that there is an entire spectrum of matchings: for any integer k, where 2 ≤ k ≤ n0 , there is a matching Mk in k G of size at least k+1 |M ∗ | whose unpopularity factor is at most k − 1; also such a matching Mk can be computed in O(mk) time by a simple generalization of our largest popular matching algorithm.

1

Introduction

preference lists are symmetric, i.e., a belongs to b’s list if and only if b belongs to a’s list, for any pair of vertices a and b. Such an instance G is called an instance of the stable marriage problem with incomplete lists and it is customary to refer to the vertices in A and B as men and women, respectively. We will also refer to G as a bipartite graph with 2-sided strict preference lists. We assume that no vertex is isolated, so m ≥ n/2, where |E| = m and |A ∪ B| = n. A matching M is a set of edges, no two of which share an endpoint. For any vertex x that is matched in M , let M (x) denote x’s partner in M . An edge (u, v) is a blocking edge to M if both u and v prefer each other to their respective assignments in M , i.e., u is either unmatched in M or prefers v to M (u) and similarly, v is either unmatched in M or prefers u to M (v). A matching M is stable if M has no blocking edges. The existence of stable matchings in every instance G and the Gale-Shapley algorithm [4] to compute a stable matching are classical results in graph algorithms. Though the original Gale-Shapley algorithm assumed that all preference lists are complete, it is straightforward to generalize this algorithm to incomplete lists [7]. A stable matching has usually been considered the best way of matching vertices in G = (A ∪ B, E). However, stability is a very strong condition and it has been shown that all stable matchings in G have the same size and they all leave the same vertices unmatched [5]. There are many problems, where it is desirable to have matchings of larger size, for instance, in allocating projects to students, where the total absence of blocking edges is not necessary and a more relaxed notion of stability suffices. The notion of popularity captures a natural relaxation of the notion of stability: blocking edges are permitted in a popular matching M , nevertheless M has overall stability. That is, in popular matchings, pairwise stability gets replaced by global stability. We define popular matchings next.

The input here is a bipartite graph G = (A ∪ B, E) where each vertex ranks its neighbors in a strict order of preference. Every vertex u ∈ A ∪ B seeks to be assigned to one of its neighbors. Preference lists can be incomplete, which means that a vertex may be adjacent to only some of the vertices on the other side. Also, 1.1 Popular Matchings. For any two matchings M0 and M1 , we say that vertex u prefers M0 to M1 if u ∗ Part of this work was done during a visit to the Max-Planckis better-off in M0 than in M1 , i.e., u is either matched Institut f¨ ur Informatik, Saarbr¨ ucken under the IMPECS program. in M0 and unmatched in M1 or matched in both and † Tata Institute of Fundamental Research, Mumbai, India; prefers M0 (u) to M1 (u). Let φ(M0 , M1 ) = the number [email protected].

123

Copyright © SIAM. Unauthorized reproduction of this article is prohibited.

of vertices that prefer M0 to M1 . We say that M0 is more popular than M1 if φ(M0 , M1 ) > φ(M1 , M0 ). Definition 1. A matching M is popular φ(M, M ′ ) ≥ φ(M ′ , M ) for all matchings M ′ .

if

Popularity captures global stability since there is no matching where more vertices are better-off than in M , where M is a popular matching. G¨ardenfors [6] introduced the notion of popularity in the context of stable matchings. Every stable matching is popular [2]: when comparing a stable matching S to any matching M ′ , note that for any edge e ∈ M ′ , both the endpoints of e cannot prefer M ′ to S - if they do, then it contradicts the stability of S. Hence if one endpoint of e prefers M ′ to S, then the other endpoint has to prefer S to M ′ . Thus the number of votes in favor of M ′ is at most the number of votes in favor of S, hence M ′ cannot be more popular than S. Since stable matchings always exist in a stable marriage instance, popular matchings also always exist in a stable marriage instance. It is easy to come up with simple instances where we have a strict containment: {stable matchings} ⊂ {popular matchings} as seen in this example. Let A = {a1 , a2 } and B = {b1 , b2 } and let the preference lists be as shown below. a 1 : b 1 , b2 ;

a 2 : b1 ;

b1 : a 1 , a 2 ;

b2 : a 1 .

Here a1 ’s top choice is b1 and second choice is b2 while a2 has a single neighbor b1 . The vertex b1 ’s top choice is a1 and second choice is a2 while b2 has a single neighbor a1 . The matching {(a1 , b1 )} is the only stable matching here, while {(a1 , b2 ), (a2 , b1 )} is popular but unstable. It has been shown that a stable matching is a smallest or minimum cardinality popular matching [8]. There are instances, as in our example above, where a largest popular matching can be twice as large as a stable matching. So in problems where we are ready to substitute stability with popularity, for the sake of obtaining a matching of larger size, the desired matching is a maximum size or largest popular matching. The only polynomial time algorithm known for computing such a matching is an O(mn0 ) algorithm from [8], where n0 = min(|A|, |B|) and m = |E|. We show the following result here.

a largest popular matching is the same as that of computing a stable matching. We will show in Section 3 that a largest popular matching has size at least 23 |M ∗ |, where M ∗ is a maximum cardinality matching in G and we show simple examples at the end of this section where this bound is tight. There are some applications, for instance, in assigning training positions to trainees, where we cannot compromise on the size of the matching, so a largest popular matching may not always be the best matching in such applications. Here the matching has to be of maximum cardinality in G, and among such matchings, we want a “best” matching. So what we seek here is a maximum cardinality matching M ∗ such that for all maximum cardinality matchings M ′ , we have φ(M ∗ , M ′ ) ≥ φ(M ′ , M ∗ ). In other words, there is no maximum cardinality matching where more vertices are better-off than in M ∗ . It is not clear if such a matching M ∗ always exists. Let M be the set of maximum cardinality matchings in G. We show the following result. Theorem 1.2. In any bipartite graph G = (A ∪ B, E) with 2-sided strict preference lists, there always exists a maximum cardinality matching M ∗ that is popular within M (the set of maximum cardinality matchings), and M ∗ can be computed in O(mn0 ) time, where m = |E| and n0 = min(|A|, |B|). Though M ∗ is popular within the set M, note that M ∗ could be quite unpopular in the set of all matchings in G. In order to measure the unpopularity of a matching, we need the following definition. In any instance G, let us measure by what factor one matching (say, M1 ) can be more popular than another (say, M0 ) as follows: ∆(M0 , M1 ) =

φ(M1 , M0 ) φ(M0 , M1 )

if φ(M0 , M1 ) 6= 0.

Otherwise (i.e., φ(M0 , M1 ) = 0), define ∆(M0 , M1 ) to be ∞. Let X denote the set of all matchings in G. The unpopularity factor of M , denoted by u(M ), is maxM ′ ∈X \{M } ∆(M, M ′ ). A matching M is popular if and only if u(M ) ≤ 1. We show in Section 3 that u(M ∗ ) ≤ n0 − 1, where n0 = min(|A|, |B|), and we also show a simple example where this bound is tight. While the solution as given by Theorem 1.1 is a maximum cardinality matching within the set of popTheorem 1.1. A largest popular matching in a biparular matchings and whose size is lower bounded by tite graph G = (A ∪ B, E) with 2-sided strict preference 2 ∗ |M |, the solution as given by Theorem 1.2 is a popular lists can be computed in O(m) time, where m = |E|. 3 matching within the set of maximum cardinality matchThus we have a linear time algorithm to compute a ings and whose unpopularity factor is upper bounded by largest popular matching in a stable marriage instance n0 − 1. It is natural to ask if there are matchings sandG = (A ∪ B, E) and the complexity of computing wiched between these two extremes. We show that there

124

Copyright © SIAM. Unauthorized reproduction of this article is prohibited.

is an entire spectrum of such matchings and these can be computed efficiently. Theorem 1.3. For every integer k ≥ 2, there exists a matching Mk in G = (A∪B, E) such that u(Mk ) ≤ k−1 k |M ∗ |; such a matching Mk can be and |Mk | ≥ k+1 computed in O(mk) time, where m = |E|.

B

A S1 A1

B1

A0 B0 When the parameter k = n0 , Theorem 1.3 promises ∗ S0 a matching Mn0 such that |Mn0 | = |M |. It will be shown in Section 3 that this matching Mn0 will, in fact, be popular within M - thus this is the matching described in Theorem 1.2. When k = 2, Theorem 1.3 Figure 1: M2 = S1 ∪ S0 , where S1 (similarly, S0 ) is stable promises a matching M2 such that u(M2 ) ≤ 1, i.e., M2 is in the graph induced on A1 ∪ B (resp., A0 ∪ B0 ). popular. It will be shown in Section 2 that this matching M2 will be a largest popular matching - thus this is the matching described in Theorem 1.1. The bottom layer vertices are a1 and b2 . Since there is an edge between a1 and b2 , we get S0 = {(a1 , b2 )}. 1.1.1 Our approach. We now outline the main The termination condition is now satisfied. Thus the ideas used here. Our algorithm for k = 2 partitions matching {(a2 , b1 ), (a1 , b2 )} is returned. the vertex set A ∪ B into two layers: bottom and top. To Let M2 be the matching in G computed by this begin with, the top layer is empty. At any point in time, algorithm. When the algorithm terminates, let A1 the vertices of A (call them men) in the top layer are (similarly, A0 ) denote the set of men in the top (resp., there because they could not find partners by being in bottom) layer and let B1 (similarly, B0 ) denote the set the bottom layer. In this algorithm, the top layer men of women in the top (resp., bottom) layer. See Figure 1. get preferential treatment - in each iteration, the top The matching M2 has the following crucial properties: layer men first make their proposals and the vertices of • All the unmatched men are in A1 and all the B (call them women) that they seek are confined to the unmatched women are in B0 . top layer. Only the women not sought after by them are available to the bottom layer men. • Any blocking edge to M2 has to be in A0 × B1 . So in each iteration, the Gale-Shapley stable matching algorithm is first run with the top layer men propos• For any edge (a, b) ∈ A1 × B0 , a prefers M2 (a) to ing and all the women who received proposals disposb and b prefers M2 (b) to a. ing, let S1 denote this matching. All the women who These three properties allow us to show that M2 is are matched in S1 move to the top layer. The men in the bottom layer then run the stable matching algo- a largest popular matching in G. Note that the idea rithm with the women left in the bottom layer to yield a of “promoting” an unmatched man is reminiscent to a matching S0 . Refer to Figure 1. If all the bottom layer similar step in Kir´ aly’s approximation algorithms [11] men get matched in S0 , then S1 ∪ S0 is returned. Else for a maximum cardinality weakly stable matching in the unmatched men in the bottom layer are promoted G = (A ∪ B, E) where vertices have ties in their preferto the top layer and the next iteration begins. ence lists. However, since the goal in Kir´ aly’s algorithms Suppose we run the above algorithm on the simple is to compute a matching that admits no blocking edges, example on 4 vertices {a1 , a2 , b1 , b2 } described earlier: the promotion step is only to break ties in the prefera1 and b1 are each other’s top choices while a2 ’s only ence lists, whereas in our algorithm, the promotion of an neighbor is b1 and b2 ’s only neighbor is a1 . To begin unmatched man from the bottom layer to the top layer with, all the vertices are in the bottom layer. Though may create blocking edges. Nevertheless, the resulting top layer men propose first in every iteration, however matching will be popular. since the top layer is empty in the first iteration, we have Though it may seem as though our algorithm may S1 = ∅ in the first iteration and we compute a stable need to call a stable matching subroutine several times matching in the bottom layer with all the men proposing due to vertices getting promoted from the bottom layer and women disposing, so S0 = {(a1 , b1 )}. Then the to the top layer, we will construct this matching in linear vertex a2 , who is unmatched in S0 , gets promoted to time by a single invocation of a modified Gale-Shapley ˜ 2 that is derived the top layer. In the second iteration, the vertex a2 stable matching algorithm in a graph G gets to propose first and this yields S1 = {(a2 , b1 )}. from G. This algorithm is given in Section 2.

125

Copyright © SIAM. Unauthorized reproduction of this article is prohibited.

To contrast this algorithm with the one in [8] to compute a largest popular matching, the algorithm in [8] computes a set L ⊂ A ∪ B is in an iterative manner (using the stable matching algorithm) such that when the stable matching algorithm is run with vertices of L proposing to those in R = (A ∪ B) \ L, every vertex in R gets matched and no neighbor in L is preferred to its assignment in M by any vertex in L, where M is the resulting matching. It was shown in [8] that such a matching M has to be a largest popular matching. In order to construct an L that satisfies the above properties, this algorithm may use Θ(n0 ) iterations, where n0 = min(|A|, |B|). Thus this algorithm takes O(mn0 ) time.

in our algorithm also allows us to show that any augmenting path with respect to Mk has length at least k |M ∗ |, where 2k + 1, which implies that |Mk | ≥ k+1 ∗ M is a maximum cardinality matching in G. This implies that when k = n0 , the resulting matching Mn0 is of maximum cardinality and properties (1) and (2) of Theorem 1.4 enable us to show that Mn0 is popular restricted to the set of maximum cardinality matchings.

1.2 Background and Related results. Popular matchings have been studied extensively during the last few years [1, 13, 12, 10, 15, 14, 9, 16] in the case where only vertices of A have preferences while vertices of B have no preferences - this is the 1-sided preference lists model. Thus each edge e = (a, b) in G has a 1.1.2 The generalized algorithm. We generalize rank associated with it (the rank that a assigns to our algorithm on 2 layers to an algorithm on k layers, b) and it is only vertices in A that cast their votes. for any k ≥ 2. As in the case for k = 2, at the There are simple examples here that admit no popular very beginning, all the men are in the bottom layer matching. Abraham et al. [1] gave efficient algorithms or layer 0. In each iteration the men in the topmost to determine if a given instance admits a popular layer (layer k − 1) propose first to all the women - matching or not and if so, to compute one of maximum call this matching Sk−1 . Then the men in layer k − 2 size. McCutchen [14] introduced two measures of propose to the women left unmatched in Sk−1 - call this unpopularity: unpopularity factor and unpopularity matching Sk−2 . In decreasing order, for every i ≥ 0, the margin and he showed that the problem of computing a men in layer i propose to the women left unmatched in matching in the domain of 1-sided preference lists that ∪j>i Sj . If all the men, except those in the top layer, are minimized either of these measures is NP-hard. k−1 Si , then S is returned; otherwise matched in S = ∪i=0 G¨ardenfors [6], who originated the notion of popular the unmatched men of layer i are promoted to layer i+1, matchings, considered this problem in the domain of 2for each 0 ≤ i ≤ k − 2, and the next iteration begins. sided preference lists. Bir´o, Manlove, and Mittal [3] Let Mk be the matching returned by this algorithm. showed that the problem of computing a maximum For any matching M ′ , the set Mk ⊕M ′ is a collection cardinality matching here that minimized the number of alternating paths and alternating cycles with respect of blocking edges is NP-hard to approximate to within to Mk . Any path/cycle ρ where alternate edges in ρ n01−ǫ , for any ǫ > 0. When ties are allowed in preference belong to Mk is called an alternating path/cycle with lists here, it was shown by Bir´o, Irving, and Manlove [2] respect to Mk . We prove Theorem 1.4 in Section 3. that the problem of computing an arbitrary popular matching in a stable marriage instance is NP-hard. As Theorem 1.4. Let Mk be the matching computed by mentioned earlier, the first polynomial time algorithm the generalized algorithm on k layers, where k ≥ 2. For for computing a largest popular matching in a stable any matching M ′ in G, the following three properties marriage instance with strict preference lists was given hold: in [8] and its running time is O(mn0 ). (1) If ρ is an alternating cycle in Mk ⊕ M ′ , then φ(Mk ⊕ ρ, Mk ) ≤ φ(Mk , Mk ⊕ ρ).

1.3 Some Examples. We first show an example G = (A ∪ B, E) where the size of a largest popular matching (2) If ρ is an alternating path in Mk ⊕ M ′ such that at is 23 (the size of a maximum cardinality matching in G). least one endpoint of ρ is unmatched in Mk , then Let the set A be {a1 , a2 , a3 } and the set B be {b0 , b1 , b2 }. The edges and preferences are given in Figure 2. φ(Mk ⊕ ρ, Mk ) ≤ φ(Mk , Mk ⊕ ρ).

(3) If ρ is an alternating path in Mk ⊕ M ′ such that both the endpoints of ρ are matched in Mk , then φ(Mk ⊕ ρ, Mk ) ≤ (k − 1) · φ(Mk , Mk ⊕ ρ).

1 b0

2

1 a1

1

2 b1

2 1 a2

1 2 b2

1 a3

Figure 2: The preferences of the vertices are indicated on The above theorem implies that u(Mk ) ≤ k − 1. the edges: 1 is top choice while 2 is second choice. The (Thus M2 , the matching computed when k = 2, will be bold edges form the largest popular matching and the dashed a popular matching.) The k-layer partition obtained edges form the maximum cardinality matching.

126

Copyright © SIAM. Unauthorized reproduction of this article is prohibited.

In the above example, the largest popular matching is {(a1 , b1 ), (a2 , b2 )} and it has size 2 while the maximum cardinality matching is {(a1 , b0 ), (a2 , b1 ), (a3 , b2 )} of size 3. This example can be easily generalized to 6t vertices, for any integer t ≥ 1, by making t copies of the graph shown in Figure 2 with no edges between any of the copies, so that the largest popular matching has size 2t while the maximum cardinality matching has size 3t. An instance where u(M ∗ ) is high. We now show an example G = (A ∪ B, E) on 2n0 vertices, where |A| = |B| = n0 , such that a maximum cardinality matching M ∗ that is popular within the set M of maximum cardinality matchings has a high unpopularity factor in the set of all matchings in G. This is a generalization of the instance on 6 vertices given in Figure 2. Let A = {a1 , . . . , an0 } and B = {b0 , . . . , bn0 −1 } and for each 1 ≤ i ≤ n0 − 1, the preference list of ai is bi (top choice) followed by bi−1 (second choice). The vertex an0 has only one neighbor, which is bn0 −1 . The vertex b0 has only one neighbor, which is a1 . For each 1 ≤ i ≤ n0 − 1, the preference list of bi is ai (top choice) followed by ai+1 (second choice). There is only one maximum cardinality matching 0 −1 here, which is M ∗ = ∪ni=0 {(ai+1 , bi )}. Consider the matching M = {(ai , bi ), where 1 ≤ i ≤ n0 −1}. We have φ(M, M ∗ ) = 2n0 − 2 since all the 2n0 − 2 vertices ai , bi for i = 1, . . . , n0 − 1 prefer M to M ∗ . The two vertices b0 and an0 prefer M ∗ to M since they are unmatched in M but matched in M ∗ . So φ(M ∗ , M ) = 2. Thus ∆(M, M ∗ ) = n0 − 1, so u(M ∗ ) ≥ n0 − 1. 2

An algorithm for a largest popular matching

Recall that our input here is a bipartite graph G = (A ∪ B, E) where each vertex ranks its neighbors in a strict order of preference. For convenience, we will refer to vertices in A as men and the vertices in B as women. We assume without loss of generality that |A| ≤ |B|, so n0 = min(|A|, |B|) = |A|. The following algorithm, where the set of vertices gets partitioned into top and bottom, was outlined in Section 1. To begin with, all the vertices are in the bottom layer, i.e., A0 = A and B0 = B while A1 = B1 = ∅. In every iteration, we do the following: • Run the Gale-Shapley stable matching algorithm on the vertex set A1 ∪ B with the vertices in A1 proposing and the vertices in B disposing. Let S1 be the resulting matching. • Let B1 ⊆ B be the women who are matched in S1 . Let B0 = B \ B1 . Run the stable matching algorithm on A0 ∪ B0 now. That is, vertices in A0 can propose only to the vertices in B0 and these women dispose. Let S0 be the resulting matching.

127

• If all vertices of A0 are matched in S0 , then return S0 ∪S1 . Else delete all the unmatched vertices from A0 and add them to A1 . 2.1 An Efficient Implementation. Before we show the correctness of this algorithm, we will first show a simple linear time implementation of this algorithm. This involves calling a modified Gale-Shapley stable matching algorithm just once in an augmented graph ˜ 2 = (A˜2 ∪ B, E). ˜ The set of women in G ˜ 2 is the same G as the set B of women in G. The fact that the vertex set of G gets partitioned into two layers is implemented by ˜2. having two copies of every man ai ∈ A in the graph G 1 1 0 0 ˜ So A2 = {a1 , . . . , an0 , a1 , . . . , an0 }, where {a1 , . . . , an0 } is the set A of men in the given graph G. The preference list of each aℓi ∈ A˜2 , for ℓ = 0, 1, is the same as that of ai ∈ A in G. The superscript ℓ in aℓi refers to the layer number: ℓ = 0 denotes bottom layer while ℓ = 1 denotes top layer. To begin with, for all i, only a0i participates in the algorithm since the top layer is empty at the start of the algorithm. For any i, if a0i is rejected by all his neighbors, then a0i exits and a1i starts participating in the algorithm. The replacement of a0i by ai1 captures ai getting promoted from bottom to top. The fact that in every iteration the top layer men propose first to all women and the bottom layer men can only propose to those women who do not receive proposals from top layer men is captured by the women’s preference lists. ˜ 2 is as fol– The preference list of each woman b in G lows: if b’s preference list in G is hai1 , . . . , ait i, then ˜ 2 is ha1 , . . . , a1 , a0 , . . . , a0 i. b’s preference list in G it i1 it i1 ˜ 2 is 2 degG (b). Thus deg(b) in G – The top layer copies of all the neighbors of b in G (in the same order of preference as in G) are the most preferred degG (b) neighbors of b ˜2. in G – Then come the bottom layer copies of all the neighbors of b in the same order of preference. So if a woman b receives a proposal from a top layer neighbor, she will henceforth reject proposals from all bottom layer neighbors. In fact, we can say that in the Gale-Shapley stable matching algorithm, when a woman receives an offer, she immediately deletes edges to worse ranked neighbors since such offers will henceforth never be accepted by her. Thus as soon as a woman receives a proposal from a top layer neighbor, she deletes all edges incident to bottom layer neighbors, thus the bottom layer men can only propose to those women who do not receive proposals from top layer men.

Copyright © SIAM. Unauthorized reproduction of this article is prohibited.

Our algorithm is to construct the desired matching ˜ 2 = (A˜2 ∪ B, E) ˜ is given as Algorithm1. This in G algorithm is essentially the same as running the Gale˜ 2 , except for some modifications. Shapley algorithm in G In the Gale-Shapley algorithm, all the men in A˜2 should propose. However at the very beginning, we want only the bottom layer men to propose since the top layer is empty. So our initialization step initializes the queue Q of active men to the bottom layer men {a01 , . . . , a0n0 }.

˜ 2 = (A˜2 ∪ B, E); ˜ Output: M ˜. Algorithm 1 Input: G 1. Initialize the queue Q to {a01 , . . . , a0n0 }. 2. while Q is not empty do 3. delete the first element aℓ from Q. 4. if aℓ ’s list of neighbors is non-empty then 5. let b be the most preferred neighbor of aℓ now. ˜ (b) exists then add this man M ˜ (b) to Q. 6. if M ˜ (b) = aℓ . 7. now set M 8. delete all edges that b ranks worse than (aℓ , b). 9. else if ℓ = 0 then 10. add aℓ+1 to Q. {So a0i has been rejected by all his neighbors, hence a0i exits and a1i enters.} 11. end if 12. end while ˜. 13. Return M In the Gale-Shapley algorithm, every man who has not yet found a partner, will propose in decreasing order of preference till he is accepted by some neighbor or he gets rejected by all his neighbors. Any offer that a woman receives is always from a better neighbor than her current partner since she deletes edges to worse ranked neighbors upon receiving a proposal. So when a woman receives a proposal, if she is already matched, she rejects her current partner and this man is inserted into Q, since he has to find a new partner now. If a man gets rejected by all his neighbors, then he will be unmatched in the final matching output by the GaleShapley algorithm. In our algorithm the modification is that once a bottom layer man a0i has been rejected by all his neighbors, then a0i exits and a1i enters the picture. [Lines 9-10 of Algorithm 1 are new, they are not found in the Gale-Shapley algorithm.] Hence a1i is inserted into Q. When it is a1i ’s turn, he starts proposing from the top of his preference list. If a1i also gets rejected by all his neighbors, then it means that ai will remain unmatched in our final matching. Algorithm 1 returns ˜ in G ˜ 2 and this translates in a straightforward manner M ˜ (b) is a0 or a1 . to a matching M2 in G: (a, b) ∈ M2 iff M

128

˜2 Time taken to compute M2 . Building the graph G takes O(n + m) time. It is easy to see that the running ˜ 2 . The time of Algorithm 1 is linear in the size of G ˜ 2 is 2 Pn0 degG (ai ). Thus the number of edges in G i=1 running time of Algorithm 1 is O(n + m). So the time taken to compute M2 is O(n + m), which is O(m). 2.1.1 Correctness of Algorithm 1. We now show that the matching M2 is a popular matching of maximum size in G. The following definition partitions A into the set A0 of bottom layer men and the set A1 of top layer men, and similarly, B into the set B0 of bottom layer women and the set B1 of top layer women. Definition 2. Let A0 consist of those men ai ∈ A such ˜ (b) = a0 for some b ∈ B, and let A1 = A \ A0 . that M i Let B1 ⊆ B be the set of women matched in M2 to the men in A1 and let B0 = B \ B1 . Thus we have M2 ⊆ (A0 × B0 ) ∪ (A1 × B1 ). The following claim follows from the definitions of the sets A0 and B1 . Claim 1. All the men unmatched in M2 belong to A1 and all the women unmatched in M2 belong to B0 . The following definition will be useful in showing the properties satisfied by M2 . Definition 3. For any u ∈ A ∪ B and neighbors x and y of u, define u’s vote between x and y, denoted by voteu (x, y), as follows: it is 1 if u prefers x to y, it is −1 if u prefers y to x, else it is 0 (i.e., x = y). Label each e = (u, v) in E \ M2 by (αe , βe ), where αe = voteu (v, M2 (u)) and βe = votev (u, M2 (v)); in case x is unmatched in M2 , then votex (y, M2 (x)) = 1 for any neighbor y of x, since every vertex prefers being matched with any of its neighbors to being unmatched. Lemmas 2.1 and 2.2 show crucial properties of M2 . Lemma 2.1. Every (1, 1) edge has to be in A0 × B1 . Proof. During the entire course of Algorithm 1, no woman in B0 ever receives a proposal from a top layer neighbor, otherwise she would be matched to some ˜ . Thus the matching M2 restricted to the a1i in M vertex set A0 ∪ B0 is stable since these women receive proposals only from the bottom layer men and they dispose according to their preference lists in G. Also, the matching M2 restricted to the vertex set A1 ∪ B is stable. Hence M2 has no blocking edges in A1 ×(B1 ∪B0 ) or in A0 × B0 . It follows that every edge labeled (1, 1) has to be in A0 × B1 . Lemma 2.2. Every edge (a, b) ∈ A1 × B0 is a (−1, −1) edge.

Copyright © SIAM. Unauthorized reproduction of this article is prohibited.

Proof. Let (a, b) be an edge in A1 × B0 . We first claim that a must be matched in M2 . Otherwise, a1 would have proposed to b. However b ∈ B0 , which means that b never received a proposal from a top layer neighbor during the entire course of the algorithm, otherwise b would have accepted such a proposal. So a1 has to be ˜ to a woman that a ranks better than b. matched in M So votea (b, M2 (a)) = −1. The man a0 was rejected by all his neighbors in Algorithm 1, that is why he got promoted to the top layer. So at some point a0 must have been rejected by b. When b rejected a0 , b was matched to a man ˜ 2 . Also, ranked better than a0 in b’s preference list in G b never received a proposal from a top layer neighbor ˜ is (since b ∈ B0 ). Thus the final partner of b in M 0 0 a bottom layer man z whom b prefers to a , in other words, b ranks her partner M2 (b) = z better than a. So we have voteb (a, M2 (b)) = −1. This finishes the proof of the lemma.

Suppose y0 ∈ B1 , a similar argument holds: though there are edges (possibly labeled (1, 1)) between B1 and A0 , once an edge of B1 × A0 is traversed in ρ, the path ρ gets stuck in A0 ∪ B0 because every vertex in A0 is matched to a vertex in B0 and there are no edges between B0 and A1 in GM2 . So once ρ reaches a vertex xi ∈ A0 , thereafter all the vertices have to be in A0 ∪B0 . Thus we have shown that in both cases of (ii), there can be at most one edge labeled (1, 1) in ρ. This finishes the proof of the lemma. We will refer to an alternating path hy0 , x1 , y1 , . . .i in GM2 where y0 ∈ A1 ∪B0 as a type (i) alternating path and an alternating path hy0 , x1 , y1 , . . .i in GM2 where y0 ∈ A0 ∪ B1 as a type (ii) alternating path.

We now show Theorem 1.4 (from Section 1) for k = 2. For any ρ ∈ M2 ⊕M ′ , where M ′ is any matching in G, we need to evaluate φ(M2 ⊕ρ, M2 )−φ(M2 , M2 ⊕ρ). This P value is just u voteu (M ′ (u), M2 (u)) where the sum is the vertices u in ρ. Recall that each edge (u, v) Let GM2 denote the subgraph of G obtained by over all ′ of M in ρ is labeled (voteu (v, M2 (u)), votev (u, M2 (v))); deleting all edges that are labeled (−1, −1) from G. We we will now use Lemma 2.3 on ρ. now show Lemma 2.3 in the graph G . M2

Proof of Theorem 1.4 for k = 2. We now show Lemma 2.3. Let ρ = hy0 , x1 , y1 , x2 , y2 , . . .i be an alterthat the matching M2 satisfies properties (1)-(3) of nating path in GM2 , where (xi , yi ) ∈ M2 for i ≥ 1. Theorem 1.4. Let M ′ be any matching in G. In order (i) If y0 ∈ A1 ∪ B0 , then there is no edge labeled (1, 1) to compare M2 and M ′ with respect to popularity, we can assume that M ′ belongs to the subgraph GM2 . in ρ. This is because if (u, v) is an edge of M ′ that (ii) If y0 ∈ A0 ∪ B1 , then there can be at most one edge is labeled (−1, −1), then we can as well assume that labeled (1, 1) in ρ. M ′ leaves u and v unmatched, i.e., we can delete the ′ no difference Proof. We first show (i). Suppose y0 ∈ A1 . There are edge (u, v) ′ from M since this makes ′ to vote (M (u), M (u)) or vote (M (v), M u 2 v 2 (v)): both no edges in GM2 between A1 and B0 (by Lemma 2.2). these values were −1 to begin with and they both So y0 ’s neighbor in ρ, i.e., the vertex x1 , has to be in B1 . remain −1 after assuming that u and v are unmatched Since the matched partners of all vertices in B1 have to ′ φ(M2 , M ′ ) and be in A1 , M2 (x1 ) = y1 ∈ A1 . So it follows that xi ∈ B1 in M′ . So for the purpose of evaluating ′ and yi ∈ A1 for all i. Thus the entire path ρ ⊆ A1 × B1 . φ(M , M′2 ), we can assume that M is in GM2 . Hence As all the (1, 1) edges are in A × B , there is no edge M2 ⊕ M is in GM2 . 0

1

labeled (1, 1) in ρ. Suppose y0 ∈ B0 . Since there are no edges between B0 and A1 in GM2 , and because the matched partners of all vertices in A0 are in B0 , it follows that xi ∈ A0 and yi ∈ B0 for all i. Thus the entire path ρ ⊆ A0 × B0 . Hence there is no edge labeled (1, 1) in ρ. We now show (ii). Suppose y0 ∈ A0 . There are edges (some of them possibly labeled (1, 1)) between A0 and B1 . However once an edge of A0 × B1 is traversed in ρ, the path ρ gets stuck in A1 ∪ B1 . This is so by the same argument as in the earlier case. Once ρ reaches a vertex xi ∈ B1 , its matched partner yi ∈ A1 and thereafter all the vertices have to be in A1 ∪ B1 as there are no edges between A1 and B0 in GM2 and because the matched partners of all vertices in B1 are in A1 .

129

Property (1). Let ρ be an alternating cycle in M2 ⊕ M ′ . Since every edge of M2 is either in A0 × B0 or in A1 × B1 , there has to exist a vertex x ∈ A1 ∪ B0 in ρ. Thus ρ \ {(x, M2 (x))} is a type (i) alternating path. Lemma 2.3 tells us that there can be no (1, 1) edge in such an alternating path and since ρ is in GM2 , it follows that every edge of ρ is labeled either (1, −1) or (−1, 1). If the number of vertices in ρ is 2t, then we have t vertices in ρ (the −1 votes) who prefer M2 to M2 ⊕ ρ and t vertices in ρ (the 1 votes) who prefer M2 ⊕ ρ to M2 . Thus φ(M2 , M2 ⊕ ρ) = φ(M2 ⊕ ρ, M2 ) here. Property (2). This follows directly from Claim 1 and Lemma 2.3. Claim 1 states that every vertex unmatched in M2 has to be in A1 ∪ B0 . So any alternating path ρ with respect to M2 in GM2 that starts with

Copyright © SIAM. Unauthorized reproduction of this article is prohibited.

an unmatched vertex has to be a type (i) alternating path. There can be no (1, 1) edge in ρ by Lemma 2.3. So among the vertices of ρ, the number of −1 votes is at least the number of 1 votes, so φ(M2 , M2 ⊕ ρ) ≥ φ(M2 ⊕ ρ, M2 ). Property (3).This follows directly from Lemma 2.3. Let ρ be any alternating path with respect to M2 in GM2 such that both the endpoints of ρ are matched in M2 . So neither endpoint is matched in M ′ and both these vertices prefer M2 to M ′ . There can be at most one edge labeled (1, 1) in ρ by Lemma 2.3. Every other edge (say, there are t of them) is labeled either (1, −1) or (−1, 1). Thus among all the vertices of ρ, there are 2 + t who prefer M2 to M ′ whereas at most 2 + t prefer M ′ to M2 . Hence φ(M2 , M2 ⊕ ρ) ≥ φ(M2 ⊕ ρ, M2 ) here. For any matching M ′ in G, using the above result (Theorem 1.4 for k = 2) we have: φ(M2 , M ′ )

=

X

φ(M2 , M2 ⊕ ρ)

ρ∈M2 ⊕M ′



X

φ(M2 ⊕ ρ, M2 )

So all edges of M ′ in p1 (say, there are t of them) are only (1, −1) and (−1, 1) edges. Also, p1 has another endpoint u that is unmatched in M ′ (restricted to GM2 ) but is matched in M2 , so u prefers M2 to M ′ . So p1 has 2t + 1 vertices, where t + 1 of these prefer M2 to M ′ and the remaining t prefer M ′ to M2 , i.e., φ(M2 , M2 ⊕ p1 ) = φ(M2 ⊕ p1 , M2 ) + 1. • For pi ∈ {p2 , . . . , ps } (the other sub-paths that p gets split into in GM2 ), we have by Theorem 1.4 for k = 2, φ(M2 , M2 ⊕ pi ) ≥ φ(M2 ⊕ pi , M2 ). • We also have φ(M2 , M2 ⊕ ρ) ≥ φ(M2 ⊕ ρ, M2 ) for all ρ ∈ (M2 ⊕ M ′ ) \ {p} (by Theorem 1.4 for k = 2). Hence it follows that φ(M2 , M ′ ) > φ(M ′ , M2 ). Hence no matching of size larger than |M2 | can be popular, since M2 is more popular than such a matching. Thus M2 is a largest popular matching in G. The time taken to compute M2 is O(m). This completes the proof of Theorem 1.1 stated in Section 1. 3

ρ∈M2 ⊕M ′ φ(M ′ , M2 ).

The generalized algorithm

In this section we will generalize Algorithm 1. We = saw in Section 2 that Algorithm 1 computes a largest Thus M2 is popular. We now show that M2 is a popular matching. This algorithm on the example in largest popular matching. Recall that an augmenting Figure 2 computes the matching {(a1 , b1 ), (a2 , b2 )} and path with respect to M2 is an alternating path p where leaves b0 and a3 unmatched. Based on the matching ˜ = {(a1 , b2 ), (a0 , b1 )} computed by Algorithm 1, A M both the endpoints of p are unmatched in M2 . 2 1 gets partitioned into A0 = {a1 } (the set of bottom layer Lemma 2.4. There is no augmenting path with respect men) and A1 = {a2 , a3 } (the set of top layer men) while to M2 in GM2 . B gets partitioned into B1 = {b2 } and B0 = {b1 , b0 }. Suppose we want a larger matching in this graph Proof. Let p = hb0 , a1 , b1 . . . , bk , ak+1 i be an augment- at the cost of suffering some small unpopularity factor. ing path wrt M2 in GM2 . It follows that b0 ∈ B0 and Then we could further promote the unmatched a1 into 3 ak+1 ∈ A1 by Claim 1. Since M2 uses only edges of an even higher layer (call it layer 2) so that it becomes (A0 × B0 ) ∪ (A1 × B1 ), p has to contain an edge between a2 and make it propose to b . Let the preference list of 2 3 a vertex bj−1 ∈ B0 and a vertex aj ∈ A1 . However we any woman have her layer 2 neighbors at the very top, know there is no such edge in GM2 (by Lemma 2.2). followed by her layer 1 neighbors, and then the layer 0 Thus there exists no augmenting path wrt M2 in GM2 . neighbors; within each layer, the ordering is as per her list in G. So when b2 receives a proposal Lemma 2.5. If M ′ is a matching in G such that |M ′ | > preference 2 ′ ′ from a , she accepts this proposal. So a12 , who is now 3 |M2 |, then φ(M2 , M ) > φ(M , M2 ). rejected by b2 , proposes to b1 who accepts him. So a01 , ′ ′ Proof. Let M be a matching in G such that |M | > who is now rejected by b1 , proposes to b0 who accepts |M2 |. Then there is an augmenting path p ∈ M2 ⊕ M ′ him. Thus using 3 layers gives us a larger matching with respect to M2 in G. In order to evaluate φ(M2 , M ′ ) {(a3 , b2 ), (a2 , b1 ), (a1 , b0 )}. It can be shown that the and φ(M ′ , M2 ), recall that we can restrict M ′ to GM2 . unpopularity factor of this matching is 2. Since there is no augmenting path with respect to M2 Just as Algorithm 1 was an efficient implementain GM2 (by Lemma 2.4), the augmenting path p in G tion of the idea of partitioning the vertex set into two breaks into sub-paths p1 , p2 , . . . , ps in GM2 , where p1 layers: bottom and top, we now show an efficient impleand ps have one endpoint each unmatched in M2 . This mentation of the generalized algorithm that partitions endpoint has to be in A1 ∪ B0 (by Claim 1), thus there the vertex set into k layers, where k is any integer ≥ 2. is no (1, 1) edge in p1 and in ps by Lemma 2.3. Let the k layers be layer 0, layer 1, . . . , layer k − 1,

130

Copyright © SIAM. Unauthorized reproduction of this article is prohibited.

where layer 0 is the bottommost layer and layer k − 1 is the topmost layer. We want the men in layer k − 1 to get the most preferential treatment and then the men in layer k − 2, and so on. To implement this idea efficiently, we will work with the following augmented ˜ k = (A˜k ∪ B, E) where the set A˜k of men is graph G k−1 {aℓ1 , . . . , aℓn0 } (recall that {a1 , . . . , an0 } is the set A ∪ℓ=0 ˜ k is the same as of men in G). The set of women in G the set B of women in G. The preference list of each aℓi ∈ A˜k , for ℓ = 0, . . . , k − 1, is the same as that of ai ∈ A in G. The ˜ k is as follows: if b’s preference list of each woman b in G ˜k preference list in G is hai1 , . . . , ait i, then deg(b) in G k−1 ℓ ℓ is k degG (b) and b’s neighbors are ∪ℓ=0 {ai1 , . . . , ait }.

3.1 Correctness. In this section we will show Theorems 1.2 and 1.3 stated in Section 1. It is straightforward to see that the time taken to construct Mk is ˜ k |), which is O(km). We will first lower bound O(|G the size of Mk and then upper bound its unpopularity factor. Definition 4 partitions A and B into layers. Definition 4. For ℓ ∈ {0, . . . , k − 2}, let Aℓ ⊆ A ˜ (b) = aℓ for some consist of those men ai such that M i b ∈ B, and let Ak−1 = A \ (A0 ∪ · · · ∪ Ak−2 ). For ℓ ∈ {1, . . . , k−1}, let Bℓ ⊆ B be the set of women matched in Mk to the men in Aℓ and let B0 = B \ (B1 ∪ · · · ∪ Bk−1 ). k−1 Thus we have Mk ⊆ ∪ℓ=0 (Aℓ × Bℓ ). Claim 2 is straightforward from Definition 4.

˜ k , we have aℓ1 preferred • In b’s preference list in G i Claim 2. All the unmatched men belong to Ak−1 and ℓ2 to aj iff either ℓ1 > ℓ2 , or ℓ1 = ℓ2 and b ranks ai all the unmatched women belong to B0 . better than aj in her preference list in G. Lemma 3.1 shows an important property of the • Thus for any b ∈ B, layer k − 1 neighbors are the partition of A∪B into the layers as given by Definition 4. most preferred, then come the layer k−2 neighbors, and so on and at the bottom come the layer 0 Lemma 3.1. For every 2 ≤ ℓ ≤ k − 1, there is no edge ˜k. neighbors in b’s preference list in G between any man in Aℓ and any woman in ∪ℓ−2 t=0 Bt . We now present Algorithm 2, whose code is the same as that of Algorithm 1, except for line 9, where “if ℓ = 0” gets replaced by “if ℓ < k − 1” here. ˜ k = (A˜k ∪ B, E); ˜ Output: M ˜ Algorithm 2 Input: G 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13.

Initialize the queue Q to {a01 , . . . , a0n0 }. while Q is not empty do delete the first element aℓ from Q. if aℓ ’s list of neighbors is non-empty then let b be the most preferred neighbor of aℓ now. ˜ (b) exists then add this man to Q. if M ˜ (b) = aℓ . now set M delete all edges that b ranks worse than (aℓ , b). else if ℓ < k − 1 then add aℓ+1 to Q. end if end while ˜. Return M aℓi

aℓi

For any where 0 ≤ ℓ ≤ k − 2, if gets rejected by all his neighbors, then aℓi has to get promoted to the next higher layer: this is achieved in our algorithm by the exit of aℓi and the arrival of aℓ+1 . The vertex aℓ+1 i i is inserted into Q and starts proposing from the top of his preference list when he gets deleted from Q. As in ˜ which translates Algorithm 1, Algorithm 2 returns M in a straightforward manner to a matching Mk in G: ˜ (b) = aℓ for some ℓ ∈ {0, . . . , k − 1}. (a, b) ∈ Mk iff M

131

Proof. Consider any a ∈ Aℓ for ℓ ≥ 2. The fact that a ∈ Aℓ implies that aℓ−1 was rejected by all his neighbors in B. Consider any b ∈ ∪j≤ℓ−2 Bj . If there was an edge (a, b) in G, then aℓ−1 would have proposed to b. However we know that b could not have received any proposal from a man z t with t ≥ ℓ − 1, otherwise b would have accepted such a proposal since a neighbor in layers ≥ ℓ − 1 is ranked better than any neighbor in layers ≤ ℓ−2, and so b would not be in ∪j≤ℓ−2 Bj . Thus if (a, b) was an edge in G, then aℓ−1 would have proposed to b and b would have accepted aℓ−1 , contradicting that aℓ−1 was rejected by all his neighbors. Hence there is no edge (a, b) in G, where a ∈ Aℓ and b ∈ ∪ℓ−2 t=0 Bt . Label every edge e = (u, v) ∈ E \ Mk by (αe , βe ), where αe = voteu (v, Mk (u)) and βe = votev (u, Mk (v)). Lemma 3.2. For each 1 ≤ ℓ ≤ k − 1, every edge (a, b) ∈ Aℓ × Bℓ−1 is a (−1, −1) edge. The proof of Lemma 3.2 is identical to that of Lemma 2.2. Lemma 3.3 allows us to lower bound |Mk |. Lemma 3.3. Any augmenting path with respect to Mk in G has length at least 2k + 1. Proof. Let p = hb0 , a1 , b1 . . . , bt , at+1 i be an augmenting path with respect to Mk in G. We know from Claim 2 that b0 ∈ B0 and at+1 ∈ Ak−1 , we also know that Mk k−1 (Aℓ × Bℓ ). In the first place, uses only edges of ∪ℓ=0 there is no edge in G between an unmatched b0 ∈ B0

Copyright © SIAM. Unauthorized reproduction of this article is prohibited.

and any a1 ∈ A1 , since such an edge would not be a (−1, −1) edge (because b0 prefers being matched to a1 to being unmatched in Mk ), contradicting Lemma 3.2. Also, there is no edge between Bℓ and ∪t≥ℓ+2 At (by Lemma 3.1). At the other end, there is no edge between an unmatched vertex in Ak−1 and any vertex bk−2 in Bk−2 , as bk−2 ∈ Bk−2 would accept such a proposal and not be in Bk−2 then. So the first edge of p has to be from B0 × A0 and the last edge has to be from Bk−1 × Ak−1 . Thus the shortest possible augmenting path has the following structure between the sets in our partition: B0 -A0 -B0 A1 -B1 -A2 · · · Ak−2 -Bk−2 -Ak−1 -Bk−1 -Ak−1 , where every Ai -Bi edge here is an edge of Mk . Thus there have to be at least k edges of Mk in p. So |p| ≥ 2k + 1.

no (1, 1) edges in Aℓ × Bℓ . So while the xi ’s are in Bℓ (which forces the yi ’s to be in Aℓ ), we do not encounter any (1, 1) edge in ρ. Hence it is necessary to traverse an edge in ρ between some yj ∈ Aℓ and xj+1 ∈ Bℓ′ , for some ℓ′ > ℓ so that a (1, 1) edge is encountered (by Lemma 3.4). For any ℓ and ℓ′ > ℓ, once we traverse an edge between Aℓ and Bℓ′ , the rest of the path ρ gets stuck in layers ≥ ℓ′ . Once the path jumps to a higher layer, since there is no way it can come back to a lower layer, it follows that we are allowed at most h − ℓ jumps in layer numbers from y0 ∈ Aℓ to xt ∈ Bh . Thus we can traverse at most h − ℓ edges labeled (1, 1) in ρ (by Lemma 3.4). This settles the base case. We assume by induction hypothesis that the claim is true when the number of (−1, −1) edges in any alternating path is at most i − 1. Let ρ have i ≥ 1 k |M ∗ |, where M ∗ is a edges labeled (−1, −1) and let (yj−1 , xj ) be one of these Corollary 3.1. |Mk | ≥ k+1 maximum cardinality matching in G. (−1, −1) edges in ρ. Let yj−1 ∈ Ar and xj ∈ Bs . Deleting the sub-path hxj−1 , yj−1 , xj , yj i (this consists Proof. Every path in Mk ⊕ M ∗ that is augmenting with of one (−1, −1) edge and two edges of M ) from ρ, we k respect to Mk , has length at least 2k+1 (by Lemma 3.3). get two alternating sub-paths ρ and ρ , where ρ = 1 2 1 So every such path has t edges of Mk and t + 1 edges of hy , x , . . . , x i and ρ = hy , x , . . . , x i. Since the 0 1 j−1 2 j j+1 t k M ∗ , for some t ≥ k. Hence |Mk | ≥ k+1 |M ∗ |. number of (−1, −1) edges in ρ1 and in ρ2 is at most i − 1, by applying the induction hypothesis on ρ1 and This finishes the lower bound on the size of Mk . We on ρ2 , it follows that the number of (1, 1) edges in ρ is now upper bound its unpopularity factor. at most the number of (−1, −1) edges in ρ1 +(r − ℓ)+ k−2 Lemma 3.4. Every (1, 1) edge has to be in ∪ℓ=0 (Aℓ × the number of (−1, −1) edges in ρ2 + (h − s), where the (r − ℓ) term comes from ρ1 and the (h − s) term comes ∪j>ℓ Bj ). from ρ2 . Proof. There is no blocking edge in Aℓ × ∪j≤ℓ Bj for The number of (−1, −1) edges in ρ1 + the number any ℓ, since Mk restricted to edges in Aℓ × ∪j≤ℓ Bj is of (−1, −1) edges in ρ2 is one less than the number obtained by running Gale-Shapley algorithm on these of (−1, −1) edges in ρ. Thus the number of (1, 1) vertices, with the men in Aℓ proposing and the women edges in ρ is at most the number of (−1, −1) edges in in ∪j≤ℓ Bj disposing. Thus every blocking edge to Mk ρ + (r − ℓ) + (h − s) − 1. Since there is an edge between k−2 has to be ∪ℓ=0 (Aℓ × ∪j>ℓ Bj ). yj−1 ∈ Ar and xj ∈ Bs , it follows from Lemma 3.1 that s ≥ r − 1. Hence h − ℓ + r − s − 1 ≤ h − ℓ. Thus the Theorem 3.1. Let ρ = hy0 , x1 , y1 , . . . , xt−1 , yt−1 , xt i claim holds when the number of (−1, −1) edges in ρ is be an alternating path with respect to Mk in G, where i. This completes the proof of Theorem 3.1. (xi , yi ) ∈ Mk for i ≥ 1. Then the number of edges labeled (1, 1) in ρ is at most the number of edges labeled Proof of Theorem 1.4. We now show that Mk (−1, −1) in ρ + (h − ℓ), where y0 ∈ Aℓ and xt ∈ Bh . satisfies properties (1)-(3) of Theorem 1.4 stated in ′ Proof. Let ρ = hy0 , x1 , . . . , yt−1 , xt i be an alternating Section 1. Let M be any matching in G. path where each (xi , yi ) ∈ Mk . Suppose y0 ∈ Aℓ and Property (1). Let ρ ∈ Mk ⊕ M ′ be an alternating cycle. k−1 xt ∈ Bh . The claim is that the number of (1, 1) edges Every edge of Mk is in ∪ℓ=0 (Aℓ × Bℓ ). Let (a, b) be an in ρ is at most the number of (−1, −1) edges in ρ + edge in Mk ∩ ρ. So ρ \ {(a, b)} is an alternating path (h−ℓ). We prove this claim by induction on the number ha, . . . , bi where a ∈ At and b ∈ Bt , for some t. Hence of (−1, −1) edges in ρ. it follows from Theorem 3.1 that the number of (1, 1) Suppose there are no (−1, −1) edges in ρ. Then edges in ρ is at most the number of (−1, −1) edges in we will show that the number of (1, 1) edges in ρ is at ρ. Each of the other edges of ρ \ Mk is labeled either most h − ℓ. We know from Lemma 3.1 that there are (−1, 1) or (1, −1). Thus among the vertices of ρ, the no edges between Aℓ and ∪j