Stable matchings of teachers to schools

Several countries successfully use centralized matching schemes for school or higher education assignment, or for entry-level labour markets. In this paper we explore the computational aspects of a possible similar scheme for assigning teachers to schools. Our model is motivated by a particular characteristic of the education system in many countries where each teacher specializes in two subjects. We seek stable matchings, which ensure that no teacher and school have the incentive to deviate from their assignments. Indeed we propose two stability definitions depending on the precise format of schools' preferences. If the schools' ranking of applicants is independent of their subjects of specialism, we show that the problem of deciding whether a stable matching exists is NP-complete, even if there are only three subjects, unless there are master lists of applicants or of schools. By contrast, if the schools may order applicants differently in each of their specialization subjects, the problem of deciding whether a stable matching exists is NP-complete even in the presence of subject-specific master lists plus a master list of schools. Finally, we prove a strong inapproximability result for the problem of finding a matching with the minimum number of blocking pairs with respect to both stability definitions.


Introduction
In the organization of education, several countries or regions use various centralized schemes to allocate children to public schools (e.g., in Boston and New York [2,1]), students to universities (e.g., in Hungary [6]), and intending junior doctors to training positions in hospitals (e.g., in the USA [21]), etc. These schemes are usually not dictatorial in the sense that they take into account the wishes of both sides of the market: students may express their preferences over the universities they wish to attend, and the universities may order their applicants based on some kind of evaluation. After analyzing several successful and unsuccessful schemes Roth [17,18] convincingly argued that a crucial property for success is so-called stability, introduced in the seminal paper by Gale and Shapley [10]. Stability means that no unmatched student-school pair should simultaneously prefer each other to their current assignee(s) (if any). In many real markets, each instance not only admits a stable matching, but it is also possible to find such a matching efficiently.
However, sometimes there are circumstances leading to additional structural requirements. For example, married couples may wish to be allocated to the same hospital or at least to hospitals that are geographically close [15], or schools may wish to have the right to close a study programme if the number of applicants does not meet a certain lower quota [6]. In such cases, a suitable notion of stability has to be defined that really mirrors the intentions of the participants and motivates them to obey the recommended assignment. Alas, a stable matching is not necessarily bound to exist; and even worse, it is often a computationally difficult problem to decide whether in the given situation one does exist [16].
The topic of this paper is motivated by the problems arising in the labour market for teachers. Traditionally, a teacher for the upper elementary or lower secondary level of education in Slovakia and the Czech republic (and in fact in many other countries and regions, such as Germany [4] and Flanders [9]) specializes in two curricular domains (from now on called subjects), e.g., Mathematics and Physics, Chemistry and Biology, or Slovak language and English etc. When a school is looking for new teachers, it may have different numbers of lessons (or teaching hours) to cover at each subject. Thus we suppose that each school has different capacity for each subject and that it will be willing to employ a set of teachers in such a way that these capacities will not be exceeded. Cechlárová et al. [8] studied a variant of this problem where the tranee-teachers could only express which schools are acceptable for them and which not without ordering them according to their preferences and the schools had no say. In these settings, the aim was to assign as many trainee-teachers as possible (ideally all of them) by respecting the schools capacities.
The aim of this paper is to study algorithmic aspects of the problem of assigning teachers to schools within the framework of two-sided preferences. We suppose that teachers rank order their acceptable schools according to their own criteria, and vice versa, schools rank order their applicants similarly [14]. In this context we suggest two stability definitions and study the computational complexity of problems concerned with finding stable matchings (or reporting that none exist). These definitions and the associated complexity results depend on the nature of the schools' preference lists.
The main results and the organization of the rest of the paper are as follows. In Section 2 we introduce relevant technical concepts and illustrate them by means of simple examples. In Section 3 we deal with the case when each school has a linear ordering on the set of teachers who apply for a position. We show that in this general case the problem of deciding whether a stable matching exists is NP-complete, even if there are only three subjects in total. By contrast, if either the preferences of schools are derived from a common master list of teachers, or vice versa, if the preferences of teachers are derived from a common master list of schools, a unique stable matching exists and it can be found using straightforward extensions of the classical serial Dictatorship mechanism [19]. Moreover, the problems with master lists are efficiently solvable without any restrictions on the number of subjects. In Section 5 we modify the stability definition to enable the schools to order the teachers differently according to their two specialization subjects. We show that in this case, the problem of deciding whether a stable matching exists is NP-complete even if there are only three subjects, there are master lists for each subject and there is also a master list of schools. Problems involving finding matchings with the minimum number of blocking pairs are discussed in Section 6. Finally Section 7 summarizes our findings and suggests some questions for further research.

