# Faster and Simpler Approximation of Stable Matchings

## Abstract

**:**

## 1. Introduction

**Stable Matchings**, known also in the literature as the

**Stable Marriage**problem. The problem is defined as follows. We are given two sets W and U of women and men. Each woman w of W has a preference list ${L}_{w}$ of a subset of men, and similarly, each man m of U has a preference list ${L}_{m}$ of a subset of women. The preference lists are linearly ordered lists of

**ties**, which are subsets of men (or respectively, women), who are equally good for a given woman (respectively, man). Ties are disjoint and can contain also one person, appropriately a man or a woman. Thus if m and ${m}^{\prime}$ are on list ${L}_{w}$ of woman w, then either (1) w prefers m to ${m}^{\prime}$, or in other words, m is better for w than ${m}^{\prime}$; or (2) m and ${m}^{\prime}$ are in a tie on ${L}_{w},$ and then we say that w is indifferent between m and ${m}^{\prime}$ or that m and ${m}^{\prime}$ are equally good for her; or (3) w prefers ${m}^{\prime}$ to m. Man m and woman w are said to be

**mutually acceptable**to each other if they belong to each other’s preference lists. The most preferred person(s) is (are) at the top of the preference lists. A

**matching**is a set of pairs $(m,w)$ such that $m\in U,w\in W$ and m and w are mutually acceptable, and each man/woman belongs to at most one pair. If $(m,w)$ belongs to a certain matching M, then we write $M\left(m\right)=w$, which means that in M woman w is a partner of m, and analogously that $M\left(w\right)=m$. If man m (or woman w) is not contained in any pair of a matching M, then we say that m (or w) is

**unmatched**or

**free**in M. A matching M is called

**stable**if it does not admit a

**blocking pair**. A pair $(m,w)$ is blocking for M if (1) m and w are mutually acceptable; (2) m is unmatched or prefers w to $M\left(m\right)$; and (3) w is unmatched or prefers m to $M\left(w\right)$. Each instance of the problem can be represented by a bipartite graph $G=(U\cup W,E)$ with vertices of U representing men, vertices of W representing women and edges E connecting all mutually acceptable pairs of men and women. The problem we are interested in is that of finding a stable matching that has the largest cardinality. The version in which there are no ties in the preference lists of men and women has been long known and an algorithm by Gale and Shapley [3] solves it exactly in $O\left(m\right)$ time, where m denotes the number of edges in the underlying graph. In the version without ties a stable matching always exists, and every stable matching has the same cardinality. If we allow ties, as in the problem we consider in this paper, then a stable matching also always exists and can be found via the Gale-Shapley algorithm by breaking ties arbitrarily. However, the sizes of stable matchings can vary considerably, and the problem of finding a stable matching of maximum cardinality is $NP$-hard, which was shown by Manlove et al. in [14]. Therefore it is desirable to devise an approximation algorithm for the problem.

**Previous and related results**Previous approximation algorithms were presented in [7,8,9,11,14]. Currently the best approximation algorithm is by McDermid [15] and achieves the approximation guarantee $\frac{3}{2}$. Its running time is $O\left({n}^{3/2}m\right)$, where n denotes the number of vertices and m the number of edges. Inapproximabilty results were shown in [4,5,17]. For a variant of the Stable Matchings problem, in which ties are allowed on one side only, an approximation algorithm achieving the ratio $\frac{25}{17}$ has been given in [10]. A slightly different linear time $\frac{3}{2}$-approximation algorithm based on an earlier version of this paper was given by Király in [12]. The conference version of this paper appeared also in the proceedings of WAOA’11 (Workshop on Approximation and Online Algorithms) [16].

