lemmatheorem \aliascntresetthelemma \newaliascntcorollarytheorem \aliascntresetthecorollary \newaliascntdefinitiontheorem \aliascntresetthedefinition \newaliascntobservationtheorem \aliascntresettheobservation
The Graphs of Stably Matchable Pairs
Abstract
We study the graphs formed from instances of the stable matching problem by connecting pairs of elements with an edge when there exists a stable matching in which they are matched. Our results include the NP-completeness of recognizing these graphs, an exact recognition algorithm that is singly exponential in the number of edges of the given graph, and an algorithm whose time is linear in the number of vertices of the graph but exponential in a polynomial of its carving width. We also provide characterizations of graphs of stably matchable pairs that belong to certain classes of graphs, and of the lattices of stable matchings that can have graphs in these classes.
1 Introduction
A stable matching instance, in its most basic form, consists of two sets of elements to be matched (for instance, students and residencies), with each element in one set having preferences that can be described as a linear ordering of the elements of the other set. In a slightly more general form, the form we consider here, an element may prefer remaining unmatched over being matched to some undesired elements. This can be expressed by making each preference ordering be a linear ordering of a subset of elements, removing the undesired elements from this ordering. A matching is stable when no matched element would prefer being unmatched over its assigned match, and no pair of elements would both prefer being matched to each other over their assigned outcomes. The Gale–Shapley theorem, which applies equally well in this more general setting, states that a stable matching exists; one such matching can be found in time linear in the total length of the preference orderings by the Gale–Shapley algorithm [10].
A given instance of stable matching may have many stable matchings, forming a distributive lattice in which the matching found by the Gale–Shapley algorithm is the top element. Although this lattice may consist of exponentially many matchings [18], it has a concise description as a partially ordered set of alternating cycles, called rotations, which can be constructed in polynomial time [15]. A given pair of elements participates in at least one stable matching if and only if it is either part of the top stable matching found by the Gale–Shapley algorithm, or part of one of these rotations. Therefore, from a given instance of stable matching, we may construct in polynomial time a bipartite graph, the graph of pairs that can be matched to each other in at least one stable matching.
In this work, we ask: can we reverse this process? Given a bipartite graph, can we determine whether it comes from an instance of stable matching in this way? Can we construct a stable matching instance that has a given graph as its graph of stably matchable pairs? What structural properties must such a graph have? For instance, by the rural hospitals theorem [23, 27] we know that every stable matching has the same set of matched elements; in graph-theoretic terms, this means that removing the isolated vertices from the graph of stably matchable pairs (the elements that cannot be stably matched) leaves a balanced bipartite graph (one with equal numbers of vertices on each side of the bipartition), and this graph is a matching-covered graph meaning that each of its edges participates in a perfect matching. Matching-covered balanced bipartite graphs can be recognized efficiently, in the same asymptotic time as finding a single perfect matching [26, 29]. Are these necessary conditions sufficient? Is every matching-covered balanced bipartite graph the graph of stably matchable pairs of some stable matching instance?