Preliminary definitions and observations
An instance of the Teachers Assignment Problem, tap for short, involves a set A of applicants (teachers), a set S of schools and a set P of subjects. For ease of exposition, elements of the set P will sometimes be referred to by letters like M , F or I to remind the reader of real subjects taught at schools, such as Mathematics, Physics, or Informatics, etc.
Each applicant a ∈ A is characterized by a pair of distinct subjects p(a) ⊆ P , where p(a) = {p 1 (a), p 2 (a)}, that define her type. Sometimes we shall also say that a particular applicant is of type F M , IM , or F I, etc. Corresponding to each applicant a ∈ A there is a set S(a) ⊆ S of schools that a finds acceptable. Moreover applicant a ranks S(a) in strict order of preference.
Each school s ∈ S has a certain capacity for each subject: the vector of capacities will be denoted by c(s) = (c 1 (s), . . . , c k (s)) ∈ N k , where k = |P |, and an entry of c(s) will be called the partial capacity of school s. Here, c i (s) is the maximum number of applicants, whose specialization involves subject p i , that school s is able to take.
Let S(A) = {(a, s) : a ∈ A ∧ s ∈ S(a)} denote the set of acceptable applicant-school pairs. An assignment M is a subset of S(A) such that each applicant a ∈ A is a member of at most one pair in M. We shall write M(a) = s if (a, s) ∈ M and say that applicant a is assigned to school s and M(a) = ∅ if there is no s ∈ S with (a, s) ∈ M. The set of applicants assigned to a school s will be denoted by M(s) = {a ∈ A : (a, s) ∈ M}. We shall also denote by M p (s) the set of applicants assigned to s whose specialization includes subject p and by M p,r (s) the set of applicants assigned to s whose specialization is exactly the pair {p, r}. More precisely, (iv) s prefers a to two different applicants a 1 , a 2 such that a 1 ∈ M p 1 (s) and a 2 ∈ M p 2 (s).
A matching is stable if it admits no blocking pair.   (iii) (a 1 , s 1 ) is a blocking pair since a 1 prefers s 1 to M(a 1 ) = s 3 , and school s 1 prefers a 3 to a 2 ∈ M(s 1 ) who is of the same type as a 1 , (iv) (a 3 , s 1 ) is a blocking pair since a 3 prefers s 1 to M(a 1 ) = s 2 , and school s 1 prefers a 2 to both its asignees a 2 and a 4 .
Note that Definition 1 (iv), as also illustrated in Example 1, gives rise to the possibility that a school could drop two applicants and accept just one in order to satisfy a blocking pair. This is also a possibility in the Hospitals / Residents problem with Couples where a single resident r can displace a couple c assigned to a hospital h if h prefers r to just one member of c [7].
We also remark that tap bears a superficial resemblance to the variant of the Hospitals / Residents problem that modelled the problem of assigning junior doctors to hospitals in Scotland in years 2000-2005, where intending junior doctors sought not one position at hospitals, but two, namely a medical post and a surgical post [12]. They also typically had preferences over the half-years in which they would carry out each type of post, so the stability definition was different to the one given in Definition 1.
We next present two examples to show that a tap instance need not admit a stable matching, and in such instances that do, stable matchings may have different sizes.
Example 2. Consider the instance J 2 of tap given in Figure 2. We show that J 2 admits no stable matching. If M(a 1 ) = s 2 then assigning a 2 to s 1 leads to the blocking pair (a 3 , s 1 ) and assigning a 3 to s 1 produces blocking pair (a 2 , s 2 ). By contrast, if M(a 1 ) = s 1 then a 2 must also be assigned to s 1 (this schools is her first choice and it has enough place to accept her), which makes the pair (a 1 , s 2 ) blocking. Hence no stable matching exists. applicant type preferences school capacities preferences Proof. It is easy to see that tap belongs to NP, since when given an assignment, it can be checked in polynomial time that it is a matching and that it is stable. To prove completeness, we reduce from a restricted version of sat. Let (2,2)-e3-sat denote the problem of deciding, given a Boolean formula B in CNF in which each clause contains exactly 3 literals and, for each variable v i , each of literals v i andv i appears exactly twice in B, whether B is satisfiable. Berman et al. [5] showed that (2,2)-e3-sat is NP-complete. Hence let B be an instance of (2,2)-e3-sat. Let V = {v 1 , v 2 , . . . , v n } and C = {c 1 , c 2 , . . . , c m } be the set of variables and clauses in B, respectively. Let us construct an instance J of tap in the following way.
There are 3 subjects, namely F , I and M . For each variable v i there are 6 applicants . For each clause c j there is one school z j . Applicants x 1 i and x 2 i correspond to the first and to the second occurrence of literal v i , and applicants y 1 i and y 2 i correspond to the first and to the second occurrence of literalv i , respectively.
The characteristics of applicants and schools and their preferences are given in Figure  4. Here, the subscripts and superscripts involving i, j and k range over the following intervals: 1 ≤ i ≤ n, 1 ≤ j ≤ m and 1 ≤ k ≤ 4. In the preference list of school z j , the symbol v s j means the x-or y-applicant that corresponds to the literal that appears in position s of clause c j . Conversely, in the preference list of x-or y-applicants the symbol c(.) denotes the z-school corresponding to the clause containing the corresponding literal. Also, in the preference list of Now, let f be a satisfying truth assignment of B. Define a matching M in J as follows.
In the former case add the pairs and in the latter case add the pairs Notice that as each clause c j ∈ C contains at most two false literals, school z j has enough capacity for accepting all the allocated applicants. Finally, add the following pairs for each i (1 ≤ i ≤ n) and k (1 ≤ k ≤ 4): It is obvious that the defined assignment is a matching; it remains to prove that it is stable. We show this by considering each type of applicants corresponding to variable v i in turn. Firstly we remark that applicants q k i,1 , q k i,2 , q k i,3 each have their first choice school (1 ≤ k ≤ 4) so cannot be involved in a blocking pair. Now suppose that v i is true under f . Then: i and a 5 i have their most-preferred schools, so are not blocking; • applicants y 1 i and y 2 i prefer school s F i , but this school is assigned a 6 i , whom it prefers; • applicant a 2 i prefers school s 2 i , but this school is assigned a 3 i , whom it prefers; • applicant a 3 i prefers school s 1 i , but this school is assigned a 1 i , whom it prefers; • applicant a 6 i prefers school s 4 i , but this school is assigned a 2 i , whom it prefers.
The case of a false variable can be proved similarly.
For the converse implication let us first prove two lemmata. Proof. Let M be a stable matching. Fix i ∈ {1, 2, . . . , n}. Notice first that both schools s T i and s F i must be full, otherwise either s T i will form a blocking pair with at least one of x 1 i and x 2 i , or s F i will form a blocking pair with at least one of y 1 i and y 2 i . Further, let us distinguish the following cases.
Then, as there are no blocking pairs, This, however means that (a 3 i , s 1 i ) and (a 4 i , s 2 i ) are blocking pairs for M, a contradiction.
So, suppose that M is a stable matching in J. We form a truth assignment f in B as follows. Let i ∈ {1, 2, . . . , n} be given. By Lemma 1, either T i ⊆ M or F i ⊆ M. In the former case set f (v i ) = true, otherwise set f (v i ) = false. Now let v i ∈ V and suppose that f (v i ) = true. Then by Lemma 2, each of y i,1 and y i,2 is assigned to her second choice school. Now suppose that f (v i ) = false. Then again by Lemma 2, each of x i,1 and x i,2 is assigned to her second choice school. Now let c j ∈ C and suppose that all literals in c j are false. By the preceding remarks about x i,1 , x i,2 , y i,1 and y i,2 we deduce that z j is over-subscribed, a contradiction. Thus f is a satisfying truth assignment.