**Our results**While constructing approximation algorithms, the goal is not only to achieve a good approximation guarantee but also good running time. We give a 3/2-approximation algorithm that runs in $O\left(m\right)$ time and additionally is significantly simpler than that of McDermid. In devising the algorithm we were led by the observation that it suffices to find a stable matching that will not create a dangerous path, which is defined later. We also give the extension of the algorithm for computing stable many-to-many matchings, which runs in $O(mlogc)$ time, where c denotes the minimum of the maximal capacities in each side of the bipartition. In particular, it means that we give an $O\left(m\right)$-time algorithm for the Hospitals-Residents problem, improving on an $O\left({d}^{5/2}{n}^{3/2}m\right)$ time algorithm given by McDermid, where d denotes the maximal capacity of a hospital. McDermid’s algorithm follows from the reduction of the Hospitals-Residents problem to the Stable Matchings problem by "cloning" hospitals. The approach by cloning does not work if the vertices on both sides of the bipartition are allowed to have capacities larger than 1. Since these problems have many practical applications (see [1,2,6], for example), we believe our algorithms will be of help.

## 2. Algorithm

**alternating (w.r.t. M)**if its edges alternate between M-edges and edges of E∖M. It is well known from matching theory (see [13] for example) that $M\oplus {M}^{\prime}$ disintegrates into a set of alternating paths and alternating cycles. (For two sets $X,Y$, the set $X\oplus Y$ denotes $(X$∖Y) ∪ (Y∖$X)$.) Let S denote a set of maximal alternating paths and cycles of $M\oplus {M}_{opt}$. Consider any alternating cycle C of S or any alternating path P of even length of S. Then both C and P contain the same number of M-edges and ${M}_{opt}$-edges. Consider an alternating path P of length $2k+1$ of S. Then either$\frac{|{M}_{opt}\cap P|}{|M\cap P|}=\frac{k+1}{k}$ or $\frac{|M\cap P|}{|{M}_{opt}\cap P|}=\frac{k+1}{k}$. Therefore, if M is stable and S does not contain a path of length 3 with the middle edge being an M-edge, then $|{M}_{opt}|\le \frac{3}{2}\left|M\right|$ and M is a $\frac{3}{2}$-approximation of ${M}_{opt}$. To achieve a $\frac{3}{2}$-approximation, we will eliminate such potential paths of length 3 of $M\oplus {M}_{opt}$.

**dangerous path w.r.t. a matching M**to be an alternating path $P=(w,{m}_{1},{w}_{1},m)$ such that w and m are unmatched in M (which means that $({m}_{1},{w}_{1})$ is in M and $(w,{m}_{1}),({w}_{1},m)$ do not belong to M) and $({m}_{1},{w}_{1})$ is not a blocking pair for the matching $N=\{(w,{m}_{1}),({w}_{1},m)\}$. We need to concern ourselves only with dangerous paths w.r.t. a matching M that can be extended to a stable matching, i.e., M is such that there exists a stable matching ${M}^{\prime}$ with $M\subseteq {M}^{\prime}$. Therefore, if $P=(w,{m}_{1},{w}_{1},m)$ is a dangerous path w.r.t. M, then w and ${m}_{1}$ do not form a blocking pair for M, which means that ${w}_{1}$ is at least as good for ${m}_{1}$ as w, and similarly, ${w}_{1}$ and m do not form a blocking pair for M, hence ${m}_{1}$ is at least as good for ${w}_{1}$ as m. Since $({m}_{1},{w}_{1})$ is not a blocking pair for the matching $N=\{(w,{m}_{1}),({w}_{1},m)\}$, either ${m}_{1}$ is indifferent between w and ${w}_{1}$ and then we say that P is a

**masculine dangerous path**, or ${w}_{1}$ is indifferent between m and ${m}_{1}$ and then we say that P is a

**feminine dangerous path**. A path P can of course be both a masculine and a feminine dangerous path.

- If man m is matched to woman w and there is at least one free woman ${w}_{1}$ such that w and ${w}_{1}$ are equally good for m, then we say that ${w}_{1}$ is a
**satellite**of m and m is**satellitic**. - If woman w is matched to a satellitic man m, then we say that w is
**co-satellitic**. - If $e=(m,w)$ is such that w is free and there is at least one free woman ${w}_{1}\ne w$ such that w and ${w}_{1}$ are equally good for m, then e is called
**special**, and consequently, $(m,{w}_{1})$ is also called special. - If man m has at least one free woman incident with him, then he is said to be
**subsatellitic**. - Woman w matched to a subsatellitic man m and not co-satellitic is said to be
**co-subsatellitic w.r.t. ${m}^{\prime}$**if m and ${m}^{\prime}$ are equally good for her.