1.1 New results
The example of shown in Figure 1 answers some of these questions: it is a balanced, matching-covered bipartite graph, but (as we will demonstrate later in Section 2) cannot be generated as the graph of stably matchable pairs of any stable matching instance. More generally, in this paper we provide the following results:
-
•
In Section 3 we search for simple criteria that can determine in some cases whether a given graph is a graph of stably matchable pairs. We observe in Section 3.1 that these graphs have no forbidden induced subgraphs: every bipartite graph is an induced subgraph of a larger regular graph, and every regular graph is a graph of stably matchable pairs. We prove in Theorem 3.1 that, for a subcubic graph to be a graph of stably matchable pairs, it is necessary that its degree-one vertices and that its degree-three vertices induce subgraphs that have perfect matchings, and sufficient that in addition its degree-two vertices induce a subgraph that has a perfect matching. We prove in Theorem 3.2 that an outerplanar graph is a graph of stably matchable pairs if and only if it has no articulation vertex, and we characterize in Theorem 3.3 the rectangular grid graphs that are graphs of stably matchable pairs. More generally, Theorem 3.4 concerns realizability of Cartesian product graphs.
-
•
In Section 4 we study the distributive lattices of stable matchings associated with graphs of stably matchable pairs, and we examine how the structure of the graph affects the structure of the lattice. We prove in Theorem 4.1 that every finite distributive lattice is the lattice of stable matchings of an instance whose graph of stably matchable pairs is subcubic, and in Theorem 4.2 we characterize the lattices of stable matchings of graphs meeting the sufficient condition of Theorem 3.1. In Theorem 4.3 we characterize the lattices of stable matchings of subcubic outerplanar and subcubic series-parallel graphs, and in Theorem 4.4 we characterize the lattices of stable matchings of planar graphs.
-
•
In Section 5 we study the computational complexity of recognizing graphs of stably matchable pairs. We prove in Theorem 5.1 that it is NP-complete to determine whether a given graph can be realized as a graph of stably matchable pairs, even when the graph is planar and subcubic.
-
•
In Section 6 we study algorithms for recognizing the graphs of stably matchable pairs, more efficiently than a brute-force search through all preference systems on the given graph. We provide algorithms that can test whether an arbitrary graph is a graph of stably matchable pairs, either in time singly exponential in the number of edges (Theorem 6.1), or in time that is fixed-parameter tractable in the carving width of the given graph (Theorem 6.2).
1.2 Related work
The graphs of stably matchable pairs for random instances with uniformly-random preferences have been investigated by Knuth, Motwani, and Patel, who proved that with elements on each side the number of edges in these graphs is with high probability [20], and by Pittel, Shepp, and Veklerov, who bounded the numbers of vertices with degree in these graphs, for constant , with high probability [25]. In contrast to these results, random instances for which the elements on one side have preference lists of bounded size produce graphs in which almost all vertices have degree one [14].
The part of our work on the lattices of stable matchings, and the connections between lattice structure and graph structure, is based on the work of Gusfield, Irving, Leather, and Saks on the distributive lattices derived from stable matching instances. As they proved, every finite distributive lattice can be derived from a stable matching instance in this way. There is a polynomial time algorithm for reversing the transformation from matching instances to lattices, and constructing a stable matching instance that has a given distributive lattice as its lattice of instances [13].
2 Preliminaries
We summarize below known and standard results on the structure of the system of stable matchings of a given stable matching instance. For convenience we will follow the convention that the elements being matched are students and residencies . For book-length surveys of the stable matching problem see [12, 19, 22].
-
•
By the rural hospitals theorem, every stable matching has the same matched elements. Therefore, the elements of the given instance may be partitioned into isolated elements (those that cannot participate in any stable matching), uniquely matched elements (elements that are always matched to the same other element), and non-uniquely matched elements (always matched, but with more than one possible match).
-
•
The stable matchings may be partially ordered, with in this order when every student prefers to (or has the same match in both and is indifferent), or equivalently when every residency prefers to or is indifferent. This partial ordering forms a distributive lattice, in which the join (least upper bound) of two matchings and is obtained by giving every residency its more-preferred match from and and giving every student their least-preferred match from and . Symmetrically, the meet (greatest lower bound) of two matchings is obtained by giving every residency its least-preferred match and giving every student their most-preferred match. The join and meet operations are associative and can be extended in the obvious way from pairs of stable matchings to arbitrary sets of stable matchings.
-
•
The top element of the lattice (the join of all stable matchings) has the property that every residency prefers to every other stable matching (or is indifferent to the comparison), and every student prefers any other stable matching to (or is indifferent to the comparison). However, this matching is not necessarily obtained by giving every residency its first choice, as this might not result in a matching. If a residency is not assigned its first choice in , then that first choice is not available to it in any stable matching. Symmetric statements apply to the first choices of students and the bottom element of the lattice.
-
•
If a pair and cannot be matched in any stable matching of a given instance, then the system of all stable matchings is unchanged by changing the preferences so that both and prefer being unmatched to being matched to each other. Therefore, any stable matching instance can be converted to an equivalent instance with partial preferences that only include pairs that can be matched. Conversely, if an instance with partial preferences has the property that its stable matchings include a match for every element, then it is equivalent to an instance with full preferences in which the additional pairings added to make the preference system full are ranked below all of the original pairings.
-
•
If two stable matchings and are adjacent in the distributive lattice of matchings (meaning that they are comparable, say as , and there is no third matching between them in the partial order with ) then their symmetric difference is a rotation, a single cycle of matched pairs that alternates between pairs of and of .
-
•
By Birkhoff’s representation theorem for distributive lattices [2], the lattice of stable matchings can be recovered uniquely from the partial order of join-irreducible stable matchings, the matchings that cannot be formed as the join of any subset of stable matchings that does not include itself. According to this theorem, the stable matchings correspond one-for-one with the lower sets of this partial order, subsets of join-irreducible stable matchings for which, if belongs to the subset and , then also belongs to the subset. The stable matching corresponding to a lower set is its join, and the lower set corresponding to a stable matching is the lower set of join-irreducible stable matchings that are below in the lattice. The top stable matching corresponds to the lower set of all join-irreducible stable matchings, and the bottom stable matching corresponds to the empty lower set. It is possible for to be join-irreducible, but cannot be, as it is the join of the empty set, which does not contain .
-
•
For each join-irreducible stable matching , there is a unique stable matching that is adjacent to : is the join of all stable matchings below . We may associate with the rotation formed by and . This association is one-to-one: every rotation comes in this way from a unique join-irreducible stable matching. Therefore, the rotations can be partially ordered, inheriting the partial order of the corresponding join-irreducible stable matchings. Within each rotation, the edges alternate between upper edges (pairs in ) and lower edges (pairs in ); the same upper-lower relation on the edges remains valid for every pair of stable matchings that differ by the same rotation.
-
•
The collection of all rotations and their partial order can be constructed from a given system of preferences in polynomial time [11].
-
•
Define an extended rotation to be either a rotation or one of the two stable matchings and . Consider every pair in to be a lower edge in , and consider every pair in to be an upper edge in . Then for every pair that participates in at least one stable matching, there is a unique extended rotation in which it is a lower edge, and a unique extended rotation for which it is an upper edge.
-
•
The stable matching corresponding to a lower set in the partial order of rotations consists of the pairs that are upper edges in one of the extended rotations of but are not lower edges in any of these extended rotations.
Based on these results, we define a rotation system for given sets of students and residencies to be a partially ordered collection of cycles that alternate between students and residencies, together with two matchings and from students to residencies, such that each pair belongs to either zero or two members of , and such that each cycle alternates between upper edges (belonging to or to an element above the cycle in the partial order) and lower edges (belonging to or to an element below the cycle in the partial order. We call the elements of rotations and the elements of extended rotations. The results above imply that every stable matching instance can be described in polynomial time by a rotation system, and that the graph of stably matchable pairs in the instance equals the graph of pairs participating in extended rotations.
Conversely, we have:
Lemma \thelemma.
Every rotation system describes the collection of stable matchings for a system of partial preferences. If in addition the rotation system has the property that there are either no unmatched students, or no unmatched residencies, then it describes the collection of stable matchings for a system of complete preferences.
Proof.
A rotation system allows the edges incident with any one student or residency to be ordered, by the partial order of the rotations in which those edges are upper edges. Each incident edge that is not in is the lower edge of at least one rotation, and has the upper edge of the same rotation above it; similarly, each incident edge that is not in is the upper edge of at least one rotation, and has the lower edge of the same rotation below it. Therefore, this partial ordering on incident edges forms a collection of ordered sequences in which there is a unique bottom element and a unique top element, which can only happen when there is a single chain forming a total order on these incident edges. Based on this ordering of incident edges, define a system of partial preferences, in which the preference ordering for each residency is the same as its ordering of incident edges, and in which the preference ordering for each student is the reverse of its ordering of incident edges.
The sets of pairs coming from a lower set of rotations, as the pairs that are upper in an extended rotation of but not lower in any of these extended rotations, are all matchings, and we claim that they are all stable for these preferences. This follows by induction on the size of . If is empty, the resulting set of pairs is itself, and it is stable because every student gets their first choice. Otherwise, some rotation in is maximal among the partially ordered elements of , and by induction the matching obtained by removing from is stable. Then changing this matching by its symmetric difference with improves the preference of every residency whose matching is changed, but worsens the preference of every student whose matching is changed. This cannot introduce any new unstable pair , because if prefers this pair, then it would already have the same preference in the stable matching prior to symmetric differencing with , implying that did not prefer this pair and still does not prefer it.
Conversely, we claim that every stable matching for these preferences is generated in this way. If a matching is not generated in this way, but covers the same elements as and , then consider the set of rotations of the rotation system that contain an edge of as one of their upper edges, or are below one of these rotations. This is a lower set, and generates a stable matching . Because and have the same number of edges, it follows that there is a cycle that is maximal in the partial order on , in which at least one upper edge of is included in but not all are. However, for such an edge, prefers its other neighbor (the adjacent lower edge in ). In order to prevent from being an unstable pair for , must be matched to an element it prefers to , and this match can only be its other neighbor in . Any other match for would either belong to an extended rotation lower than in the partial order, which would not prefer to , or to an extended rotation higher than , contradicting the choice of as being maximal in . It follows that the upper edge of also belongs to . But repeating this argument step-by-step around shows that all upper edges of belong to , contradicting the choice of as being a rotation whose upper edges are not all included in . This contradiction establishes our claim that the given set of preferences does not generate any extra stable matchings beyond the ones coming from the given rotation system.
To obtain a full preference system from this partial preference system, when there are no unmatched students or no unmatched residencies, rank every added pairing below the pairings in the partial preference system. For the case that there are no unmatched students, is stable because it gives every student their first choice, establishing the base case of the induction. Every stable matching must have at least one matched pair belonging to the rotation system, because otherwise every pair in would be an unstable pair. The remaining steps of the proof, showing by induction that every matching from the rotation system is stable and showing by contradiction that no other stable matching can use a matched pair from the rotation system, go through as before. The case that there are no unmatched residencies is symmetric and follows by reversing the roles of students and residencies (also reversing the comparisons in the partial order of the rotation system). ∎
For completeness we also include:
Observation \theobservation.
Every graph of stably matchable pairs has the property that every connected component of more than two vertices is matching-covered and has a 2-factor (a 2-regular subgraph covering all of its vertices).
Proof.
Being matching-covered (within any connected component) follows from the definition, that the graph is covered by the stable matchings of some stable matching instance, and from the rural hospitals theorem, according to which all stable matchings cover the same set of vertices. The 2-factor within any component can be found as the disjoint union of the top and bottom matchings within the component, which (for a component of more than two vertices) must be disjoint. ∎

Figure 2 shows that the two conditions in Section 2 are independent: both are biconnected subcubic balanced bipartite graphs, one is matching-covered but has no 2-factor, and the other has a 2-factor but is not matching-covered. Both conditions can be tested in polynomial time. With this foundational material established, we can turn to the example from Figure 1, which is matching-covered and has a 2-factor, but is still not a graph of stably matchable pairs.
Observation \theobservation.
The graph depicted in Figure 1 is not the graph of stably matchable pairs of any stable matching instance.
Proof.
The four perfect matchings of this graph (shown on the right side of the figure) each use only one of the four central edges of the graph, so all four are needed to cover the whole graph. Because a single rotation can include only two of these edges (one as an upper edge and the other as a lower edge of the rotation), each rotation must pass through one of the degree-two vertices. Each degree-two vertex can be in only one rotation, so there are at most two rotations. For two rotations to generate four perfect matchings, they must be incomparable in the partial order of rotations, because a partial order with two comparable elements has only three lower sets. Rotations that are incomparable must be edge-disjoint, but this graph does not have two edge-disjoint cycles. ∎
3 Which graphs are representable?
Our later NP-completeness result (Theorem 5.1) strongly suggests that a simple and exact characterization of the graphs of stably matchable pairs, in general, does not exist. Therefore, in this section, we seek special classes of graphs for which a characterization can be found, as well as partial characterizations in terms of conditions that are necessary or sufficient but not both.
3.1 Regular graphs and induced subgraphs

In this section we show that the graphs of stably matchable pairs have no hidden structure, in the sense that there are no forbidden induced subgraphs for these graphs. We begin with the following observation:
Observation \theobservation.
Every regular bipartite graph is a graph of stably matchable pairs for some stable matching instance.
Proof.
By a theorem of Dénes Kőnig, every regular bipartite graph can be decomposed into disjoint perfect matchings [21]. Arbitrarily order these matchings, and construct a partial preference system in which one side of the bipartition (the students) prioritizes each potential pairing of the graph according to this ordering, and the other side of the bipartition (the residencies) prioritizes the pairings according to the reverse ordering. With these priorities, every matching of the decomposition (as well as, potentially, some other matchings using the same edges) is stable. ∎
For instance, this applies to the graph of the cube, to every balanced complete bipartite graph, to every Levi graph of a finite projective plane (such as the Heawood graph, the Levi graph of the Fano plane), and to every Levi graph of a projective configuration of equally many points and lines with each point on the same number of lines and each line containing the same number of points (such as the Möbius–Kantor graph, Pappus graph, and Desargues graph, Levi graphs of configurations with 8, 9, and 10 points and lines respectively).
Lemma \thelemma.
Every bipartite graph is an induced subgraph of a regular bipartite graph.
Proof.
Let be an arbitrary bipartite graph. Add isolated vertices to one side of the bipartition of , if necessary, to make the resulting graph become balanced. Let and be the vertices on the two sides of the bipartition of the resulting balanced bipartite graph. Construct a graph with twice as many vertices, by making a copy or of each vertex and . For each edge in , make two edges in , and , and for each pair that is not an edge in , make two edges in , and , as shown in Figure 3. The result is a regular balanced bipartite graph in which the vertices and induce a copy of , and in which every vertex on one side of the bipartition is adjacent to exactly half of the vertices on the other side of the bipartition. ∎
Corollary \thecorollary.
Every bipartite graph is an induced subgraph of a graph of stably matchable pairs.
Proof.
It is an induced subgraph of a regular bipartite graph by Section 3.1, and this regular bipartite graph is a graph of stably matchable pairs by Section 3.1. ∎
3.2 Subcubic graphs
A subcubic graph is a graph such as our example in which every vertex has degree at most three. It all degrees are exactly three, it is a cubic graph. In this section we examine more closely the structure of subcubic graphs of stably matchable pairs, finding both necessary conditions and (different) sufficient conditions for a subcubic graph to be representable in this way. Our next result provides necessary and (different) sufficient conditions for being a graph of stably matchable pairs, based on matchings of equal-degree vertices. It is convenient to introduce the notation , where is a graph and is a natural number, meaning the subgraph of induced by its degree- vertices.
Theorem 3.1.
If is a bipartite subcubic graph, then a necessary condition for to be a graph of stably matchable pairs is that and both have perfect matchings. It is sufficient that, as well, has a perfect matching.
Proof.
If is to be a graph of stably matchable pairs, it is necessary that every non-isolated vertex of be matched in every stable matching. If is a degree-one vertex, its neighbor can have no other matches, so its neighbor must also be degree-one. Therefore, it is necessary for to have a perfect matching.
If is a subcubic graph of stably matchable pairs of some stable-matching instance, and is a vertex of degree two or three in , then one of the edges incident to must belong to the top matching of the lattice of stable matchings, and a different one of the edges incident to must belong to the bottom matching . Each degree-three vertex is incident to a unique edge that belongs neither to nor , so these edges form a perfect matching of .
If , , and all have perfect matchings (Figure 4, far and middle left), then the subgraph formed by removing from the matched edges in consists of isolated vertices and edges, and disjoint cycles of degree-two and degree-three vertices (Figure 4, middle right). Form two matchings and consisting of the matched edges in and alternating subsets of these disjoint cycles, choosing arbitrarily within each cycle how to alternate between edges of (which we call top edges) and edges of (which we call bottom edges). Call the edges in the matching of middle edges, as they are neither in nor in . Additionally, for a top edge or a bottom edge, we say that it is matched if it is part of the perfect matching of , and unmatched otherwise. Once this choice has been made, form a system of cycles in of two types (Figure 4, far right):
-
•
Upper cycles alternate between unmatched top edges and either middle edges (at degree-3 vertices of ) or matched bottom edges (at degree-2 vertices of ).
-
•
Lower cycles alternate between unmatched bottom edges and either middle edges or matched top edges.
These cycles are simply the connected components of a 2-regular graph formed by splitting each degree-three vertex and each middle edge into two copies, an upper copy and a lower copy, with the incident top edge going to the upper copy and the incident bottom edge going to the lower copy. In particular, they are simple cycles, with each top or bottom edge appearing in exactly one of these cycles and each middle edge appearing in one upper cycle and one lower cycle.

Partially order these cycles by making two cycles and comparable when they share one or more middle edges, with when is the lower cycle and is the upper cycle of the two, and by making all other pairs of cycles incomparable. Then this system of partially ordered cycles, together with the matchings and , form a rotation system for , and the result that is a graph of stably matchable pairs follows from Section 2. ∎
3.3 Outerplanar graphs
Outerplanar graphs can be tested for being a graph of stably-matching pairs very easily, by checking a simple necessary and sufficient condition.
Lemma \thelemma.
No graph of stably-matching pairs can have an articulation vertex.
Proof.
A graph with an articulation vertex cannot be matching-covered, and so by Section 2 cannot be a graph of stably-matching pairs. For, if any component formed from the graph by the removal of has an even number of vertices, the edge or edges connecting that component to cannot be included in any perfect matching. And if all of these components have an odd number of vertices, only one of these components can have an edge to in a perfect matching, and the rest of these components cannot be perfectly matched. ∎
Theorem 3.2.
A bipartite outerplanar graph is a graph of stably-matching pairs if and only if has no articulation vertex.
Proof.
One direction is Section 3.3. In the other direction, let be a bipartite outerplanar graph, drawn in an outerplanar way (with all vertices belonging to the unbounded face). We prove by induction on the number of bounded faces that is a graph of stably matchable pairs for a rotation system in which the outer face of is the union of the top and bottom matchings, and (when has more than one bounded face) all bounded faces are rotations.
As a base case, if is a cycle graph, it has a rotation structure consisting of two disjoint perfect matchings (the top and bottom matchings of the rotation structure) and an empty set of rotations. As a second base case, if consists of two cycles sharing an edge, it has a rotation structure where these two cycles are both rotations, alternating between top edges and bottom edges except at their shared edge. One of these two rotations (the upper one in the partial order of the two rotations) has top edges adjacent to the shared edge, and the other one has bottom edges adjacent to the shared edge.
In the non-base case, the weak dual of (a graph with a vertex for each bounded face and an edge between bounded faces that share an edge in ) is a tree with at least one leaf , a bounded face of that shares only one edge with the rest of the graph. By induction, the outerplanar graph formed from by removing (but keeping the shared edge in place) has a rotation structure in which the outer face of (including ) alternates between top and bottom edges, and each face is a rotation. We construct a rotation structure for by adding as a rotation to this structure, alternating between top and bottom edges. If was a top edge in , we place above the neighboring rotation in the partial order, and choose the alternation of top and bottom edges of to have top edges adjacent to . Otherwise, we place below the neighboring rotation, and choose the alternation of its edges with bottom edges adjacent to . Both cases preserve all the defining properties of a rotation system. ∎
Although more general bipartite outerplanar graphs may be unbalanced, the bipartite outerplanar graphs with no articulation vertex are automatically balanced. This follows as a corollary from Theorem 3.2 but can also be proven more directly by a similar induction.
3.4 Rectangular grids
We define an grid graph to be the graph of unit distances in the integer points with and . That is, it consists of a rectangular array of vertices, with vertices along one side of the rectangle and along the other, and with vertices adjacent to their nearest neighbors in the directions parallel to the rectangle sides. When is even, the resulting graph is automatically balanced.

Theorem 3.3.
The grid graph can be realized as a graph of stably matchable pairs if and only if is even and .
Proof.
We consider the following cases:
-
•
If is odd, the number of vertices is odd and no perfect matching can exist.
-
•
If , the graph is outerplanar and realizability follows from Theorem 3.2.
-
•
If , suppose for a contradiction that the grid has a rotation system. Consider the block of six squares at one end of the grid, separated by three edges from the rest of the grid. In any rotation system, the bottom matching includes an even number of these separating edges. A rotation that does not include these edges does not change the number of separating edges that are used. A rotation that uses the middle of these three edges either adds two to the number of separating edges that are used, or removes two of these edges from use, because (by the parity of the distance between the endpoints of the two separating edges that it uses) either both separating edges must be upper in the rotation or both must be lower. However, in any sequence of stable matchings progressing upward through the lattice of stable matchings from its bottom to its top, each of the three separating edges must be introduced exactly once, so there must be a rotation that introduces only one new edge. Such a rotation must necessarily use the outer two of the three edges separating from the rest of the graph; again, by the parity of the distance between the endpoints of these outer separating edges, one of them would be an upper edge of any such rotation and the other of them would be a lower edge. Within , the path of uses an odd number of vertices, so in order for all vertices of to be matched, the two perfect matchings that are connected by must both include the middle separating edge of as one of their matched edge. The remaining five vertices of induce a path, which must be the path followed by . Because the two corner vertices of this path have degree two, the four edges of this path must all belong to or . But this means that the rotation passes through the degree-three vertex at the center of the path using only edges of or , making it impossible for any other rotation to incorporate the third edge at that vertex into the rotation system. This contradicts our assumption that a rotation system exists, proving that no realization as a graph of stably matchable pairs is possible in this case.
Figure 6: A rotation system realizing a grid as a graph of stably matchable pairs. Figure 7: A rotation system realizing a grid as a graph of stably matchable pairs. Repeating the same pattern of top and bottom matchings and rotations produces a rotation system for any grid with . -
•
If and are both even, we form a rotation system using a subset of the unit squares of the grid as rotations, as illustrated in Figure 5. If we associate a grid square with its lower left corner (the point of the square whose coordinates are smallest), then we choose the squares whose first coordinate is even and whose second coordinate as odd as the bottom elements of the partial order of rotations. We choose the squares with both coordinates even as intermediate elements in this partial order, and we choose the squares whose first coordinate is odd and whose second coordinate is even as the top elements of the partial order. We do not use squares with both coordinates odd as rotations. The top matching consists of horizontal edges of top squares, and vertical edges of intermediate squares that are not shared with top squares. The bottom matching consists of vertical edges of bottom squares, and horizontal edges of intermediate squares that are not shared with bottom squares.
-
•
In the remaining cases, the smallest odd dimension of the grid is at least five and the smallest even dimension is at least six. Figure 6 depicts a rotation system realizing the grid and Figure 7 shows how to extend this to all grids for . Examination of each grid edge in the figures shows that they are all covered by two elements of the rotation system and top and bottom matching, one upper and one lower, and examination of each rotation shows that they all alternate between upper and lower edges, as required for a rotation system.
Note that, in each of the resulting rotation systems, the top matching includes a perfect matching of the vertices on the bottom rows of the rotation system. This allows these rotation systems to be extended by any even number of rows below these bottom rows, by using the square rotations from the bottom squares of the pattern used in the previous case for even-by-even grids, maintaining the partial order among these rotations and placing them in the partial order above all of the rotations used for the top five rows of the grid.
In all cases with even, the grid is realizable when and unrealizable otherwise. ∎
3.5 Product graphs
Given two graphs and , their Cartesian product is a graph whose vertices belong to the Cartesian product of sets and whose edges connect two elements of (two pairs of a vertex in and a vertex in ) when the vertices in are equal and the vertices in are adjacent, or vice versa. We may identify the edge set of the product graph with the disjoint union . For instance, the grid graphs of the previous section are Cartesian products of path graphs. If both and are bipartite, then so is their product: if we two-color both and , then one side of the bipartition of consists of monochromatic pairs of a vertex from and a vertex from , and the other side consists of bichromatic pairs.
Theorem 3.4.
If both and are realizable as graphs of stably matching pairs, then so is .
Proof.
We assume without loss of generality that neither nor has isolated vertices, as any such vertices lead in to disconnected copies of or that can be handled separately.
A preference system realizing from separate realizations of and can be derived by giving the students preferences that prioritize edges coming from over edges coming from , and giving the residencies preferences that prioritize edges coming from over edges coming from . However it is easier to verify that this does not lead to additional undesired matched edges if we describe more explicitly a rotation system realizing , derived from rotation systems for and for .
Let , , , and denote the top and bottom matchings of the rotation systems for and . We form a rotation system whose top matching is (using the top matching in each copy of , as preferred by the residencies) and whose bottom matching is . For each rotation in we form copies of in the rotation structure for , one for each vertex in , and similarly for each rotation in we form copies in the rotation structure for , one for each vertex in . These copies are partially ordered in the same way they are in the rotation systems of or , with two copies of rotations being incomparable when they correspond to different vertices in or .
Finally, we add to these rotations the cycles of the 2-regular graph . Each such cycle is partially ordered above the copies of rotations from with which it shares an edge, and below the copies of rotations from with which it shares an edge, causing it to alternate between upper and lower edges (as required in a rotation system) and providing each of the edges of this 2-regular graph with a second rotation that it belongs to (as also required in a rotation system). ∎
The examples of the grid graphs show that, although the realizability of both and is sufficient for the realizability of , it is not always necessary. The example of in Figure 2 (left) shows that realizability of a single factor and bipartiteness of the other factor is not always sufficient.
4 How does the graph constrain the lattice?
In this section we revisit the result of Gusfield, Irving, Leather, and Saks that every finite distributive lattice is the lattice of stable matchings of a stable matching instance [13]. We ask whether this remains true for natural subclasses of the graphs of stably matchable pairs, or whether restricting the class of graphs that we consider also restricts the classes of lattices that they can realize.
4.1 Background and definitions
Several of our characterizations will relate the lattices of stable matchings to the lattices of closures of a directed graph. In this context, a closure is a subset of the vertices of a given directed graph that has no outgoing edges: there is no edge from a vertex in the closure to a vertex outside the closure [24, 9]. The closures of a graph, ordered by subsets, form a distributive lattice, which is the lattice of lower sets in a partial order on strongly connected components of the given graph, defined by setting whenever a vertex of component can be reached from a vertex of . A maximum-weight closure can be found in polynomial time, and maximum-weight closures on directed acyclic graphs of rotations can be used to find stable matchings that meet additional optimization criteria [16].
A directed graph may be obtained from an undirected graph by choosing a direction for each undirected edge, and a directed graph constructed in this way is called an orientation of the undirected graph; for instance, oriented planar graphs are the orientations of undirected planar graphs. A minor of a graph is any graph that can be obtained from it by a (possibly empty) sequence of edge contractions, edge deletions, and vertex deletions.
A comparability graph is a graph whose vertices are the elements of a partially ordered set and whose edges connect pairs of elements that are related in the partial order. An intersection graph is a graph whose vertices are members of a family of sets and whose edges connect pairs of vertices whose sets have a nonempty intersection. A string graph is an intersection graph of a family of curves in the plane [7]. (Sometimes a restriction is added that at most two curves intersect at any point; this does not affect the resulting class of graphs, as any family of curves can be perturbed to meet this restriction without adding or removing any intersection pairs.)
4.2 Subcubic graphs
Although the condition that every element have only three choices of matches may seem restrictive, subcubic graphs still have much of the general structure of arbitrary stable matching instances, as the following result demonstrates.

Theorem 4.1.
Every finite distributive lattice is isomorphic to the lattice of stable matchings of a stable matching instance whose graph of stably matchable pairs is subcubic.
Proof.
From an arbitrary given finite distributive lattice, construct the partial order of its subset of join-irreducible elements, and let be the Hasse diagram of this partial order. That is, has a vertex for each join-irreducible element of the lattice, and an edge from the lower to the upper of each two comparable elements that have no other join-irreducible element between them.
For each vertex of , construct a cycle graph , of even length, with its edges labeled alternatingly as upper and lower and with its vertices labeled alternatingly as students and residencies. Each edge in should be associated with one of the lower edges of , and each edge in should be associated with one of the upper edges of , in such a way that the edges of that are associated with edges of in this way are not adjacent to each other in . If has total degree in , then can be constructed with length if , or with length at most if .
Form a graph from the union of the cycles by, for each edge in , merging together the edges of and that are associated with (at the same time merging the two student endpoints of these edges and the two residency endpoints of these edges). Then is subcubic, because each merged pair of endpoints produces a vertex of with degree three (one merged edge and its two neighbors in the two cycles from which it was merged) and each unmerged vertex of one of the cycles continues to have degree two. Form also a rotation system in , in which the rotations are the cycles , partially ordered by the partial order for which is the Hasse diagram, in which is the matching formed by the unassociated upper edges of cycles , and in which is the matching formed by the unassociated lower edges of cycles . Both and are perfect matchings, because each merged or unmerged vertex in has exactly one neighbor in and one in .
Because the subcubic graph has a rotation system, it follows from Section 2 that there is a system of preferences for which this rotation system describes all of the stable matchings. Because both the lattice of stable matchings for these preferences and the initially given finite distributive lattice can be described as the lower sets of isomorphic partial orders, they are isomorphic lattices. ∎
The construction of Theorem 4.1 is illustrated in Figure 8.
Recall that in Theorem 3.1 we proved that if a subcubic graph has a perfect matching where all matched edges connect equal-degree vertices, then it is a graph of stably matchable pairs. Call a graph with this property degree-matchable. The height of a partial order is the maximum number of elements in any chain, a totally-ordered subset of elements. A bipartite orientation of an undirected bipartite graph is an orientation in which all edges are directed in the same way, from one side of the bipartition to the other. The closures of a bipartite orientation are the same as the lower sets of a partial order of height at most two, on the vertices of the bipartite graph, with if there is an edge from to .
Theorem 4.2.
If a stable matching instance has a subcubic degree-matchable graph as its graph of stably matchable pairs, then its lattice of stable matchings is isomorphic to the lattice of closures of a bipartite orientation, or equivalently the lattice of lower sets of a partial order of height at most two. Every lattice of closures of a bipartite orientation, or lattice of lower sets of a partial order of height at most two, can be realized as the lattice of stable matchings of an instance whose graph of stably matchable pairs is subcubic and degree-matchable.
Proof.
Let be a degree-matchable graph of stably matchable pairs. The degree-zero and degree-one vertices of are irrelevant for its lattices of stable matchings, so assume without loss of generality that there are none. Consider any rotation system for ; we wish to show that the lattice of stable matchings of this rotation system is isomorphic to the closures of a bipartite orientation, whose underlying undirected bipartite graph will be the comparability graph of the rotations. To see this, label the edges of as top, bottom, or middle, accordingly. Then each rotation must alternate between upper and middle edges, or between middle and lower edges, at the degree-3 vertices of , and between upper and lower edges at the degree-2 vertices of . Because is degree-matchable, every part of a rotation that passes through degree-2 vertices starts and ends on an edge with the same label, and does not allow the part of the rotation that passes through degree-3 vertices to change between upper–middle and middle–lower alternations. Therefore, the rotations can be partitioned into three classes:
-
•
the rotations with no middle edges, which form isolated vertices in the comparability graph of rotations,
-
•
the rotations in which every middle edge lies between two top edges, and
-
•
the rotations in which every middle edge lies between two bottom edges.
Each middle edge belongs to one rotation in the second class and one in the third. The rotations in the first and second classes are maximal in the partial order of rotations, and the rotations in the first and third classes are minimal. The lattice of stable matchings can be described as the lattice of lower sets of rotations, and these are just the closures in a directed graph on rotations having an edge from each rotation in the second class to each rotation sharing a middle edge with it in the third class. This graph is a bipartite orientation of the comparability graph of rotations.
In the other direction, suppose we are given a lattice of closures of a bipartite orientation of a graph and wish to find a corresponding subcubic degree-matchable graph of stably matchable pairs for an instance of stable matching with the same lattice. Because a bipartite orientation is always a transitively reduced directed acyclic graph, the join-irreducibles of its lattice of closures are in one-to-one correspondence with its vertices, and its underlying undirected bipartite graph is isomorphic under this correspondence to the comparability graph of its join-irreducibles. When we apply the construction of Theorem 4.1 to this lattice, we obtain a rotation for each vertex of , with its edges labeled as top, middle, or bottom. The endpoints of middle edges of these rotations are glued to other rotations, producing degree-3 vertices in the resulting graph of stably matchable pairs, and these degree-3 vertices have the middle edges as a perfect matching. Because no vertex of has both incoming and outgoing neighbors in the bipartite orientation, each path of top or bottom edges in each rotation has an even number of degree-2 vertices, and these vertices can be perfectly matched using the edges of the rotation. Therefore, is degree-matchable. ∎
4.3 Outerplanar and series-parallel graphs
Next, we turn to the lattices associated with outerplanar (or more generally series-parallel) graphs of stably matchable pairs. Characterizing these lattices is simplified by an additional assumption, that these graphs are subcubic, because of the following observation, which shows that in the subcubic case the definition of an intersection graph of rotations does not depend on whether we consider a rotation to be a set of vertices or of edges.
Observation \theobservation.
In a subcubic graph, two rotations share a vertex if and only if they share an edge incident to that vertex. Each vertex of a subcubic graph can be shared by at most two rotations.
Lemma \thelemma.
Suppose that for a given rotation system of a subcubic graph , the intersection graph of rotations contains a cycle. Then has at least one of or the graph of a triangular prism as a minor.
Proof.
Let be a shortest cycle in the intersection graph of rotations and let be a rotation that is maximal among the rotations of , according to the partial order of rotations. Let and be the two neighbors of in . Then all of the edges shared by with and are lower edges in the alternation of upper and lower edges of ; in particular, no two of these shared edges can be adjacent. Because was taken to be shortest, by the observation above, the edges that shares with and are the only parts of shared with other rotations in .
Let be the subgraph of induced by vertices in , let be any vertex of an edge shared by two rotations of , neither of which is , and let be the connected component containing in . Then must have a path through to rotation , and within to two endpoints of shared edges in . Symmetrically, must have a path through to rotation , and within to another two endpoints of shared edges in . Therefore, is connected by via at least four edges to at least four distinct vertices of . By combining a spanning tree within with these four connecting edges, we can find a tree in that is edge-disjoint from and has leaves at four vertices of . Because is subcubic, this tree has no degree-four vertices, so we can contract it to a tree with exactly two degree-three internal nodes, still having four leaves at distinct vertices of . Contracting the paths in between these four vertices produces a minor of consisting of a 4-cycle from and a tree with two internal nodes of degree three having these four vertices as its leaves. Depending on the order in which the tree leaves are attached to , this minor can only be either or the graph of the prism. ∎
Theorem 4.3.
If a stable matching instance has a subcubic outerplanar or series-parallel graph as its graph of stably matchable pairs, then its lattice of stable matchings is isomorphic to the lattice of closures of an oriented forest. Every lattice of closures of an oriented forest can be realized as the lattice of stable matchings of an instance whose graph of stably matchable pairs is subcubic and outerplanar.
Proof.
An outerplanar or series-parallel graph cannot have or the graph of a prism as a minor. Therefore, if a stable matching instance has a subcubic outerplanar or series-parallel graph as its graph of stably matchable pairs, by Section 4.3 the intersection graph of its rotations is a forest. Each edge of this forest corresponds to a pair of rotations that share an edge in the graph of stably matchable pairs, and can be oriented from the upper of the two rotations to the lower one. With this orientation, the lower sets of the partial order of rotations are the same as the closures of the orientation of this forest.
In the other direction, every oriented forest is a transitively-reduced acyclic graph, whose lattice of closures is the same as the lattice of lower sets of a partial order on its vertices in which when there is a directed path from to . Applying the construction of Theorem 4.1 to this lattice produces a graph in which each vertex of the forest is represented as a rotation, and in which the shared edges between these rotations correspond to edges of the forest. Gluing cycles together on shared edges in the pattern of a forest always produces an outerplanar graph, with glued edges interior and unglued edges on the outer face of its outerplanar embedding, as can be proved by induction on the number of gluing steps. ∎

Figure 9 shows that the assumption that the graph is subcubic is necessary for Theorem 4.3. Outerplanar graphs that are not subcubic may come from rotation systems whose transitive reduction contains a cycle, which would not be possible for orientations of forests.
4.4 Planar graphs
Finally, we turn to the lattices associated with planar graphs.
Theorem 4.4.
If a stable matching instance has a planar graph as its graph of stably matchable pairs, then its lattice of stable matchings is isomorphic to the lattice of closures of an oriented string graph. Every lattice of closures of an oriented string graph can be realized as the lattice of stable matchings of an instance whose graph of stably matchable pairs is planar and subcubic.
Proof.
If a stable matching instance has a planar graph as its graph of stably matchable pairs, find a planar embedding of it, and represent each rotation of the instance as the curve through its vertices and edges in the embedding. Every two rotations whose curves intersect are comparable in the partial order of rotations; if they intersect at an edge this is immediate while if they intersect at a vertex they are part of the totally ordered subset of rotations that pass through that vertex. Therefore, we may orient the string graph of the rotations by directing each edge from rotation to rotation whenever in the partial order of rotations; with this orientation, the lower sets of the partial order of rotations coincide with the closures of the oriented string graph.

In the other direction, let be an oriented string graph. By doubling and perturbing each curve if necessary we may assume without loss of generality that each of the curves defining is closed (although possibly self-crossing), that each point of the plane belongs to at most two arcs of curves (either of two different curves or two arcs of the same curve), and that each point belonging to two arcs is a simple crossing point of these arcs. Whenever a curve crosses itself we may remove short lengths of the two crossing arcs, within a small disk surrounding the crossing and disjoint from the other curves, and replace the removed arcs by two non-crossing arcs while preserving the connectivity of the curve; one of the two ways of choosing how to connect these arcs will always produce a curve that remains connected. Repeating this transformation produces a collection of curves with the same intersection graph but with no self-crossings (Figure 10, left). Similarly, whenever two curves that belong to the same strongly connected component of cross, we may replace their crossing by two non-crossing arcs in a way that merges the two curves into a single curve; one of the two ways of choosing how to connect these arcs will merge them. Repeating this transformation produces a collection of curves with the same partial order on the strongly connected components of the oriented string graph but with at most one curve per component (Figure 10, right). After these transformations we may assume without loss of generality that is acyclic (although not necessarily transitively reduced) and that each vertex of is represented by a simple closed curve in the plane. Because is acyclic, the join-irreducibles of its lattice of closures (which should correspond to the rotations of a rotation system representing this lattice) also correspond one-for-one with the curves in this arrangement. Whenever two curves cross, they correspond to two distinct comparable rotations.

If any curve of this system of curves has no crossings, replace it by a cycle of four vertices, drawn with its edges along the curve. For the remaining curves, again remove a small disk surrounding each crossing point, partitioning each curve into a sequence of arcs connecting these disks. Along each arc of a curve , draw a path of either three edges and four vertices (if the rotation corresponding to is above both of the rotations that it crosses at the ends of the arc, or below both of the rotations that it crosses) or two edges and three vertices (if the rotation is above one of the rotations that it crosses, and below the other one of these rotations, as illustrated in Figure 11 (center right). By this construction, if we were to add an edge in across each of the small disks, the result would be a cycle of even length; choose arbitrarily for each curve a bipartition of the vertices of this cycle into students and residencies.
At each of the small disks where a pair of curves cross, this construction creates two students and two residencies, in the cyclic order student–student–residency–residency around the disk. Merge the two students into a single vertex within the disk, merge the two residencies into a single vertex within the disk, and add an edge between them (Figure 11, far right). The result is a subcubic bipartite graph, embedded in the plane, and a rotation system for that graph whose rotations are the cycles following each curve of the string graph. The partial ordering on the rotations is the same as the ordering coming from the orientation of . Therefore, it has a lattice of stable matchings that realizes the lattice of closures of the given oriented string graph. ∎
An example of a graph that is not a string graph can be obtained by subdividing every edge of into a two-edge path. If these paths are all oriented towards their central degree-2 vertex, the resulting oriented non-string graph is transitively reduced and acyclic. Its lattice of closures cannot correspond to a planar graph of stably matchable pairs, because it is not itself an oriented string graph and it has no supergraph with the same closures.
5 Hardness
In this section we prove that testing whether a given planar subcubic graph is a graph of stably matchable pairs is NP-complete. Our reduction is from monotone planar 2-in-4-SAT, an NP-complete problem in which Boolean variables and clauses form a planar bipartite graph, each clause is adjacent to exactly four variables, and the task is to determine whether there exists a truth assignment to the variables for which each clause is adjacent to two true and two false variables [17]. Because the proof is complicated, we warm up with a simpler reduction, for nonplanar subcubic graphs, from not-all-equal satisfiability with three variables per clause (NAE3SAT) [28]. This problem takes as its input a collection of Boolean variables, and clauses each of which involves three terms (variables or their negations). The output is true when there is some way to assign truth values to the variables so that each clause involves at least one true term and at least one false term.
5.1 NAE3SAT reduction

In this section we sketch but do not formally prove our warm-up hardness reduction from (nonplanar) NAE3SAT instances to (nonplanar) subcubic bipartite graphs. We transform each term that appears at least once in a given NAE3SAT instance into a term gadget, a subgraph of what will eventually become a subcubic graph. A term gadget is just a simple cycle of even length, with the vertices alternating between students and residencies, and with the edges alternating between truth edges and terminal edges. Our overall construction will have the property that, when the resulting graph has a rotation structure, the truth edges will belong either to the top stable matching of the structure, , or to the bottom stable matching. When the truth edges belong to , this situation corresponds to a truth assignment that makes the term true, and when the truth edges belong to , the corresponding truth assignment makes the term false. The terminal edges are mostly used to connect to clause gadgets for the clauses that include the given term, but we will leave one of them unconnected, to force the truth edges to belong to either or , and we may also need an additional terminal edge to connect to the negation of the same clause.
For each clause in the given NAE3SAT instance, we construct a clause gadget, in the form of a subdivision of the graph of a cube. The graph of a cube is 3-regular, with 8 vertices. It has three perfect matchings formed by three parallel edges of the cube, and six perfect matchings formed by choosing two opposite square faces of the cube and matching the vertices within each of these two faces in a way that is not parallel to the matching in the opposite face. However, there are also eight three-edge matchings in the cube that are maximal but not perfect, obtained by removing two opposite vertices of the cube and finding a perfect matching in the remaining six-vertex cycle. Our clause gadget is obtained by finding one of these three-edge maximal matchings, subdividing each of its edges into a five-edge path, and choosing the middle edge of each of these paths as one of the three terminal edges of the gadget. The cube is bipartite and subdividing edges into odd paths does not change its bipartiteness, so we can find a bipartition of it and choose arbitrarily for one side of the bipartition to be students and the other side to be residencies.
The final type of gadget that we will use is a connector gadget, which we will use in two ways: to connect a term gadget for a variable to the term gadget for its negation (when both the variable and its negation appear as terms in the given NAE3SAT instance), and to connect term gadgets to gadgets for the clauses in which they appear as terms. A connector gadget consists of two paths, each of two edges, connecting the endpoints of one terminal edge to the endpoints of another terminal edge. One of the two paths connects the two student endpoints of the two terminal edges through a central residency vertex, and the other path connects the two residency endpoints through a central student vertex, ensuring that these added paths preserve bipartiteness. One of the two terminal edges should belong to a term gadget and the other should either belong to the gadget for the negation of the term or to a clause gadget.
The overall reduction, then, consists of constructing a term gadget for each term, a clause gadget for each clause, a connector gadget for each pair of terms that are negations of each other, and a connector gadget for each appearance of a term within a clause. The choice of which free edge or which terminal edge within each gadget to use for each connector edge is arbitrary, as long as each one is used at most once. These gadgets and the way they are connected are depicted in Figure 12.
The correctness of our reduction is based on the following analysis of our connection gadgets.
Lemma \thelemma.
Let be a connection gadget, and let and be three-edge paths in the term or clause gadgets connected by , with the center edge of each three-edge path being one of the terminal edges whose endpoints are connected by . Suppose that the graph produced by the reduction of Section 5.1 has a rotation system, and label the edges of the graph as top, bottom, or middle, according to whether they belong to the matchings or of the rotation system or to neither of these two matchings, respectively. Then one of paths or must have edges whose labels alternate between top and middle, and the other must have edges whose labels alternate between middle and bottom.
Proof.
Consider the sequence of matchings produced by starting at and then applying the rotations of the rotation system, one by one, in an ordering given by an arbitrary linear extension of the partial order of rotations, until reaching . Then to cover all three edges at each of the degree-three vertices of , the part of the matching within subgraph must change at least twice, passing through at least three distinct matchings, throughout this sequence. The first of these changes cannot pass through a degree-two vertex of , because after a change through such a vertex its matched edge can never change again, and this would prevent the degree-three vertex at the other end of that matched edge from changing to its third match. The only other possibility is that this first change is generated by a rotation that passes through , , or both, causing this path to alternate between bottom and middle edges.
Symmetrically, the last change to the subgraph , in this sequence of matchings, cannot pass through a degree-two vertex of , because the edge that this degree-two vertex was matched to before the change could not have changed in any previous step, preventing its degree-three vertex at its other end from having changed enough times to cover its three incident edges. Therefore, this last change also passes through or , alternating between top and middle edges. Since at least one of or must alternate between bottom and middle edges, and at least one of or must alternate between top and middle edges, exactly one of the two paths must alternate in each of these two ways. ∎

If is a graph constructed as in Section 5.1 from an NAE3SAT instance, and the NAE3SAT instance has a satisfying truth assignment, then we can construct a valid rotation system for by labeling the truth edges of variable gadgets as top or bottom edges according to the truth assignment, assigning all terminal edges to be middle edges, and propagating these labels to the remaining graph edges consistently with Section 5.1 and with the requirement that each degree-two vertex have adjacent labels top and bottom and that each degree-three vertex have all three labels adjacent to it. Figure 13 shows the results of propagating these constraints on labelings from a variable gadget to nearby edges. The satisfaction of each clause in the truth assignments allows this propagation to be completed uniquely within each clause gadget. The resulting labeling corresponds uniquely to a collection of cycles in which pairs of adjacent edges alternate between the closest higher label (bottom to middle or middle to top at a degree-three vertex, bottom to top at a degree-two vertex) and the closest lower label (defined symmetrically). These cycles have a partial ordering with the central cycle of a true vertex gadget as the topmost elements, cycles in connector gadgets to true vertex gadgets next, cycles within clause gadgets in the middle, cycles in connector gadgets to false vertex gadgets second-to-last, and the central cycles of false vertex gadgets last. Within each clause gadget the partial ordering (on the two alternating cycles within the gadget) is the same as in a cube graph with the same labels, using the outermost label of each subdivided edge as the label for the corresponding unsubdivided edge in a cube graph. Therefore, when the NAE3SAT instance is satisfiable, has a rotation system.
Conversely, when has a rotation system, Figure 13 shows that the term gadgets have truth edges that must be labeled consistently according to some truth assignment. The constraints on edge labels at degree-2 and degree-3 vertices imply that the labels on the connector gadgets and the subdivided edges of clause gadgets must be as shown in Figure 13. And in order for the rest of the clause gadget to have a consistent labeling, each clause must be satisfied, for an unsatisfied clause would have a clause gadget with all three subdivided edges labeled the same way, preventing or from being completed to a perfect matching within that gadget. Therefore, when has a rotation system, the NAE3SAT instance is satisfiable.
Although this is enough to prove NP-completeness of recognizing subcubic graphs of stably matchable pairs, it does not prove the stronger result that we have claimed, NP-completeness for planar subcubic graphs. There are several difficulties that we must overcome in order to prove this stronger result.
-
•
Although our clause gadgets (subdivided cubes) are planar graphs, the terminal edges by which they connect to the rest of the reduction do not all lie on a single face of their planar embedding, causing the overall reduced graph to become nonplanar even when starting with a planar instance of NAE3SAT. Therefore, we need alternative clause gadgets that accomplish a similar function while preserving planarity.
-
•
Planar NAE3SAT is not a hard problem; it has a polynomial-time algorithm. So we cannot merely replace the clause gadgets of our NAE3SAT reduction; we need a different hard problem. Realizability by stable matchings has an inherent symmetry (swapping and and reversing the partial order on rotations preserves the validity of a rotation structure), and this symmetry is reflected in the symmetry of inverting all truth values in NAE3SAT. For our planar reduction, we have chosen 2-in-4-SAT, which is also symmetric under truth value inversion, but has more complicated clauses with four terms instead of three.
-
•
Our NAE3SAT reduction preserves the bipartiteness of the resulting graph by leaving a choice free for each connection gadget, of which pairs of vertices to connect by paths. One of the two choices can be used, regardless of previously made choices of which of the connected vertices are students and which are residencies. But if the resulting graph is to be planar, we do not have this freedom, because one of these two choices will introduce an undesired crossing. Instead we must make sure that when all the gadgets we are connecting have their bipartitions chosen consistently. This is already a problem for the term gadgets in our NAE3SAT reduction, because when we use a connector gadget to connect a term and its negation, and embed the resulting planar graph, the two terms will be oppositely oriented (one with students clockwise from residencies on its terminal edges, the other with students counterclockwise from residencies). So we need a gadget that, like the connector gadget, can reverse the truth value associated with a connection, but without inverting its orientation.
-
•
In our NAE3SAT reduction, partially ordering the rotations was aided by the fact that the term gadgets are inherently acyclic (either maximal or minimal in the partial order of rotations, rather than having both predecessors and successors in the partial order). This might not be true for other gadgets; for instance, it is not true of the clause gadgets. So if other gadgets are to be connected together we need to take care that yes-instances have rotations that can be partially ordered. On the other hand, as we will see, the possibility that a collection of cycles might fail to be a rotation system by having a cycle in its ordering can lead to new opportunities for constraining the behavior of gadgets.
5.2 More gadgets

We will re-use the term gadgets and connection gadgets from the NAE3SAT reduction, as analyzed using Section 5.1. As in that reduction, gadgets will be connected to each other at terminal edges; to preserve planarity, we will usually require these terminal edges to be on the outer face of an embedding of each gadget. To handle the issue that the two paths of a connection gadget cannot cross, we will define the polarity of a terminal edge to be either clockwise or counterclockwise, the direction around the outer face of the gadget followed by orienting the terminal edge from its student endpoint to its residency endpoint. The polarity of all terminal edges of a single gadget can be reversed by taking the mirror image of the gadget, but it cannot be changed for individual terminal edges without changing the polarity of all other terminal edges of the same gadget. All terminal edges of a term gadget have the same polarity as each other, but the two edges of a connector gadget have opposite polarity.
We add to these the following repertoire of gadgets and combinations of gadgets.
- The switch gadget.
-
This is, essentially, a connection gadget with its paths extended by two more edges, allowing the interior edges of the paths to function as terminal edges to which another connection gadget can be attached, at the points marked as and in Figure 14. In turn, the switch gadget connects to the terminal edges from two other gadgets. Following the same analysis as Section 5.1, these two other gadgets must have rotations ( and in the figure) that pass through their terminal edges, one of which is earlier than the central cycle of the switch gadget in the partial ordering of rotations, and the other of which is later. The key behavior of the switch gadget is to control the relative orderings of these two rotations: if the incoming connection gadget at has top edges at the ends of its paths, then the path within the switch gadget must have edges labeled (in order from to ) bottom-middle-bottom-top, forcing to be earlier than in the partial order of rotations. If the connection gadget attached to has bottom edges at the ends of its paths, then symmetrically must be earlier than in the partial order of rotations.
To achieve this behavior, only one of the two terminal edges and needs to be attached to a connection gadget. If both are attached to connection gadgets, then both connection gadgets are forced to have the same state, which can be used to propagate information from one side of the switch gadget to the other. In some ways this is like a crossover gadget in some other planar NP-completeness proofs, but unlike a crossover gadget there are not two independent bits of information crossing each other: the partial ordering of and carries the same information as the state of the connection gadgets at and .
If terminal edge is unused, the path containing it can be shortened to two edges without affecting the behavior of the rest of the gadget.
Figure 15: The fuse gadget and two of its four rotation systems. The other two are obtained from the two shown by swapping the top and bottom matchings and reversing the order of the rotations. - The fuse gadget.
-
This is obtained from a grid by subdividing some of its edges into paths of odd lengths, whose degree-two vertices force the subdivided paths to use only top and bottom edges. The unsubdivided grid has rotation systems consisting of the three faces of the grid, in some order, but the subdivision prevents these rotation systems from being valid. Instead, the remaining four rotation systems are of two types, as shown in Figure 15.
We will always attach switch gadgets to the terminal edges of the fuse gadgets. To understand the behavior of a fuse gadget, suppose that one of its two attached switch gadgets connects a rotation (at its other end) to a rotation within the fuse gadget, in an ordering controlled by a connection gadget at terminal edge . Suppose symmetrically that the other attached switch gadget connects a rotation within the fuse gadget, to a rotation at its other end, in an ordering controlled by a connection gadget at terminal edge .
Two of the rotation systems for the fuse gadget (including the one shown in the central part of the figure) use the outer boundary of the grid as one of the rotations, and the center face of the grid as the other rotation, causing one of the two terminal edges to be upper and the other to be lower in the same rotation as each other. The outer rotation will act as both and for the two attached switch gadgets, while the inner rotation is separated from the switch gadgets. When connection gadgets and have the same state, exactly one of these two rotation systems will be valid, producing one of two transitive orderings of rotations: , or . Intuitively, when the switch gadgets are both switched in the same direction, the fuse gadget transmits the ordering relation from one switch gadget to the other.
The other two rotation systems for the fuse gadget are the one shown on the right of the figure and its reverse. When the two attached switch gadgets are switched in opposite directions, one of these two rotation systems will be valid within the fuse gadget, and there will be no order relation between and caused by these gadgets.
Figure 16: Planarity-preserving four-input not-all-equal gadget, constructed from a cycle of four switch gadgets and four fuse gadgets. - Planar not-all-equal gadgets.
-
We can construct a not-all-equal gadget with any number of inputs by connecting switch gadgets and fuse gadgets in a cycle, as shown in Figure 16. Because both switch gadgets and fuse gadgets reverse the polarity of the two terminal edges that they attach to, the result is bipartite even when is odd, and all of its free terminal edges (the terminal edges used to connect connector gadgets to switch gadgets) have the same polarity as each other.
When the connector gadgets attached to these switch gadgets all have the same state (all edges at the attached ends of their paths labeled as top, or all labeled as bottom), the combined behavior of the switch and fuse gadgets will cause the not-all-equal gadget to have a cycle in its ordering of rotations, preventing a valid rotation structure from existing. When not all connector gadgets have the same state, this cycle will be broken at the fuse gadget between each two consecutive connectors that have unequal states, allowing the existence of a valid and partially ordered set of rotations within this part of the overall graph.
- Inverter gadget.
-
In our NAE3SAT reduction, we used connector gadgets between pairs of a term gadget and its negation, which in this application acted as an inverter: if the edges at one end of a connector gadget’s paths are labeled as top, the edges at the other end are labeled as bottom. However, a connector gadget also reverses the polarity of its two terminal edges, which may be problematic in some of our constructions. We may obtain an inverter that does not reverse polarity as a special case of our not-all-equal gadget with two inputs (a cycle of two switch gadgets and two fuse gadgets).
In any valid rotation system involving the inverter gadget, the cycles within the two switch gadgets will have no ordering relation to each other, because they are isolated from each other by the fuse gadgets between them and by the requirement that the two switch gadgets be ordered in opposite directions at each fuse gadget. Therefore, it is possible to use this gadget without any concern that there may be additional ordering relations on rotations transmitted through the connection gadgets attached to it.
- Insulator gadget.
-
As discussed above, the inverter gadget attaches to two connector gadgets that must have opposite states, and breaks any ordering relation that might have been created between rotations at the other ends of these two connectors. It is useful to have a gadget that, similarly, attaches to two connector gadgets that must have equal states, and breaks any ordering relation that might have been created between rotations at the other ends of these two connectors. This can be accomplished by using a term gadget with two terminal edges (not counting its unconnected terminal edge).
5.3 Nested gadget cycles for arbitrary inversion-symmetric clauses
By combining the simpler gadgets above, we have a general construction for gadgets that can represent any logical function that is symmetric under the inversion of the truth values of all its variables (as the not-all-equal function is). As in our NAE3SAT construction, define a truth edge of a gadget to be an edge adjacent to a terminal edge, which (in all rotation systems for all our gadgets) must be either part of the top or bottom matching, and define such an edge to correspond to a Boolean value, true if it belongs to the top matching and false if it belongs to the bottom matching.
Lemma \thelemma.
Let be a nontrivial Boolean function of any number of Boolean variables, with the property that inverting all variables does not change the value of . Then there exists an embedded planar subcubic bipartite graph , with designated terminal edges of equal polarities and degree-2 endpoints on the outer face of its embedding, corresponding to the variables of , with the following property. For every truth assignment to the variables of , and every corresponding labeling of the truth edges of as belonging to the top or bottom matchings of a rotation system, is true for the given truth assignment if and only if has a rotation system extending the given labeling. Further, whenever a truth assignment corresponds to a rotation system, the rotation system can be chosen in such a way that there are no order relations in its partial order between any two rotations containing terminal edges.
Proof.
For Boolean variables , there are complementary pairs of truth assignments, some of which cause to become true and some of which cause it to become false. We prove the result by induction on the number of pairs of truth assignments that cause to become false. As a base case, when there is only one forbidden truth assignment, we may use the not-all-equal gadget of Figure 16, with each of its terminal edges attached by a connector gadget to either an inverter gadget or an insulator gadget. The choice of whether to attach an inverter or insulator can be made by choosing an insulator for variables that have the same value as in the forbidden truth assignments, and an inverter for variables that have the opposite value to . The not-all-equal gadget itself is unrealizable only for the all-equal truth assignment, and this choice of inverter gadgets instead causes the graph to become unrealizable only for the single forbidden truth assignment of . The use of inverter and insulator gadgets at every terminal edge of the central not-all-equal gadget prevents rotation systems for this graph from having order relations between the rotations containing its terminal edges.

When has more than one forbidden truth assignment, choose one of them, let be the function forbidding only that truth assignment, construct a graph for it as above, and let be the Boolean function formed from by changing its value to true on the forbidden assignment for and then complementing its variables in the same pattern that was used for the inverters in the construction of . By induction, construct a graph corresponding to the function , and embed inside the central face of , attached by connector gadgets to the inner terminal edges of the switch gadgets of . Figure 17 shows this construction for the 2-in-4 function , which forbids five of the eight complementary pairs of truth assignments to its four Boolean variables (the pair of all-equal assignments, and four pairs of assignments that set one of the four variables opposite to the other three). The figure omits the outermost layer of insulator gadgets, as they are unnecessary when this 2-in-4 gadget is incorporated into our overall reduction.
In the resulting graph , each connection gadget, switch gadget, inverter gadget, and insulator gadget has two terminal edges, whose adjacent truth edges can be labeled in only one way consistent with the labeling at the outer terminal edges of : at each connection gadget, switch gadget, or insulator gadget, the two terminal edges must have the same labeling at their incident truth edges, while at an inverter gadget the labels must be opposite. This labeling determines the structure of the rotations within all of these gadgets, leaving only the fuse gadgets undetermined. For a truth assignment that satisfies , all of the cycles of switch and fuse gadgets in will have at least two consecutive switch gadgets with opposite states, breaking the potential cyclic ordering of rotations at the fuse gadget between these two switches and producing a valid rotation system for meeting all the conditions of the lemma. For a truth assignment that does not satisfy , one of the cycles of switch and fuse gadgets, the one corresponding to the complementary pair including that assignment, will have all four of its switch gadgets in the same state. In this case, the only locally-valid edge labeling to the switch and fuse gadgets of this cycle produces a cyclically-ordered set of rotations, so there is no valid global rotation structure. ∎
5.4 The overall reduction
Theorem 5.1.
It is NP-complete, given a bipartite graph , to determine whether there exists a stable matching instance for which is the graph of stably matchable pairs, even when is planar and subcubic.
Proof.
To show that recognizing graphs of stably matchable pairs belongs to NP, we may either use a preference system for the stable matching instance as a witness, with a verification algorithm that constructs the rotation system from the preference system and checks that its graph equals , or we may use a rotation system directly as a witness, with a verification algorithm that checks that it meets the definition of a rotation system and has as its graph.
To show that the problem is NP-hard, we find a polynomial-time many-one reduction from the known NP-hard monotone planar 2-in-4-SAT problem to the problem of the theorem. This reduction finds a planar embedding of the given monotone planar 2-in-4-SAT instance, replaces each variable of the instance by a term gadget, replaces each 2-in-4 clause of the instance by a 2-in-4 clause gadget according to Section 5.3 and Figure 17, and replaces each connection between a variable and a clause in the planar embedding of the instance by a connection gadget, attached to the terminal edges of the term and clause gadgets in the cyclic ordering given by the planar embedding.
When the 2-in-4-SAT instance has a satisfying truth assignment, this assignment may be reflected to a labeling of the truth edges of the term gadgets as being top or bottom edges, and this labeling propagated to the remaining gadgets as described in Section 5.3, producing a collection of rotations that are locally partially ordered and that have no nonlocal transitive relations in their ordering. The result is a valid rotation system for the reduced graph. Conversely, when the reduced graph has a rotation system, the truth edges of the term gadgets must be consistently labeled according to a valid truth assignment, and the unique consistent propagation of this labeling to the other gadgets, as described in Section 5.3, can only produce a value rotation system when this truth assignment satisfies all the clauses, so the starting 2-in-4-SAT instance is satisfiable.
We have described a polynomial-time many-one reduction from monotone planar 2-in-4-SAT to recognizing planar subcubic graphs of stably matchable pairs, and we have shown that recognizing arbitrary graphs of stably matchable pairs belongs to NP, so both the recognition problem for arbitrary graphs and its special case for subcubic planar graphs are NP-complete. ∎
Because recognizing graphs of stably matchable pairs is trivial on cubic graphs (Section 3.1) but hard on subcubic graphs, it provides another answer to a 2012 question of Vinicius dos Santos, who asked for natural problems that are polynomial on cubic graphs but NP-complete for subcubic graphs [6].
6 Exact algorithms

Although recognizing the graphs of stably matchable pairs is NP-complete, it may still be possible to find algorithms for this problem that are faster than a naive brute force search through all preference systems. We provide two such algorithms. Our first algorithm, for arbitrary graphs, runs in time where is the number of edges, improving the time bound that one would obtain from a brute force search (see Figure 18). Our second algorithm shows that recognizing the graphs of stably matchable pairs is fixed-parameter tractable for graphs of bounded carving width, and takes linear time in such graphs (with a constant factor depending exponentially but not singly-exponentially on the carving width).
We will assume, as is standard for the design and analysis of algorithms, the unit cost model of computation in which arithmetic and Boolean operations on binary values within a single machine word, and operations that access a single machine word of computer memory, take constant time. We will also necessarily assume that each machine word stores enough bits to address the amount of memory needed for our algorithms. For algorithms whose storage requirements are exponential in the input size, this means that the entire input may be assumed to fit into a machine word or a small number of words. It is not reasonable to intrepret this as suggesting the existence of computers whose word size grows with the problem input size; instead, our assumptions should be interpreted as meaning that (as is generally true in practice) our algorithms can only be applied to inputs small enough that they do not overflow the available memory. However, the choice between these two interpretations makes no difference to the mathematics of the problem.
6.1 Singly exponential in the number of edges
Our singly exponential time and space bounds will depend on the following analysis of matching-related structures in graphs.
Lemma \thelemma.
Let be a type of structure associated with a graph, and let be a constant, such that a graph with edges has structures of type . Let denote the maximum number of pairs of a perfect matching and a structure of type in the subgraph of unmatched edges, maximized over graphs with edges. Then , where is at most and can be upper-bounded as
Proof.
By the binomial theorem, the number of structures consisting of a set of edges, together with a structure of type within that set, is
The bound follows by considering the set of edges in such a structure to be the set complementary to a perfect matching.
To get the more precise bound of the lemma, we can list structures formed as a perfect matching plus a structure of type by the following algorithm: repeatedly find a vertex of minimum degree in the current graph, and loop over its incident edges. For each such edge , recursively call the same algorithm in the subgraph formed by removing the two endpoints of and all their incident edges. If the recursion ever finds a vertex of degree zero, it returns without listing anything (as the choices made in this branch of the recursion do not lead to a perfect matching). Otherwise, the bottom-level calls to this algorithm (in which the remaining subgraph is empty) have each found a perfect matching, and list all structures of type (in an unspecified way) in the subgraph of removed but unmatched edges.
At a recursive call of this algorithm where the minimum degree is , the number of unmatched removed edges that will be considered later in listing structures of type is at least , and the total number of removed edges is at least , explaining the two exponents in the formula of the lemma. (The cases where more than this number of unmatched edges are removed produce similar terms with greater exponents, but they can be omitted from the formula as they cannot produce the maximum value of the overall formula.) By choosing as upper-bounded by the formula of the lemma, it follows by induction on that the total number of structures found by this algorithm is as stated. ∎
We observe that in cases where the structures of type can be efficiently enumerated (for instance when they are just subsets, as below) the proof of the lemma can be made into an algorithm whose running time is obtained by replacing the bound on the number of structures of type by the running time for enumerating these structures.
Lemma \thelemma.
A graph with edges has at most perfect matchings, where
This bound is tight for a graph consisting of disjoint copies of .
Proof.
This follows from a result of Alon and Friedman [1] according to which the number of perfect matchings in a graph with degree sequence is at most . In a graph with edges, there are vertex-edge incidences, which can be grouped in various ways to vertices of varying degrees. According to the formula of Alon and Friedman, an incidence that participates in a vertex of degree contributes a factor of to the total bound on the number of matchings. This factor is maximized at degree three, for which it is . If each vertex-edge incidence participates in a vertex of degree three, maximizing the contribution to the product from every incidence, then the total product is as stated. ∎
It is not possible for all matchings of to be stable so this provides an upper bound but not a tight bound on the number of stable matchings as a function of .
Lemma \thelemma.
In a graph with edges, the number of structures consisting of a perfect matching and an arbitrary subset of the remaining edges is , and the number of structures consisting of two perfect matchings (not necessarily disjoint) and an arbitrary subset of the remaining edges is , where
and
Proof.
The bound on follows from Section 6.1, counting matchings plus a structure consisting of an arbitrary set of edges, with . Calculation shows that the maximum value for the upper bound in the lemma is achieved at , giving the value shown.
The bound on follows by using the same minimum-degree algorithm from the proof of Section 6.1 to choose a matching and a disjoint set of edges, and then applying Section 6.1 to bound the number of matchings in the set of edges that were not chosen to be included in the disjoint set of edges. Each matched edge or unmatched but unchosen edge contributes a factor of to the total number of structures found by this combination of bounds. When the minimum vertex has degree and all its neighbors, this produces a contribution per removed edge of , almost the same as if we were applying Section 6.1 with . Here, the first factor of comes from the application of Section 6.1 to the edge that was chosen to be in the matching, and the factor of comes from applying the binomial theorem to the choice of edges to be part of the disjoint set and to the factor of that will be included when an edge is not chosen. When the minimum vertex has degree but some of its neighbors have higher degrees, the leading factor in this formula is averaged over a greater number of edges each contributing a factor of , leading to a more complicated calculation but a lower contribution per removed edge than for the case of equal degrees. Calculation shows that the maximum value for this upper bound is achieved for a vertex with neighbors of equal degree, at , giving the value stated in the lemma. ∎
Theorem 6.1.
We can test whether a given graph with edges and vertices is a graph of stably matchable pairs in space and time , where and are the numbers from Section 6.1.
Proof.
We will search for a sequence of perfect matchings, differing from one to the next in the sequence by a single rotation, that together cover all edges of and such that each edge of is rotated into a matching at most once and rotated out of a matching at most once. If such a sequence exists, we can produce a rotation structure that has the first matching in the sequence as its bottom matching, the last matching in the sequence as its top matching, and the rotations of the sequence as the rotations of the rotation structure, partially ordered consistently with the sequence order.
We search for this sequence as a path in a graph whose vertices are pairs where is a perfect matching and is any subset of the unmatched edges. (This is essentially a dynamic programming algorithm but we find it more convenient to describe it as a graph search.) In our search, we will use to represent the matching at the current endpoint of a partial sequence of matchings of , and to represent the edges that have already been covered by matchings earlier in the partial sequence. We make an edge in from vertex to vertex when matchings and differ by a single rotation, when , and when . With this definition, paths in automatically correspond to sequences of matchings that never re-use any edges: an edge, once used, gets added to and its presence there and the requirement that be disjoint from prevent later matchings in the sequence from re-using it. Therefore, the sequences we seek are exactly the paths from any vertex of the form to any other vertex of the form . We can find such a path by breadth first or depth first search of , starting from the vertices and terminating whenever a vertex of the form is reached.
By Section 6.1, has vertices and edges. It remains to describe how to construct and search it in a space-efficient way, bearing in mind that we do not want to use the amount of memory it would require to store all the edges of . We have enough memory that (by the assumption that machine words are large enough to store a single memory address) we can store a single matching or a single set of edges in a single word, and perform set operations like unions and intersections of these sets in constant time per operation. We will index the vertices of by consecutive integers in the range from to . Based on these indexes, we store the following information:
-
•
An array , addressed by vertex index, of the pairs of structures associated with vertex .
-
•
An array , addressed by vertex index, of the predecessor of vertex in the first path to reach that vertex found by the search, or a special flag value to indicate that it has not yet been reached.
-
•
An array of indexes of vertices on the current frontier of the search, arranged either as a stack for depth first search or a queue for breadth first search.
-
•
An array of Boolean values indexed by sets of edges, true when that set of edges is a simple cycle and false otherwise.
-
•
An array of lists indexed by sets of edges, listing the matchings disjoint from in sorted order, together with the vertex index for for each matching.
Array takes space to store, and the remaining arrays (including the total length of the lists in take space . Initializing can be accomplished in linear time using the structure enumeration algorithm of the proof of Section 6.1. Array is easily initialized to contain only flag values, and is initialized to list all vertices of the form . Initializing can be done by a naive algorithm that tests each set for being a cycle, in time , smaller than our stated time and space bounds. can be initialized by using to count how many matchings are associated with each disjoint set in order to allocate storage for the lists within , using a second pass over to place matchings into lists, and then sorting each list.
Each step of the search of is obtained by removing a vertex of from the search frontier , terminating the algorithm if , otherwise looping through the neighbors of in , and for each previously-unreached neighbor setting its predecessor in and adding it to the frontier . It remains to describe how to find the outgoing neighbors of a vertex of , since these are not explicitly represented by the data structures described above (and storing them explicitly would use too much space). We do this simply by using to find all of the matchings disjoint from , performing set operations on and to find their symmetric difference, and using to check that this symmetric difference is a simple cycle. When it is, we have found a neighbor of in , with . We can find the vertex index of this neighbor by a binary search in the list for of . The bottleneck of the algorithm is performing these binary searches; each takes time and the number of searches performed is .
The alternative space and time bounds of and , which are better for dense graphs, follow from the same algorithm (with a preprocessing stage that eliminates vertices of degree less than two) using a more naive analysis in which we count pairs of a matching and a disjoint set, or two matchings and a disjoint set, by bounding the number of matchings by and the number of disjoint sets by two to the power of the number of unmatched edges. ∎
By combining this algorithm with a kernelization algorithm that removes isolated vertices or edges, immediately halts if there are other degree-one vertices, and compresses all paths of degree-two vertices to paths of the same parity with one or two degree-two vertices, we would also obtain an algorithm that is fixed-parameter tractable in the number of vertices of degree greater than two. However, this is subsumed by the results of the next section, in which we show that the problem is fixed-parameter tractable in the carving width of the input graph.
6.2 Carving width
In this section we parameterize the recognition of graphs of stably matchable pairs by carving width. The precise definition of carving width involves hierarchical clusterings of the vertices of a graph so that each cluster boundary is crossed by a small number of edges, but we do not need the details for this section; instead, it suffices to know that for graphs of treewidth and maximum degree , the carving width is bounded below by and bounded above [8]. Therefore, we can equivalently think of the graphs of small carving width as being graphs that simultaneously have small treewidth and small maximum degree.
As is standard for fixed-parameter tractable algorithms involving treewidth, our treewidth-parameterized algorithm for recognizing graphs of stably matchable pairs uses dynamic programming on a tree decomposition, a tree whose nodes are associated with sets of vertices of the given graph (called bags), with the constraints that every edge of the graph has both endpoints in at least one bag and that the bags containing any given vertex of the graph are associated with the nodes of a connected subtree. The width of the decomposition is one less than the number of vertices in its largest bag, and the treewidth of the graph is the minimum width of a tree decomposition. It will be convenient to use a nice tree decomposition, in which the tree of bags is rooted and each bag has one of three types [5]:
-
•
An introduce node is either a leaf node whose bag contains a single vertex, or a node with exactly one child whose bag is formed by adding one vertex to its child’s bag.
-
•
A forget node is a node with exactly one child whose bag is formed by removing one vertex from its child’s bag.
-
•
A join node has exactly two children, with the bags of it and its children all being equal.
Each vertex can be introduced in many introduce nodes, but forgotten only from one, which must be the parent of the common ancestor of the introduce nodes. It will be convenient to introduce one more type of node, an edge node, associated bijectively with a specific edge in the given graph whose endpoints belong to the bag of the edge node. In this way, each node of the tree decomposition can be associated with a unique subgraph of the given graph, the subgraph whose edges and vertices are associated with the given node and its descendants. By introducing additional forget nodes we may assume without loss of generality that the root of the tree has an empty bag; its associate is the whole graph. We describe a tree decomposition that meets these minor modifications to the usual definition of a nice tree decomposition as a good tree decomposition.
Minimum-width tree decompositions can be found in time linear in the number of vertices of an input graph but exponential in the cube of the width [3]; it is also possible to find an approximate tree decomposition whose width is within a constant factor of minimum, in time linear in the number of vertices of the input graph and single-exponential in the width [4]. An arbitrary tree decomposition can be transformed into a nice tree decomposition of the same width, blowing up the number of nodes by a factor polynomial in the width, in time linear in the number of vertices of the graph and polynomial in the width [5]. Adding edge nodes between the highest node whose bag contains both endpoints of each edge and the forget nodes above them introduces a number of nodes which is again linear in vertices and polynomial in width, within the same time bounds.
Our dynamic programming algorithm will consider two different kinds of partial information about a rotation system for the given graph, restricted to the subgraph associated with a node of a nice tree decomposition, which we call a rotation subsystem and a rotation state. A rotation subsystem completely describes the part of a rotation system within the subgraph associated with a node, while a rotation state describes only the parts of the rotation system involving the vertices of the current bag. A rotation subsystem and a rotation state are compatible when the rotation state is obtained from the rotation subsystem by forgetting the information about vertices that are not in the bag. For a given node of the tree decomposition, let denote the subgraph associated with that node, denote the set of vertices of the bag associated with that node, denote the set of forgotten vertices, and denote the part of having both endpoints in . More specifically, a rotation subsystem for a node consists of the following information:
-
•
Top and bottom matchings and in which all vertices of are matched, but vertices of may or may not be matched.
-
•
A collection of rotations, an abstract partially ordered set whose elements will represent the subset of rotations of the rotation system that include at least one edge of .
-
•
A collection of pieces of rotations, the intersections of rotations with . Each piece is either a full cycle, or a connected path whose endpoints both belong to . Each two pieces of the same rotation must be disjoint. A rotation can either have a full cycle as its piece or one or more paths as pieces, but not both.
Each edge in the subgraph associated with a node must be part of two elements (either pieces or or ), and be upper in one and lower in the other (as determined by the partial order of the rotations). Each piece must alternate between upper and lower edges. We do not require that this structure can be extended to a full rotation system, in general; however, we have:
Observation \theobservation.
A rotation subsystem at the root node of a good tree decomposition coincides with a rotation system for the given graph.
Proof.
Rotation subsystems differ from rotation systems in allowing pieces of rotations that are paths rather than cycles, and in allowing the bag vertices to be unmatched in and . But because the root node of a good tree decomposition is assumed to be empty bag, these differences are not possible at that node. ∎
We define a rotation state at a node of the tree decomposition to consist of the following information, corresponding to the information in a rotation subsystem but restricted to bag vertices. Then a rotation state for consists of:
-
•
Top and bottom matchings and in , together with two bits of information for each remaining bag node specifying whether it has a match in or .
-
•
A collection of rotations, an abstract partially ordered set whose elements will represent the subset of rotations of the rotation system that either include at least one edge of or at least one piece that is a path with an endpoint in . Because of the assumption that the input graph has low degree, the number of rotations in this collection will also be low.
-
•
A collection of pieces of rotations. For each piece we store the rotation that it is part of, the edges of the piece that belong to , and the endpoints of the piece in , but not the edges in the rest of . At each endpoint in , we store whether the edge of the piece that is incident to that endpoint is an upper or lower edge in its rotation.
We require that each edge of belong to two elements (either pieces or or ), and be upper in one and lower in the other, and that when two edges of are consecutive within a piece that they alternate between upper and lower. We do not require that this structure can be extended to a rotation subsystem for the same node of the tree decomposition, but we call it valid when it can be so extended.
Lemma \thelemma.
In a tree decomposition of width for a graph of degree , the number of possible rotation states is at most exponential in .
Proof.
Because each piece of rotation represented within a rotation state uses at least one of the incident edges at one of the vertices of , there can be at most pieces, and rotations. The partial order on rotations can be represented using bits of information, the top and bottom matchings in require bits of information, and the information about which rotation pieces belong to which rotations, which bag vertices are endpoints of which pieces, and whether the incident edges are upper or lower, all take bits of information. ∎
Our overall algorithm will construct a tree decomposition and then work bottom up through its nodes, calculating at each node the set of valid rotation states. To do so, it uses the following lemmas, which describe the sets of valid rotation states for each possible type of node in our decomposition, and allow each set to be computed in an amount of time that is exponential in a polynomial of the carving width, but independent of the overall graph size.
Lemma \thelemma.
At an introduce node of the tree decomposition, with child , a state is valid if and only if the vertex that is introduced at does not take part in any pieces of rotations, is marked as not matched in and , and the state formed by removing from vertex is valid for .
Proof.
If is valid, it has a rotation subsystem for , which cannot use vertex in any rotation or in the top or bottom matching because has no edges in . Therefore, removing produces a rotation subsystem for , showing that is valid. Conversely, if is valid, it has a rotation subsystem for Adding to this subsystem without changing its rotations or pieces produces a rotation subsystem for , in which is unmatched, showing that is valid. ∎
Lemma \thelemma.
At a forget node of the tree decomposition, with child , a state is valid if and only if the vertex that is forgotten at does not take part in any pieces of rotations, and there exists a valid state formed from by adding to , marking it as matched in both and , and possibly adding an edge incident to in to or .
Proof.
If is valid, it has a rotation subsystem for , which cannot have vertex as the endpoint of a piece of a rotation because does not belong to . Because belongs to , it must be matched in both and in this rotation subsystem. The same rotation subsystem exists for , and corresponds to a state that meets the conditions of the lemma. Conversely, if a state as described in the lemma exists, it has a rotation subsystem, which matches in both and . This matching is the only additional requirement for a rotation subsystem at , so there is a rotation subsystem at showing that is valid. ∎
Lemma \thelemma.
At an edge node which introduces edge as the only edge of graph , a state is valid if and only if one of the following three conditions is met:
-
•
Edge is included in , vertices and are marked as matched in and unmatched in , and there are no rotations or pieces of rotations.
-
•
Edges is included in , vertices and are marked as matched in and unmatched in , and there are no rotations or pieces of rotations.
-
•
Edge is not included in or , vertices and are marked as unmatched in both and , and there is a single rotation having a single piece, consisting of this edge, marked as either upper or lower.
Proof.
In each case , so rotation subsystems coincide with rotation states, and these are the only possible rotation subsystems for a single-edge graph. ∎
The next lemma lets us reduce the analysis of edge nodes more generally to be a special case of join nodes.
Lemma \thelemma.
At an edge node with child which introduces edge to a non-empty subgraph , a state is valid if and only if it would be valid for a join node with the same bag as whose two children are and an edge introducing as the only edge in its subgraph.
Proof.
Validity of a rotation state at a node depends only on and , and for the nodes described in the lemma we have and . ∎
Lemma \thelemma.
At a join node with children and , a rotation state is valid if and only if there exist valid states for and for such that:
-
•
The matchings and in are disjoint unions of the corresponding matchings in and , and the sets of matched vertices in and in are disjoint unions of the corresponding sets of matched vertices in and .
-
•
The rotations in are a union (not necessarily disjoint) of the rotations in and , with the partial order on these rotations in and equalling the restriction to those subsets of the partial order on rotations in .
-
•
Each piece of a rotation in is formed as a concatenation of one or more pieces of rotations in and , all pieces of rotations in and are used to form pieces of rotations in this way, and at each point of concatenation the two concatenated pieces alternate between an upper edge and a lower edge.
Proof.
If is valid, it is associated with a rotation subsystem, and restricting that subsystem to and produces two subsystems with disjoint matchings and , each having a subset of the rotations with a restriction of the partial order on rotations, and each having pieces of rotations that are subsets of the pieces of rotations in the subsystem for . It follows that the rotation states and associated with those restricted rotation subsystems are valid and meet the conditions of the lemma. Conversely, if valid rotation states and meeting the conditions of the lemma exist, then they each are associated with rotation subsystems for and that can be combined together in the obvious way to produce a rotation subsystem for , showing that is valid. ∎
Theorem 6.2.
For a graph with vertices and carving width , we can test whether is a graph of stably matchable pairs in time linear in and exponential in .
Proof.
We can find a good tree-decomposition of width in the stated time bound. A graph with width has edges, so there are edge nodes in the tree-decomposition. We may eliminate any join nodes in which one of the two sides of the join has no edges, without change to the validity of the decomposition, leaving a decomposition that also has join nodes and (as for any nice tree decomposition) forget nodes. Removing the forget nodes and join nodes partitions the tree-decomposition into subtrees within which there can be at most introduce nodes, so there can be at most introduce nodes total.
Because has carving width , its treewidth and maximum degree are both , so by Section 6.2 the number of states at each node of this decomposition is exponential in . By the lemmas above, we can compute the set of valid states at each node by an algorithm that examines each valid state at the child node (when there is one child) or each pair of valid states at the two children (when there are two children), in an amount of time per state or pair of states that is polynomial in . Therefore the total time per node is bounded by this polynomial multiplied by the square of the number of states, which remains exponential in . ∎
7 Conclusions and open problems
We have investigated the graphs of stably matchable pairs of stable matching instances, with results including the characterization of special classes of these graphs, characterization of the lattices of stable matchings corresponding to these classes of graphs, the NP-completeness of recognizing graphs of stably matchable pairs in general, and exact algorithms for recognizing these graphs that run in singly exponential or fixed-parameter tractable time.
A natural open problem that remains concerns whether our algorithm for carving width can be extended to treewidth for graphs of unbounded degree. As a first step towards this, what is the complexity of recognizing series-parallel graphs of stably matchable pairs? Another problem concerns the analysis of numbers of combinations of matchings and subsets of edges in Section 6.1, which we used to analyze our exponential-time recognition algorithm. This analysis seems unlike to be tight; can it be improved?
References
- [1] Noga Alon and Shmuel Friedland. The maximum number of perfect matchings in graphs with a given degree sequence. Electronic Journal of Combinatorics, 15(1):N13, 2008. doi:10.37236/888.
- [2] Garrett Birkhoff. Rings of sets. Duke Mathematical Journal, 3(3):443–454, 1937. doi:10.1215/S0012-7094-37-00334-X.
- [3] Hans L. Bodlaender. A linear-time algorithm for finding tree-decompositions of small treewidth. SIAM Journal on Computing, 25(6):1305–1317, 1996. doi:10.1137/S0097539793251219.
- [4] Hans L. Bodlaender, Pål Grønås Drange, Markus S. Dregi, Fedor V. Fomin, Daniel Lokshtanov, and Michał Pilipczuk. A 5-approximation algorithm for treewidth. SIAM Journal on Computing, 45(2):317–378, 2016. doi:10.1137/130947374.
- [5] Frederic Dorn and Jan Arne Telle. Semi-nice tree-decompositions: the best of branchwidth, treewidth and pathwidth with one algorithm. Discrete Applied Mathematics, 157(12):2737–2746, 2009. doi:10.1016/j.dam.2008.08.023.
- [6] Vinicius dos Santos. Is there a problem that is easy for cubic graphs but hard for graphs with maximum degree 3? Theoretical Computer Science StackExchange, November 24 2012. URL: https://cstheory.stackexchange.com/q/14457/95.
- [7] G. Ehrlich, S. Even, and R. E. Tarjan. Intersection graphs of curves in the plane. Journal of Combinatorial Theory, 21(1):8–20, 1976. doi:10.1016/0095-8956(76)90022-8.
- [8] David Eppstein. The effect of planarization on width. Journal of Graph Algorithms and Applications, 22(3):461–481, 2018. doi:10.7155/jgaa.00468.
- [9] David Eppstein. The parametric closure problem. ACM Trans. Algorithms, 14(1):2:1–2:22, 2018. arXiv:1504.04073, doi:10.1145/3147212.
- [10] David Gale and Lloyd S. Shapley. College admissions and the stability of marriage. American Mathematical Monthly, 69(1):9–14, 1962. doi:10.2307/2312726.
- [11] Dan Gusfield. Three fast algorithms for four problems in stable marriage. SIAM Journal on Computing, 16(1):111–128, 1987. doi:10.1137/0216010.
- [12] Dan Gusfield and Robert Irving. The Stable Marriage Problem: Structure and Algorithms. Foundations of Computing Series. MIT Press, 1989.
- [13] Dan Gusfield, Robert Irving, Paul Leather, and Michael Saks. Every finite distributive lattice is a set of stable matchings for a small stable marriage instance. Journal of Combinatorial Theory, Series A, 44(2):304–309, 1987. doi:10.1016/0097-3165(87)90037-9.
- [14] Nicole Immorlica and Mohammad Mahdian. Marriage, honesty, and stability. In Proceedings of the 16th ACM–SIAM Symposium on Discrete Algorithms (SODA ’05), pages 53–62, 2005.
- [15] Robert Irving and Paul Leather. The complexity of counting stable marriages. SIAM Journal on Computing, 15(3):655–667, 1986. doi:10.1137/0215048.
- [16] Robert Irving, Paul Leather, and Dan Gusfield. An efficient algorithm for the “optimal” stable marriage. J. ACM, 34(3):532–543, 1987. doi:10.1145/28869.28871.
- [17] Jan Kára, Jan Kratochvíl, and David R. Wood. On the complexity of the balanced vertex ordering problem. Discrete Mathematics & Theoretical Computer Science, 9(1):193–202, 2007. URL: https://hal.inria.fr/hal-00966505.
- [18] Anna R. Karlin, Shayan Oveis Gharan, and Robbie Weber. A simply exponential upper bound on the maximum number of stable matchings. In Ilias Diakonikolas, David Kempe, and Monika Henzinger, editors, Proceedings of the 50th Symposium on Theory of Computing (STOC 2018), pages 920–925. Association for Computing Machinery, 2018. arXiv:1711.01032, doi:10.1145/3188745.3188848.
- [19] Donald E. Knuth. Stable marriage and its relation to other combinatorial problems, volume 10 of CRM Proceedings & Lecture Notes. American Mathematical Society, 1997. doi:10.1090/crmp/010.
- [20] Donald E. Knuth, Rajeev Motwani, and Boris Pittel. Stable husbands. Random Structures & Algorithms, 1(1):1–14, 1990. doi:10.1002/rsa.3240010102.
- [21] Dénes Kőnig. Über Graphen und ihre Anwendung auf Determinantentheorie und Mengenlehre. Mathematische Annalen, 77:453–465, 1916. doi:10.1007/BF01456961.
- [22] David F. Manlove. Algorithmics of Matching under Preferences, volume 2 of Series on Theoretical Computer Science. World Scientific, 2013. doi:10.1142/8591.
- [23] David G. McVitie and Leslie B. Wilson. Stable marriage assignment for unequal sets. BIT Numerical Mathematics, 10(3):295–309, 1970. doi:10.1007/BF01934199.
- [24] Jean-Claude Picard. Maximal closure of a graph and applications to combinatorial problems. Manag. Sci., 22(11):1268–1272, 1976. doi:10.1287/mnsc.22.11.1268.
- [25] Boris Pittel, Lawrence Shepp, and Eugene Veklerov. On the number of fixed pairs in a random instance of the stable marriage problem. SIAM Journal on Discrete Mathematics, 21(4):947–958, 2007. doi:10.1137/070696155.
- [26] Jean-Charles Régin. A filtering algorithm for constraints of difference in CSPs. In Barbara Hayes-Roth and Richard E. Korf, editors, Proceedings of the 12th National Conference on Artificial Intelligence, Seattle, WA, USA, July 31 - August 4, 1994, Volume 1, pages 362–367. AAAI Press and MIT Press, 1994. URL: https://www.aaai.org/Library/AAAI/1994/aaai94-055.php.
- [27] Alvin E. Roth. On the allocation of residents to rural hospitals: A general property of two-sided matching markets. Econometrica, 54(2):425–427, 1986. doi:10.2307/1913160.
- [28] Thomas J. Schaefer. The complexity of satisfiability problems. In Proceedings of the 10th ACM Symposium on Theory of Computing (STOC ’78), pages 216–226, 1978. doi:10.1145/800133.804350.
- [29] Tamir Tassa. Finding all maximally-matchable edges in a bipartite graph. Theoretical Computer Science, 423:50–58, 2012. doi:10.1016/j.tcs.2011.12.071.