Master lists
In some centralized matching schemes all the applicants are ordered in a common master list. Although the criteria used for creating such lists are often subject to some controversy (see [11] for the description of the matching scheme for allocating medical students to hospital posts in England in 2005-06 and [20] for the situation in the central allocation scheme of teachers in Portugal that was used prior to 2005), computationally the situation with master lists may be easier. A detailed study of stable matching problems with master lists from the computational point of view can be found in [13]. In this section we shall consider the case of a master list of applicants and the (perhaps slightly less realistic) case of a master list of schools.
The problems of deciding the existence of a stable matching in these cases will be denoted by tap-am and tap-sm, respectively. The phrase 's has enough capacity for a' used in the algorithms in this section means the following: if a is of type {p, r} then |M p (s)| < c p (s) as well as |M r (s)| < c r (s).   Theorem 2. Let J be an instance of tap-am with the master list a 1 , a 2 , . . . , a n of applicants. Then J admits a unique stable matching that may be found by an application of Algorithm Serial Dictatorship as shown in Figure 5.
Proof. It is easy to see that Serial Dictatorship outputs a matching. We have to prove that this matching is stable and that it is the unique stable matching.
M is stable. Suppose that (a i , s j ) is a blocking pair and that i is the smallest index of an applicant involved in a blocking pair. Since a i has chosen the best available school from her list, s j did not have enough capacity to accept a i when it was a i 's turn in the algorithm. However, all the applicants that were assigned to s j at that moment precede a i in the master list, hence (a i , s j ) cannot be a blocking pair.
Uniqueness. Let M ′ = M be another stable matching and let a i be the first applicant in the master list with M ′ (a i ) = M(a i ). As Serial Dictatorship gave a i her best available school and all applicants who precede a i in the master list have the same assignments in M as in M ′ , it must be the case that a i prefers s j = M(a i ) to s k = M ′ (a i ). But this implies that (a i , s j ) is a blocking pair for M ′ , as s j will be able to reject one or two applicants worse than a i in order to free up sufficient capacity for a i (for, s j had enough room for a i in M when it was a i 's turn during Serial Dictatorship, and any applicant that precedes a i in the master list has the same assignment in M as she does in M ′ ).
The situation with a master list of schools, although less likely to occur in practice, is also efficiently solvable.
Theorem 3. Let J be an instance of tap-sm with the master list of schools s 1 , s 2 , . . . , s m . Then J admits a unique stable matching that may be found by an application of Algorithm Dual Serial Dictatorship as shown in Figure 6.
Proof. Let us denote by J(s 1 ) the subinstance of J containing just school s 1 and applicants who apply to s 1 . J(s 1 ) is an instance of tap-am, so it has a unique stable matching. This is obtained by Serial dictatorship of applicants that is equivalent with the part of Dual serial dictatorship within one iteration of the for-cycle for schools. Let us denote this matching by M 1 . Let us further observe that no applicant assigned to s 1 could be a member of a blocking pair, as she received her most preferred school. If we now denote by J(−s 1 ) the subinstance of J with pairs of M 1 deleted, the result follows by induction.

Subject-specific preference lists
Suppose that a school can order applicants differently for different subjects. The definition of a blocking pair should now be modified in order to take account of this scenario. (iv) s prefers a in subject p 1 to applicant a 1 ∈ M p 1 (s) and in subject p 2 to another applicant a 2 ∈ M p 2 (s).
Let us denote this variant by tap-ss. Define a matching M in a tap-ss instance to be applicant-complete if every applicant is assigned in M.

Lemma 3.
Given an instance of tap-ss, the problem of deciding whether an applicantcomplete stable matching exists is NP-complete. This result holds even if there are at most three subjects, each partial capacity of a school is at most 1, and the preference lists of the schools are derived from subject-specific master lists of the applicants.
Proof. We reduce from (2,2)-e3-sat (see the proof of Theorem 1). Let B be an instance of this problem, where V = {v 0 , v 1 , . . . , v n−1 } and C = {c 1 , c 2 , . . . , c m } be the set of variables and clauses respectively in B. We construct an instance J of tap in the following way.
There are 3 subjects, namely F , I and M . For each variable v i (0 ≤ i ≤ n − 1) there are 4 applicants x 4i+r (0 ≤ r ≤ 3), each of type F I, and 4 schools y 4i+r (0 ≤ r ≤ 3). For each clause c j (1 ≤ j ≤ m) there are 4 applicants q j and w t j (1 ≤ t ≤ 3), each of type F M , and 4 schools s t , applicants x 4i and x 4i+1 correspond to the first and second occurrences of literal v i in B, and applicants x 4i+2 and x 4i+3 correspond to the first and second occurrences of literalv i in B, respectively. For each r ∈ {0, 1}, let s(x 4i+r ) denote the school s t j such that the (r + 1)th occurrence of literal v i appears in position t of clause c j (1 ≤ j ≤ m, 1 ≤ t ≤ 3). Similarly, for each r ∈ {2, 3}, let s(x 4i+r ) denote the school s t j such that the (r −1)th occurrence of literalv i appears in position t of clause c j (1 ≤ j ≤ m, The applicants' preferences, together with a summary of their types and a summary of the schools' partial capacities, are given in Figure 7. Here, the subscripts and superscripts involving i, j and t range over the following intervals: 0 ≤ i ≤ n − 1, 1 ≤ j ≤ m and 1 ≤ t ≤ 3. applicant type preferences school capacities F I M x 4i F I y 4i , s(x 4i ), y 4i+1 y 4i 1 1 0 x 4i+1 F I y 4i+1 , s(x 4i+1 ), y 4i+2 y 4i+1 1 1 0 x 4i+2 F I y 4i+3 , s(x 4i+2 ), y 4i+2 y 4i+2 1 1 0 We now construct the subject-specific master lists of applicants. Let X denote the elements of X in increasing order of subscript, and let X denote the reverse of this order. Similarly let W denote the elements of W listed in increasing order of subscript, and within this ordering, those elements with equal subscript are listed in increasing order of superscript. Also let W denote the reverse of W . Finally let Q denote the elements of Q listed in increasing order of subscript. The master lists of the applicants with respect to subjects are shown in Figure 8.
For, let f be a satisfying truth assignment of B. Define a matching M in J as follows. For each variable v i ∈ V , if f (v i ) = true, add the pairs in T i to M and if f (v i ) = false, add the pairs in F i to M. Each clause c j ∈ C contains some literal in c j that is true under f , let t be the position of c j containing this true literal (1 ≤ t ≤ 3). Add the following pairs to M: It is obvious that the defined assignment is an applicant-complete matching; it remains to prove that it is stable. It is straightforward to verify that no applicant in Q can be involved in a blocking pair of M, and no pair in X × Y can block M. Now suppose that (w t j , s t j ) blocks M for some j (1 ≤ j ≤ m) and t (1 ≤ t ≤ 3). Then (w t j , s 4 j ) ∈ M and (q j , s t j ) ∈ M, and school s t j prefers q j over w t j for subject M , so (w t j , s t j ) cannot block M after all. Finally suppose that (x 4i+r , s(x 4i+r )) blocks M for some i (0 ≤ i ≤ n − 1) and r (0 ≤ r ≤ 1). Then f (v i ) = false by construction of M. Let s t j = s(x 4i+r ). Then (q j , s t j ) ∈ M, since (x 4i+r , s(x 4i+r )) blocks M. But then by construction of M, the tth literal of c j is true under f , a contradiction. The argument is similar if r ∈ {2, 3}. Hence M is stable in J.
Conversely suppose that M is an applicant-complete stable matching in J. For any j (1 ≤ j ≤ m), it follows that (q j , s t j ) ∈ M for some t (1 ≤ t ≤ 3) and thus (w t j , s 4 j ) ∈ M, since q j and w t j must be assigned. Moreover Thus M contains no pair of the form (x 4i+r , s(x 4i+r )) (0 ≤ i ≤ n − 1, 0 ≤ r ≤ 3). Moreover, since each member of X must be assigned in M, we have thus established that for each i (0 ≤ i ≤ n − 1), either T i ⊆ M or F i ⊆ M. Now we construct a truth assignment f in B as follows.
We claim that f is a satisfying truth assignment. For, suppose that some clause c j contains no true literal. As M is an applicant-complete matching, (q j , s t j ) ∈ M for some t (1 ≤ t ≤ 3). Now let x 4i+r be the applicant such that Hence (x 4i+r , s(x 4i+r )) blocks M, again a contradiction.

Lemma 4.
Given an instance of tap-ss, the problem of deciding whether a stable matching exists is NP-complete. This result holds even if there are at most three subjects, each partial capacity of a school is at most 1, and the preference lists of the schools are derived from subject-specific master lists of the applicants.
Proof. We show how to modify the reduction presented in the proof of Lemma 3 in order to ensure that any stable matching in J is applicant-complete. We create a new tap instance J ′ from J as follows. For each applicant a in J, create two new applicants a ′ and a ′′ . If a is of type F I, then a ′ and a ′′ are of type F M and IM respectively. If a is of type F M , then a ′ and a ′′ are of type F I and IM respectively. Create a new school g(a) which has capacity 1 for each of subjects F , I and M . Append g(a) to applicant a's preference list in J to obtain her preference list in J ′ . Each of applicants a ′ and a ′′ finds only g(a) acceptable.
Let X ′ and X ′′ denote the sets of newly-created applicants in J ′ with single and double primes respectively that correspond to applicants in X. Define R ′ and R ′′ similarly for the newly-created applicants in J ′ that correspond to applicants in Q ∪ W . For A ∈ {R, X}, let A ′ and A ′′ denote arbitrary but fixed orderings of the applicants in A ′ and A ′′ respectively.
The subject-specific master lists in J ′ are as shown in Figure 9. We show how to modify the proof of Lemma 3 to show that B has a satisfying truth assignment if and only if J ′ has a stable matching.
Firstly, if f is a satisfying truth assignment of B, construct the matching M in J as in the proof of Lemma 3. We then extend M to a matching M ′ in J ′ as follows. For each applicant a in J, add the pair (a ′ , g(a)) to M. Since M is applicant-complete in J, it is straightforward to verify that M ′ is stable in J ′ .
Conversely suppose that M ′ is a stable matching in J ′ . We firstly claim that each applicant a in J is assigned in M ′ to a school better than g(a). For, suppose (a, g(a)) ∈ M ′ . Then (a ′′ , g(a)) blocks M ′ , a contradiction. Now suppose that a is unassigned in M ′ . Clearly some applicant is assigned to g(a) in M ′ , for otherwise (a, g(a)) blocks M ′ . If (a ′ , g(a)) ∈ M ′ then (a, g(a)) blocks M ′ , whilst if (a ′′ , g(a)) ∈ M ′ then (a ′ , g(a)) blocks M ′ . The claim is thus proved. It is then also straightforward to verify that (a ′ , g(a)) ∈ M ′ for each applicant a in J, for otherwise (a ′ , g(a)) blocks M ′ .
Let M be the matching obtained from M ′ by removing all pairs of the form (a ′ , g(a)), where a is an applicant in J. It follows by the previous paragraph that M is an applicantcomplete stable matching in J. The remainder of the proof is then identical to the converse direction of the proof of Lemma 3.
Theorem 4. Given an instance of tap-ss, the problem of deciding whether a stable matching exists is NP-complete. This result holds even if there are at most three subjects, each partial capacity of a school is at most 1, the preference lists of the schools are derived from subject-specific master lists of the applicants, and the preference lists of the applicants are derived from a single master list of schools.
Proof. We consider the reduction given by Lemmata 3 and 4, and show that the applicants' preference lists may be derived from a single master list of schools.
For each i (0 ≤ i ≤ n − 1), let S i denote the sequence Let S 4 = {s 4 j : 1 ≤ j ≤ m} and let S 4 denote an arbitrary order of the schools in S 4 . Let G denote the set of schools of the form g(a) as introduced in the proof of Lemma 4 for each applicant a in the original tap-ss instance as constructed in the proof of Lemma 3. Let G denote an arbitrary order of the schools in G. Define the following master list of schools: In the proof of Lemma 3, let the preference list of each q j (1 ≤ j ≤ m) be reordered such that the relative ordering of the three schools s 1 j , s 2 j and s 3 j is derived from the above master list. This does not change the remainder of the proof of Lemma 3, nor the proof of Lemma 4. Moreover every other applicant's preference list is derived from the above master list of schools. The theorem then follows.

"Most stable" matchings
Given an instance of tap, we have already seen that a stable matching need not exist. In such cases it is natural to seek a matching that is "as stable as possible" in a precise sense.
Here we regard such "most stable" matchings as those that admit the minimum number of blocking pairs. Note that this approach was also considered in [3].
Clearly min bp tap, the problem of finding such a matching in an instance of tap, is NP-hard, given Theorem 1. It is then natural to consider the approximability of this problem. In this section we prove that the problem of finding a matching with the minimum number of blocking pairs, given an instance of tap, is NP-hard and not approximable within n 1−ε , for any ε > 0, unless P=NP, where n is the number of agents (applicants plus schools). We show that similar observations hold for min bp tap-ss, the problem of finding a matching with the minimum number of blocking pairs in an instance of tap-ss.
We begin by stating a more general result. Let p be any stable matching problem for which deciding whether a stable matching exists is NP-complete. Define min bp p to be the problem of finding a matching with the minimum number of blocking pairs, given an instance I of p. We let opt(I) denote 1 plus the minimum number of blocking pairs admitted by any matching in I. (We then use opt(I) as the measure against which any approximation algorithm for p performs, since adding 1 ensures that opt(I) ≥ 1.) We now present a general inapproximability result for min bp p, and later use it to derive similar inapproximability results for min bp tap and min bp tap-ss.
Theorem 5. min bp p is not approximable within n 1−ε , where n is the number of agents in a given instance, for any ε > 0 unless P=NP.
Proof. Let n 0 be the number of agents in an instance I of p. Choose c = ⌈2/ε⌉ and k = n c 0 . Now, let I 1 , I 2 , . . . , I k be k disjoint copies of the instance I. Let I ′ be the instance of p formed by taking the union of the sub-instances I 1 , I 2 , . . . , I k . Let n = kn 0 denote the number of agents in I ′ .
Clearly if I admits a stable matching then each copy of I must admit a stable matching. Hence opt(I ′ ) = 1. However, if I admits no stable matching, then each I r (1 ≤ r ≤ k) admits only matchings with one or more blocking pair, and hence any matching admitted by I ′ must admit k or more blocking pairs. Hence opt(I ′ ) ≥ k + 1. We now show that n 1−ε ≤ k.
We now show that n 1−ε ≤ n (c−1)/(c+1) . Observe that c ≥ 2/ε and thus c + 1 ≥ 2/ε. Hence and hence by Inequality 4, n 1−ε ≤ k. Now, assume that X is an approximation algorithm for p with a performance guarantee of n 1−ε . If I admits a stable matching, X must return a matching in I ′ with measure at most opt(I).n 1−ε = n 1−ε ≤ k, since opt(I) = 1. Otherwise, I ′ does not admit a stable matching and, as shown above, X must return a matching with measure ≥ k + 1. Thus algorithm X may be used to determine whether I admits a stable matching in polynomial time, a contradiction. Hence, no such polynomial approximation algorithm can exist unless P = NP.
Theorem 5 allows us to state the following corollaries for the inapproximability of min bp tap and min bp tap-ss. Corollary 1. min bp tap is not approximable within n 1−ε , where n is the number of agents in a given instance, for any ε > 0 unless P=NP. This result holds even if there are at most three subjects, each partial capacity of a school is at most 2, and the preference list of each applicant is of length at most 3.
Proof. This result follows immediately from Theorems 1 and 5.
Corollary 2. min bp tap-ss is not approximable within n 1−ε , where n is the number of agents in a given instance, for any ε > 0 unless P=NP. This result holds even if there are at most three subjects, each partial capacity of a school is at most 1, the preference lists of the schools are derived from subject-specific master lists of the applicants, and the preference lists of the applicants are derived from a single master list of schools.
Proof. This result follows immediately from Theorems 4 and 5.

Conclusion
In this paper we studied the notion of stability in the Teachers Assignment Problem from the computational perspective. Notice that when there are only two different subjects in total, then all the applicants are of the same type and the problem reduces to the classical Hospitals / Residents problem. However, the presence of just three subjects makes the problem of deciding the existence of a stable matching intractable, unless there is a master list of applicants or a master list of schools. By contrast, if the schools may order applicants differently in each of their specialization subjects, then even subject-specific master lists plus the master list of schools do not make the problem tractable. Thus we have been able to characterize the borderline between the polynomially solvable and intractable cases of the Teachers Assignment Problem.
Further, we proved a general inapproximability result for the problem of finding a matching with the minimum number of blocking pairs. This implies that, if P = N P , there is no polynomial approximation algorithm with performance guarantee n 1−ε for finding a matching with the minimum number of blocking pairs in both preference variants of the Teachers Assignment Problem.