**Figure 1.**The description of a dangerous path and its two types: a feminine dangerous path and a masculine dangerous path.

#### 2.1. Description of Algorithm GS Modified

**Algorithm GS Modified**

**while**there exists a free man m with a nonempty list ${L}_{m}$ or a nonempty list ${L}_{m}^{\prime}$

**if**${L}_{m}\ne \varnothing $,

**then**

**if**$(m,w)$ is not special,

**then**remove w from ${L}_{m}$

**if**w is free,

**then**$M\leftarrow M\cup (m,w)$

**else**

**if**w is co-satellitic,

**then**

**if**$(M\left(w\right),{w}^{\prime})$ is not special,

**then**remove ${w}^{\prime}$ from ${L}_{M\left(w\right)}$

**else**

**if**w prefers m to $M\left(w\right)$,

**then**$M\leftarrow M\cup (m,w)$∖$(w,M(w\left)\right)$

**else**

**if**w is co-subsatellitic w.r.t. m,

**then**add w to the end of list ${L}_{m}^{\prime}$

**else**

**if**w is co-subsatellitic w.r.t. m,

**then**$M\leftarrow M\cup (m,w)$∖$(w,M(w\left)\right)$

## 3. Correctness of Algorithm GS Modified

**Lemma 1.**

- If woman w becomes matched, she will stay matched.
- Woman w can become co-satellitic only the first time someone, say m, proposes to her and only if at the time of the proposal edge $(m,w)$ is special. If a co-satellitic woman w receives a proposal, she always accepts it and is no longer co-satellitic.
- If woman w is matched to man m and is not co-satellitic, she can accept man ${m}^{\prime}$ only if ${m}^{\prime}$ is at least as good for her as m. Moreover, if ${m}^{\prime}$ is better for her than m, she always accepts him. If ${m}^{\prime}$ is equally good for her as m, then she accepts him only if she is co-subsatellitic w.r.t. ${m}^{\prime}$ and ${m}^{\prime}$ proposes from ${L}_{{m}^{\prime}}^{\prime}$.
- If woman w matched to man m is not co-satellitic and changes m for ${m}^{\prime}$, who is equally good for her as m, then m is subsatellitic and ${m}^{\prime}$ is not.

**Proof.**Statements 1 and 3 follow directly from the description of Algorithm GS Modified.

**Lemma 2.**Let M denote a matching computed by Algorithm GS Modified. Then the underlying graph does not contain blocking pairs and dangerous paths w.r.t. M.

**Proof.**Suppose that $(m,w)$ is a blocking pair. Man m is either free or $M\left(m\right)$ is worse for him than w. It means that at some point m proposed to w from ${L}_{m}$ when edge $(m,w)$ was not special. (Clearly, at some point m proposed to w from ${L}_{m}$. Assume that at that point edge $(m,w)$ was special. Then w was free and accepted m. However, m got rejected later and therefore proposed to w from ${L}_{m}$ again, when edge $(m,w)$ was no longer special.) If w rejected him then, then by claim 2 of Lemma 1, w was not co-satellitic and, by claim 3 of Lemma 1, was matched to someone at least as good for her as m and thus would have stayed matched to someone as good for her as m. If w accepted m, then after getting matched to m she was not co-satellitic, and by claim 3 of Lemma 1, would have stayed matched to someone at least as good for her as m. Either way we get a contradiction.

**Theorem 1.**Algorithm GS Modified computes a stable matching M which is a $\frac{3}{2}$- approximation of the optimal solution. Algorithm GS Modified runs in $O\left(m\right)$ time.

**Proof.**By Lemma 2, matching M computed by Algorithm GS Modified is stable and does not contain dangerous paths. Therefore M is a $\frac{3}{2}$-approximation of the optimal solution.

## 4. Extension to Bipartite Stable b-Matchings

**unsaturated**: agent v is unsaturated in a b-matching M if $de{g}_{M}\left(v\right)<b\left(v\right),$ and if $de{g}_{M}\left(v\right)=b\left(v\right)$, then we will say that v is

**saturated**. For any agent v we will denote the set $\{w\in U\cup W$:$(v,w)\in M\}$ by $M\left(v\right)$. A pair $(u,w)$ is

**blocking**for a b-matching M if (1) u and w are mutually acceptable; (2) u is unsaturated or prefers w to one of the W-agents of $M\left(u\right)$; and (3) w is unsaturated or prefers u to one of the U-agents of $M\left(w\right)$. A b-matching M is said to be stable if it does not admit a blocking pair. As previously, we are interested in finding a stable b-matching of largest size. Let us also note that if for each u in U we have $b\left(u\right)=1$, then the problem is known under the name Hospitals-Residents problem or one-to-many stable matching problem.

**alternating path**P

**w.r.t.**a b-matching M is defined as any sequence of edges $({v}_{1},{v}_{2}),({v}_{2},{v}_{3}),\dots ,({v}_{k-1},{v}_{k})$ such that the edges alternate between M-edges and edges of E∖M, and an

**alternating cycle**C

**w.r.t. M**is defined as an alternating path (w.r.t. M) that ends and begins with the same vertex, i.e., the sequence of edges has the form $({v}_{1},{v}_{2}),({v}_{2},{v}_{3}),\dots ,({v}_{k},{v}_{1})$. As before, for any two b-matchings M and ${M}^{\prime}$, the symmetric difference $M\oplus {M}^{\prime}$ can be partitioned into maximal alternating paths and cycles (i.e., no two alternating paths from the partition can be combined to form one alternating path). A given stable b-matching M might not be a 3/2-approximation of ${M}_{opt}$, where ${M}_{opt}$ denotes a stable b-matching of maximum size, only if the underlying graph contains a dangerous path defined as follows. If M is a stable b-matching, then a path $P=(w,{u}_{1},{w}_{1},u)$ is called

**dangerous with respect to M**if u and ${u}_{1}$ are U-agents, w and ${w}_{1}$ are W-agents, $({u}_{1},{w}_{1})$ is in M, $(w,{u}_{1}),({w}_{1},u)$ are not in M, w and u are unsaturated in M, ${u}_{1}$ and ${w}_{1}$ are saturated in M, and $({u}_{1},{w}_{1})$ is not a blocking pair for the b-matching ${M}^{\prime}=(M\setminus ({u}_{1},{w}_{1}))\cup \{(w,{u}_{1}),({w}_{1},u)\}$. Since $(w,{u}_{1})$ is not blocking for M, w is not better for ${u}_{1}$ than any of the W-agents currently belonging to $M\left({u}_{1}\right)$, and analogously, u is not better for ${w}_{1}$ than any of the U-agents currently belonging to $M\left({w}_{1}\right)$. Thus if P is dangerous, then either w and ${w}_{1}$ are equally good for ${u}_{1}$ and then P is called a

**masculine dangerous path**, or u and ${u}_{1}$ are equally good for ${w}_{1}$ and then P is called a

**feminine dangerous path**.

- If a U-agent u is in $M\left(w\right)$, and there is at least one unsaturated W-agent ${w}_{1}\notin M\left(u\right)$ different from w such that w and ${w}_{1}$ are equally good for u, then we say that ${w}_{1}$ is a
**satellite of u w.r.t. w**and u is**satellitic w.r.t. w**. - W-agent w belonging to $M\left(u\right)$ such that u is satellitic w.r.t. w is said to be
**co-satellitic**. - If $e=(u,w)$ is such that w is unsaturated and there is at least one unsaturated W-agent ${w}_{1}\ne w$ such that w and ${w}_{1}$ are equally good for u, then e is called
**special**, and consequently, $(u,{w}_{1})$ is also called special. - If a U-agent u has at least one unsaturated W-agent $w\notin M\left(u\right)$ incident with him, then he iscalled
**subsatellitic**. - A saturated and not co-satellitic W-agent $w\in M\left(u\right)$ such that u is subsatellitic is said to be
**co-subsatellitic w.r.t. ${u}^{\prime}$**if ${u}^{\prime}\notin M\left(w\right)$ and u and ${u}^{\prime}$ are equally good for her. - By a
**worst U-agent belonging to $M\left(w\right)$**we will mean any U-agent $u\in M\left(w\right)$ such that there is no other U-agent ${u}^{\prime}\in M\left(w\right)$ who is worse for w than u.

**Algorithm ASBM**(short for Approximate Stable b-Matching)

**while**there exists an unsaturated U-agent u with a nonempty list ${L}_{u}$ or a nonempty list ${L}_{u}^{\prime}$

**if**${L}_{u}\ne \varnothing $,

**then**

**if**$(u,w)$ is not special,

**then**remove w from ${L}_{u}$

**if**w is unsaturated,

**then**$M\leftarrow M\cup (u,w)$

**else**

**if**w is co-satellitic,

**then**

**if**$({u}^{\prime},{w}^{\prime})$ is not special,

**then**remove ${w}^{\prime}$ from ${L}_{{u}^{\prime}}$

**else**

**if**w prefers u to a worst U-agent in $M\left(w\right)$,

**then**

**if**w is co-subsatellitic w.r.t. ${u}^{\prime}$,

**then**add w to the end of list ${L}_{{u}^{\prime}}^{\prime}$

**else**

**if**w is co-subsatellitic w.r.t. u,

**then**add w to the end of list ${L}_{u}^{\prime}$.

**else**

**if**w is co-subsatellitic w.r.t. u,

**then**

**if**w is co-subsatellitic w.r.t. ${u}^{\prime}$,

**then**add w to the end of ${L}_{{u}^{\prime}}^{\prime}$

## 5. Correctness of Algorithm ASBM

**Lemma 3.**

- If a W-agent becomes saturated, she will stay saturated.
- A co-satellitic W-agent w accepts every proposal. Once a saturated W-agent is not co-satellitic, she cannot become co-satellitic later.
- A W-agent $w\in M\left(u\right)$ can reject u only if w is saturated and a) u is satellitic w.r.t. w (w is co-satellitic), or b) w is not co-satellitic, u is one of the worst U-agents belonging to $M\left(w\right)$, and w receives a proposal from ${u}^{\prime}$ who is better for w than u, or c) w is not co-satellitic and u is one of the worst U-agents belonging to $M\left(w\right)$, u is subsatellitic, and w is co-subsatellitic w.r.t. ${u}^{\prime}$ who proposes from ${L}_{{u}^{\prime}}^{\prime}$
- A saturated W-agent w who is not co-satellitic can accept a U-agent ${u}^{\prime}$ only if ${u}^{\prime}$ is at least as good for w as a worst U-agent $u\in M\left(w\right)$; moreover if ${u}^{\prime}$ is equally good for w as u, then w accepts ${u}^{\prime}$ only if w is co-subsatellitic w.r.t. ${u}^{\prime}$ and ${u}^{\prime}$ proposes from ${L}_{{u}^{\prime}}^{\prime}$.

**Theorem 2.**Let M denote a b-matching computed by Algorithm ASBM. Then M is a $3/2$-approximation of an optimal stable b-matching.

**Proof.**We will show that the underlying graph does not contain blocking pairs and dangerous paths with respect to M. The non-existence of a dangerous path for the stable matching found guarantees the approximation ratio $3/2$.

## 6. Data Structures and Running Time

- finding the maximum element (takes $O\left(1\right)$ time)
- deleting a given element (takes $O(logn)$ time, where n denotes the number of elements in apriority queue)
- inserting a given element (takes $O(logn)$ time)
- finding an element having a certain priority value (takes $O(logn)$ time).

**Theorem 3.**The running time of Algorithm ASBM is $O(mmax\{1,logc\left\}\right)$, where $c=min\left\{max\right\{b\left(v\right):v\in U\},max\{b\left(v\right):v\in W\left\}\right\}$ and m denotes the number of the edges.

## Acknowledgments

## Conflicts of Interest

## References

- Abdulkadiroglu, A.; Pathak, P.A.; Roth, A.E. Strategy-proofness vs. Efficiency in matching with indifferences: Redesigning the NYC high school match. Am. Econ. Rev.
**2009**, 99, 1954–1978. [Google Scholar] [CrossRef] - Erdil, A.; Haluk, E. What’s the Matter with Tie-Breaking? Improving Efficiency in School Choice. Am. Econ. Rev.
**2008**, 98, 669–689. [Google Scholar] - Gale, D.; Shapley, L.S. College admissions and the stability of marriage. Am. Math. Mon.
**1962**, 69, 9–15. [Google Scholar] [CrossRef] - Halldórsson, M.M.; Irving, R.W.; Iwama, K.; Manlove, D.; Miyazaki, S.; Morita, Y.; Scott, S. Approximability results for stable marriage problems with ties. Theor. Comp. Sci.
**2003**, 306, 431–447. [Google Scholar] [CrossRef] - Halldórsson, M.M.; Iwama, K.; Miyazaki, S.; Yanagisawa, H. Improved approximation results for the stable marriage problem. ACM Trans. Algorithms
**2007**, 3, 30. [Google Scholar] [CrossRef] - Irving, R.W.; Manlove, D. Finding large stable matchings. ACM J. Exp. Algorithmics
**2009**, 14. article 2. [Google Scholar] [CrossRef] - Iwama, K.; Miyazaki, S.; Okamoto, K. A ($2-c\frac{\mathrm{log}n}{n}$)-approximation algorithm for the stable marriage problem. IEICE Trans.
**2006**, 89-D, 2380–2387. [Google Scholar] - Iwama, K.; Miyazaki, S.; Yamauchi, N. A ($2-c\frac{2}{\sqrt{n}}$)-approximation algorithm for the stable marriage problem. Algorithmica
**2008**, 51, 342–356. [Google Scholar] [CrossRef] - Iwama, K.; Miyazaki, S.; Yamauchi, N. A 1:875-approximation algorithm for the stable marriage problem. In Proceedings of the Eighteenth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA, New Orleans, January 7–9, 2007; Bansal, N., Pruhs, K., Stein, C., Eds.; pp. 288–297.
- Iwama, K.; Miyazaki, S.; Yanagisawa, H. A 25/17-Approximation algorithm for the stable marriage problem with one-sided ties. Lect. Notes Comp. Sci.
**2010**, 6347, 135–146. [Google Scholar] - Király, Z. Better and simpler approximation algorithms for the stable marriage problem. Algorithmica
**2011**, 60, 3–20. [Google Scholar] [CrossRef] - Király, Z. Approximation of Maximum Stable Marriage; Technical Report TR-2011-0; The Egerváry Research Group: Budapest, Hungary, 2011. [Google Scholar]
- Lovász, L.; Plummer, M.D. Matching Theory. In Annals of Discrete Mathematics 29, North-Holland, Amsterdam, 1986.
- Manlove, D.; Irving, R.W.; Iwama, K.; Miyazaki, S.; Morita, Y. Hard variants of stable marriage. Theor. Comput. Sci.
**2002**, 276, 261–279. [Google Scholar] [CrossRef] - McDermid, E. A 3/2-approximation algorithm for general stable marriage. In Proceedings of the Automata, Languages and Programming, 36th International Colloquium, ICALP, Rhodes, Greece, 2009; Albers, S., Marchetti-Spaccamela, A., Matias, Y., Nikoletseas, S.E., Thomas, W., Eds.; pp. 689–700.
- Paluch, K.E. Faster and simpler approximation of stable matchings. In Proceedings of the WAOA ’11: 9th Workshop on Approximation and Online Algorithms, Saarbruecken, Germany, 2011; Solis-Oba, R., Persiano, G., Eds.; pp. 176–187.
- Yanagisawa, H. Approximation Algorithms for Stable Marriage Problems. Ph.D. Thesis, Kyoto University, Kyoto, Janpan, 2007. [Google Scholar]

© 2014 by the author; licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution license (http://creativecommons.org/licenses/by/3.0/).

## Share and Cite

**MDPI and ACS Style**

Paluch, K.
Faster and Simpler Approximation of Stable Matchings. *Algorithms* **2014**, *7*, 189-202.
https://doi.org/10.3390/a7020189

**AMA Style**

Paluch K.
Faster and Simpler Approximation of Stable Matchings. *Algorithms*. 2014; 7(2):189-202.
https://doi.org/10.3390/a7020189

**Chicago/Turabian Style**

Paluch, Katarzyna.
2014. "Faster and Simpler Approximation of Stable Matchings" *Algorithms* 7, no. 2: 189-202.
https://doi.org/10.3390/a7020189