Two Algorithms For The Student-Project Allocation Problem
Two Algorithms For The Student-Project Allocation Problem
www.elsevier.com/locate/jda
Abstract
We study the Student-Project Allocation problem (SPA), a generalisation of the classical Hospitals/Residents problem (HR). An
instance of SPA involves a set of students, projects and lecturers. Each project is offered by a unique lecturer, and both projects and
lecturers have capacity constraints. Students have preferences over projects, whilst lecturers have preferences over students. We
present two optimal linear-time algorithms for allocating students to projects, subject to the preference and capacity constraints.
In particular, each algorithm finds a stable matching of students to projects. Here, the concept of stability generalises the stability
definition in the HR context. The stable matching produced by the first algorithm is simultaneously best-possible for all students,
whilst the one produced by the second algorithm is simultaneously best-possible for all lecturers. We also prove some structural
results concerning the set of stable matchings in a given instance of SPA. The SPA problem model that we consider is very general
and has applications to a range of different contexts besides student-project allocation.
© 2006 Elsevier B.V. All rights reserved.
Keywords: Stable matching problem; Preference lists; Linear-time algorithm; Student-optimal; Lecturer-optimal
1. Introduction
In many university departments, students seek to undertake a project in a given field of speciality as part of the
upper level of their degree programme. Typically a wide range of available projects is offered, and usually the total
number of project places exceeds the number of students, to provide something of a choice. Also, typically each
lecturer will offer a variety of projects, but does not necessarily expect that all will be taken up.
Each student has preferences over the available projects that he/she finds acceptable, whilst a lecturer will normally
have preferences over the students that he/she is willing to supervise. There may also be upper bounds on the number
of students that can be assigned to a particular project, and the number of students that a given lecturer is willing to
✩
A preliminary version of this paper was presented at ISAAC 2003 [D.J. Abraham, R.W. Irving, D.F. Manlove, The student-project allocation
problem, in: Proceedings of ISAAC 2003: the 14th Annual International Symposium on Algorithms and Computation, Lecture Notes in Computer
Science, vol. 2906, Springer-Verlag, 2003, pp. 474–484].
* Corresponding author.
E-mail addresses: [email protected] (D.J. Abraham), [email protected] (R.W. Irving), [email protected] (D.F. Manlove).
1 Work done whilst at Department of Computing Science, University of Glasgow.
2 Supported by Engineering and Physical Sciences Research Council grant GR/R84597/01, Nuffield Foundation award NUF-NAL-02, and Royal
Society of Edinburgh/Scottish Executive Personal Research Fellowship.
1570-8667/$ – see front matter © 2006 Elsevier B.V. All rights reserved.
doi:10.1016/j.jda.2006.03.006
74 D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90
supervise. In this paper we consider the problem of allocating students to projects based on these preference lists and
capacity constraints—the so-called Student-Project Allocation problem (SPA).
SPA is an example of a two-sided matching problem [1,24], a large and very general class of problems whose
input includes a set of participants that can be partitioned into two disjoint sets A and B (in this case A is the set of
students and B is the set of projects), and we seek to match members of A to members of B, i.e. to find a subset
of A × B, subject to various criteria. These criteria usually involve capacity constraints, and/or preference lists, for
example.
Both historical evidence (see e.g. [11, pp. 3–4], [19]) and game-theoretic analysis [22,24] indicate that participants
involved in two-sided matching problems should not be allowed to construct an allocation by approaching one another
directly and making ad hoc arrangements. Rather, the allocation process should be automated by means of a centralised
matching scheme. Moreover, it has been convincingly argued [22] that, when preference lists exist on both sides, the
key property that a matching constructed by such schemes should satisfy is that of stability. A formal definition of
stability follows, but informally, a stable matching M guarantees that no two participants who are not matched together
in M would rather be matched to one another than remain with their assignment in M. Such a pair of participants
could come to a private arrangement that would undermine the integrity of the matching.
The National Resident Matching Program (NRMP) [18] in the US is perhaps the largest and best-known example
of a centralised matching scheme. It has been in operation since 1952, and currently handles the allocation of some
30,000 graduating medical students, or residents, to their first hospital posts, based on the preferences of residents
over available hospital posts, and the preferences of hospital consultants over residents. The NRMP employs at its
heart an efficient algorithm that essentially solves a variant of the classical Hospitals/Residents problem (HR) [9,11].
The algorithm finds a stable matching of residents to hospitals that is resident-optimal, in that each resident obtains
the best hospital that he/she could obtain in any stable matching.
There are many other examples of centralised matching schemes, both in educational and vocational contexts
(e.g. allocating pupils to secondary schools in Singapore [25], school-leavers to universities in Spain [21] and trainee
teachers to probationary posts in Scotland). Many university departments in particular seek to automate the allocation
of students to projects [2,4,26]. However, as we discuss in greater detail later, an optimal linear-time algorithm for this
setting cannot be obtained by simply reducing an instance of SPA to an instance of HR. Thus, a specialised algorithm
is required for the SPA problem.
In this paper we present two linear-time algorithms for finding a stable matching, given an instance of SPA. The
first algorithm is student-oriented, in that it finds the stable matching in which each student obtains the best project
that he/she could obtain in any stable matching. The second algorithm is lecturer-oriented, in that it constructs the
stable matching in which each lecturer has as good a set of students (in a precise sense, to be defined) as in any
other stable matching. Our algorithms are applicable in any context that fits into the SPA model, for example where
applicants seek posts at large organisations, each split into several departments.
As alluded to above, the centralised allocation of students to projects has been considered previously in the liter-
ature. Various models have been constructed that allow student preferences over projects, but do not permit lecturer
preferences [2,20,26], so stability is not relevant in these contexts. However an automated system for allocating stu-
dents to projects at the Department of Computer Science, University of York is described [4,14,27] which takes into
account student preferences over projects and lecturer preferences over students. In this model, preference lists may
include ties, each project has capacity 1, and lecturer capacities are unbounded. Constraint programming techniques
are utilised in order to find a stable matching with additional properties, such as balancing the supervision load among
lecturers as evenly as possible. The underlying algorithms do not, in general, run in polynomial time.
The remainder of this paper is structured as follows. In Section 2, a formal definition of the SPA problem is given,
followed by some consequences of this definition and a discussion of relationships between SPA and existing models
in the literature. Then, in Section 3, the student-oriented algorithm for SPA is presented, together with correctness
proofs and an analysis of its complexity. In Section 4 we present some properties of the set of stable matchings in
a given SPA instance and consider the issue of load balancing students among lecturers. Then in Section 5, we give
the lecturer-oriented algorithm, also establishing its correctness and time complexity. Finally, Section 6 contains a
discussion of the SPA problem model considered in this paper, and also presents some open problems.
D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90 75
An instance of the Student-Project Allocation problem (SPA) may be defined as follows. Let S = {s1 , s2 , . . . , sn } be
a set of students, let P = {p1 , p2 , . . . , pm } be a set of projects, and let L = {l1 , l2 , . . . , lq } be a set of lecturers. Each
student si supplies a preference list, ranking a subset of P in strict order. If project pj appears on si ’s preference list,
we say that si finds pj acceptable. Denote by Ai the set of projects that si finds acceptable.
Each lecturer lk offers a non-empty set of projects Pk , where P1 , P2 , . . . , Pq partitions P . Let Bk = {si ∈ S: Pk ∩
Ai = ∅} (i.e. Bk is the set of students who find acceptable a project offered by lk ). Lecturer lk supplies a preference
j
list, denoted by Lk , ranking Bk in strict order. For any pj ∈ Pk , we denote by Lk the projected preference list of lk for
j
pj —this is obtained from Lk by deleting those students who do not find pj acceptable. In this way, the ranking of Lk
is inherited from Lk . Also, lk has a capacity constraint dk , indicating the maximum number of students that he/she is
willing to supervise. Similarly, each project pj carries a capacity constraint cj , indicating the maximum number of
students that could be assigned to pj . We assume that max{cj : pj ∈ Pk } dk {cj : pj ∈ Pk }.
An example SPA instance is shown in Fig. 1. Here the set of students is S = {s1 , s2 , . . . , s7 }, the set of projects is
P = {p1 , p2 , . . . , p8 } and the set of lecturers is L = {l1 , l2 , l3 }. As an example, the projected preference list of l1 for
p1 comprises s1 , s3 , s2 , s5 , ranked in that order.
An assignment M is a subset of S × P such that:
If (si , pj ) ∈ M, we say that si is assigned to pj , and pj is assigned si . Hence Condition 2 states that each student is
assigned to at most one project in M. For notational convenience, if si is assigned in M to pj , we may also say that si
is assigned to lk , and lk is assigned si , where pj ∈ Pk .
For any student si ∈ S, if si is assigned in M to some project pj , we let M(si ) denote pj ; otherwise we say
that si is unassigned in M. For any project pj ∈ P , we denote by M(pj ) the set of students assigned to pj in M.
Project pj is under-subscribed, full or over-subscribed according as |M(pj )| is less than, equal to, or greater than cj ,
respectively. Similarly, for any lecturer lk ∈ L, we denote by M(lk ) the set of students assigned to lk in M. Lecturer lk
is under-subscribed, full or over-subscribed according as |M(lk )| is less than, equal to, or greater than dk respectively.
A matching M is an assignment such that:
Hence Condition 3 stipulates that pj is assigned at most cj students in M, whilst Condition 4 requires that lk is
assigned at most dk students in M.
A (student, project) pair (si , pj ) ∈ (S × P )\M blocks a matching M if:
3. Either
(a) pj is under-subscribed and lk is under-subscribed, or
(b) pj is under-subscribed, lk is full, and either si ∈ M(lk ) or lk prefers si to the worst student in M(lk ), or
(c) pj is full and lk prefers si to the worst student in M(pj ),
where lk is the lecturer who offers pj .
Our blocking pair definition in this paper attempts to encapsulate the various practical scenarios in which si and lk
could both simultaneously improve relative to M by permitting an assignment between si and pj . For this to occur, si
must find pj acceptable (Condition 1), and either be unassigned in M or prefer pj to M(si ) (Condition 2). We now
consider lk ’s perspective. In Condition 3(a), lk will co-operate if there was already a free place for si . Similarly, in
Condition 3(b), if lk is full and si was already assigned in M to a project offered by lk , then lk agrees to the switch
since the total number of students assigned to lk remains the same, and pj has room for si . Alternatively, if lk is full
and si was not already assigned in M to a project offered by lk , then lk cannot take on si without first rejecting some
student assigned to lk . Lecturer lk would only agree to this switch if he/she prefers si to the worst student assigned to
lk in M, and project pj has room for si . Finally, we consider Condition 3(c). If pj is full, then lk cannot take on si
without first rejecting some student assigned to pj . Lecturer lk would only agree to this switch if he/she prefers si to
the worst student assigned to pj in M. Notice that if si was already assigned in M to a project offered by lk , then the
number of students assigned to lk would decrease by 1 after the switch; we revisit this point in Section 6.1.
We remark that HR is a special case of SPA in which m = q, cj = dj and Pj = {pj } (1 j m). Essentially the
projects and lecturers are indistinguishable in this case. In the HR setting, lecturers/projects are referred to as hospitals,
and students are referred to as residents. Linear-time algorithms are known for finding a stable matching, given an
instance of HR. The resident-oriented algorithm [11, Section 1.6.3] finds the resident-optimal stable matching, in
which each assigned resident is assigned to the best hospital that he/she could obtain in any stable matching, whilst
each unassigned resident is unassigned in every stable matching. On the other hand, the hospital-oriented algorithm
[11, Section 1.6.2] finds the hospital-optimal stable matching M. Such a matching M satisfies the property that there
is no stable matching M and hospital h for which h prefers a resident in M (h)\M(h) to the worst resident in M(h).
The set of stable matchings in a given instance of HR satisfy several interesting properties that together form the
Rural Hospitals Theorem [11, Theorem 1.6.4].
Theorem 2.1 (Rural Hospitals). For a given instance of HR, the following holds.
(i) Each hospital is assigned the same number of residents in all stable matchings [10].
(ii) Exactly the same set of residents are unassigned in all stable matchings [10].
(iii) Any hospital that is under-subscribed in one stable matching is assigned precisely the same set of residents in all
stable matchings [23].
In Section 4, we generalise parts of the Rural Hospitals Theorem to the SPA case, although as we demonstrate, not
all of the above properties carry over to SPA.
It is worth drawing attention to a special case of HR (and hence of SPA). This is the classical Stable Marriage
problem with Incomplete lists (SMI), where cj = 1 (1 j m) [9], [11, Section 1.4.2]. In this setting, residents are
referred to as men and hospitals are referred to as women. There exists a reduction from HR to SMI using the method
c
of ‘cloning’ hospitals. That is, replace each hospital hj , of capacity cj , with cj women, denoted by h1j , h2j , . . . , hjj .
The preference list of hkj is identical to the preference list of hj . Any occurrence of hj in a resident’s preference
c
list should be replaced by h1j , h2j , . . . , hjj in that order. Hence in theory, the Gale/Shapley algorithm for SMI [11,
Section 1.4.2] could be used to solve an HR instance. However in practice direct algorithms are applied to HR instances
[11, Section 1.6], because the cloning technique increases the number of hospitals (women) in a given HR instance
by a potentially significant factor of C/m, where C = m j =1 cj .
D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90 77
On the other hand there is no straightforward reduction involving cloning from an instance of SPA to an instance of
HR, due to the projects and lecturers being distinct entities, each having capacity constraints. Even if such a reduction
were possible, again it would typically increase the number of lecturers (hospitals) by a significant factor. This justifies
the approach of this paper, in which we consider direct algorithms for SPA.
The two algorithms that we present are generalisations of the resident-oriented and hospital-oriented algorithms
for HR. The running time of each algorithm is O(λ), where λ is the total length of the input preference lists, and
hence is linear in the size of the problem instance. This time complexity is optimal, since the Stable Marriage problem
(SM)—the special case of SMI in which m = n and each man finds every woman acceptable—is a special case of
SPA. A lower bound of Ω(λ) is known for SM [17], and hence this also applies to SPA.
We now consider similarities between the SPA problem model and existing models for two-sided matching prob-
lems that have been proposed in the literature.
Recently Fleiner [6,7] developed a matroid-theoretic characterisation of stable matchings in bipartite matching
models. This is based on imposing two ordered partition matroids, MA , MB , one on each side of a bipartite graph G.
A matching is an independent set that is common to both MA and MB . Moreover a stable matching corresponds to
an MA MB -kernel, and it is shown that such a structure is bound to exist [6,7]. Fleiner [8] noted that the SPA problem
model may be included in this characterisation by imposing a student matroid as a partition matroid, and a lecturer
matroid as the truncation of a direct sum of uniform matroids (thus ensuring that all project and lecturer capacities
are satisfied). Here the vertices on one side of G correspond to students, the vertices on the other side correspond to
lecturers, and the edges correspond to acceptable (student, project) pairs (so that G is in general a multigraph).
Also Eguchi et al. [5] formulated a model for two-sided matching problems in which preferences are based on
M -concave functions, which arise in discrete convex analysis. They gave an algorithm for finding a stable matching
in such a context, however the algorithm does not, in general, run in polynomial time for an arbitrary M -concave
function. Their model includes the possibility of capacities and multiple partners; moreover since linear orders gives
rise to M -concave functions, it follows that the model of Eguchi et al. [5] includes SPA as a special case.
Our approach in this paper is to give specialised linear-time algorithms for SPA. As the algorithms are described
directly in terms of the SPA problem model, they should be more intuitive and easier to implement in practical
applications. Also, some structural and optimality properties of the SPA problem model are derived (see Theorems 3.5,
4.1 and 5.5) which do not necessarily hold in the more general models mentioned.
We now present our first algorithm for SPA, starting with an overview of its operation. The student-oriented al-
gorithm for an instance of SPA involves a sequence of apply operations (i.e. students apply to projects). An apply
operation is similar to a proposal in the context of the Gale/Shapley algorithm for SM [9]. These operations lead to
provisional assignments between students, projects and lecturers; such assignments can subsequently be broken dur-
ing the algorithm’s execution. Also, throughout the execution, entries are possibly deleted from the preference lists
of students, and from the projected preference lists of lecturers. We use the abbreviation delete (si , pj ) to denote the
j
operation of deleting pj from the preference list of si , and deleting si from Lk , where lk is the lecturer who offers pj .
Initially all students are free, and all projects and lecturers are totally unsubscribed. As long as there is some student
si who is free and who has a non-empty list, si applies to the first project pj on his/her list. We let lk be the lecturer
who offers pj . Immediately, si becomes provisionally assigned to pj (and to lk ).
If pj is over-subscribed, then lk rejects the worst student sr assigned to pj . The pair (sr , pj ) will be deleted by
the subsequent conditional that tests for pj being full. Similarly, if lk is over-subscribed, then lk rejects his/her worst
assigned student sr . The pair (sr , pt ) will be deleted by either of the two subsequent conditionals, where pt was the
project most recently assigned sr .
Regardless of whether any rejections occurred as a result of the two situations described in the previous paragraph,
we have two further (possibly non-disjoint) cases in which deletions may occur. If pj is full, we let sr be the worst
78 D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90
SPA-student(I ) {
assign each student to be free;
assign each project and lecturer to be totally unsubscribed;
while (some student si is free and si has a non-empty list) {
pj = first project on si ’s list;
lk = lecturer who offers pj ;
/* si applies to pj */
provisionally assign si to pj ; /* and to lk */
if (pj is over-subscribed) {
j
sr = worst student assigned to pj ; /* according to Lk */
break provisional assignment between sr and pj ;
}
else if (lk is over-subscribed) {
sr = worst student assigned to lk ;
pt = project assigned sr ;
break provisional assignment between sr and pt ;
}
if (pj is full) {
j
sr = worst student assigned to pj ; /* according to Lk */
j
for (each successor st of sr on Lk )
delete (st , pj );
}
if (lk is full) {
sr = worst student assigned to lk ;
for (each successor st of sr on Lk )
for (each project pu ∈ Pk ∩ At )
delete (st , pu );
}
}
return {(si , pj ) ∈ S × P : si is provisionally assigned to pj };
}
j j
student assigned to pj (according to Lk ) and delete (st , pj ) for each successor st of sr on Lk . Similarly if lk is full,
we let sr be the worst student assigned to lk , and delete (st , pu ) for each successor st of sr on Lk , and for each project
pu offered by lk that st finds acceptable.
The algorithm is described in pseudocode form in Fig. 2 as Algorithm SPA-student. We will prove that, once the
main loop terminates, the assigned pairs constitute the stable matching that is simultaneously best-possible for all
students.
The correctness of the algorithm, together with the optimality property of the constructed matching, may be estab-
lished by the following sequence of lemmas.
Proof. Each loop iteration involves a free student si applying to the first project pj on his/her preference list. No
student can apply to the same project twice, since, for example, once si is freed from pj , the pair (si , pj ) is deleted.
The total number of iterations is therefore bounded by the overall length of the student preference lists. Finally, it is
clear that, once the main loop terminates, the assigned pairs constitute a matching. 2
Lemma 3.2. No pair deleted during an execution of Algorithm SPA-student can block the constructed matching.
Proof. Let E be an arbitrary execution of the algorithm in which some pair (si , pj ) is deleted. Suppose for a con-
tradiction that (si , pj ) blocks M, the matching generated by E. Now (si , pj ) is deleted in E because either (i) pj
D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90 79
becomes full, or (ii) lk becomes full, where lk is the lecturer offering pj . We will show that in Case (i), (si , pj ) fails
(a), (b) and (c) of Condition 3 of a blocking pair. Case (ii) is easier: (si , pj ) cannot block M, since once full, a lecturer
never becomes under-subscribed, and is only ever assigned more preferable students. We now deal with Case (i), and
further consider the three sub-cases of Condition 3 of a blocking pair.
Proof. By Lemma 3.1, let M be the matching generated by an arbitrary execution E of the algorithm, and let (si , pj )
be any pair blocking M. We will show that (si , pj ) must be deleted in E, thereby contradicting Lemma 3.2. For, sup-
pose not. Then si must be assigned to some project M(si ) = pj , for otherwise si is free with a non-empty preference
list (containing pj ), thereby contradicting the fact that the algorithm terminates. Now when si applies to M(si ), M(si )
is the first project on his/her list. Hence, (si , pj ) must be deleted, since for (si , pj ) to block M, si must prefer pj to
M(si ). 2
For a given instance of SPA, we define a stable pair to be a (student, project) pair that belongs to some stable
matching. The next lemma shows that Algorithm SPA-student never deletes a stable pair.
Proof. Suppose for a contradiction that (si , pj ) is the first stable pair deleted during an arbitrary execution E of the
algorithm. Let M be the matching immediately after the deletion in E, and let M be any stable matching containing
(si , pj ). Now (si , pj ) is deleted in E because either (i) pj becomes full, or (ii) lk becomes full, where lk is the lecturer
offering pj . We consider each case in turn.
(i) Suppose that (si , pj ) is deleted because pj becomes full during E. Immediately after the deletion, pj is full, and
lk prefers all students in M(pj ) to si . Now, si ∈ M (pj )\M(pj ), and since pj is full in M, there must be some
s ∈ M(pj )\M (pj ). We will show that (s, pj ) forms a blocking pair, contradicting the stability of M .
Firstly, since (si , pj ) is the first stable pair deleted in E, s prefers pj to any of his/her stable partners (except
possibly for pj itself). Additionally, since (si , pj ) ∈ M and lk prefers s to si , it follows that lk prefers s to both
the worst student in M (pj ) and M (lk ). Clearly then, for any combination of lk and pj being full or under-
subscribed, (s, pj ) satisfies all the conditions to block M .
(ii) Suppose that (si , pj ) is deleted because lk becomes full during E. Immediately after the deletion, lk is full, and
lk prefers all students in M(lk ) to si . We consider two cases: |M (pj )| > |M(pj )| and |M (pj )| |M(pj )|.
Suppose firstly that |M (pj )| > |M(pj )|. Since lk is full in M, there must be some project p ∈ Pk \{pj } such
that |M (p)| < |M(p)|. We remark that p is therefore under-subscribed in M . Now let s be any student in
M(p)\M (p). Since (si , pj ) is the first stable pair deleted, s prefers p to any of his/her stable partners (except
possibly for p itself). Also, lk prefers s to si , and hence to the worst student in M (lk ). So, in either case that lk is
full or under-subscribed, (s, p) blocks M .
80 D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90
Now suppose that |M (pj )| |M(pj )|. Then since (si , pj ) ∈ / M, there is some s = si ∈ M(pj )\M (pj ). Now pj
is under-subscribed in M, for otherwise (si , pj ) is deleted because pj becomes full, contradicting the assumption
that deletion occurs because lk becomes full. Therefore, pj is under-subscribed in M . As above, s prefers pj to
any of his/her stable partners (except possibly for pj itself), since (si , pj ) is the first stable pair deleted. Also,
lk prefers s to si , and hence to the worst student in M (lk ). So, in either case that lk is full or under-subscribed,
(s, pj ) blocks M . 2
Theorem 3.5. For a given instance of SPA, any execution of Algorithm SPA-student constructs the stable matching
in which each assigned student is assigned to the best project that he/she could obtain in any stable matching, whilst
each unassigned student is unassigned in any stable matching.
Proof. By Lemma 3.3, let M be the stable matching generated by an arbitrary execution E of the algorithm. In M,
each student is assigned to the first project on his/her reduced preference list, if any. Also, by Lemma 3.4, no stable
pair is deleted during E. It follows then that in M, each assigned student is assigned to the best project that he/she
could obtain in any stable matching, whilst any unassigned student is unassigned in any stable matching. 2
Given the optimality property established by Theorem 3.5, we define the stable matching returned by Algorithm
SPA-student to be the student-optimal stable matching. For example, in the SPA instance given by Fig. 1, the student-
optimal stable matching is {(s1 , p1 ), (s2 , p5 ), (s3 , p4 ), (s4 , p2 ), (s7 , p3 )}.
In the next subsection, we show how to implement Algorithm SPA-student so that it runs in linear time.
The algorithm’s time complexity depends on how efficiently we can execute ‘apply’ operations and deletions, each
of which occur at most once for any (student, project) pair. It turns out that both operations can be implemented to run
in constant time, giving an overall time complexity of (λ), where λ is the total length of all the preference lists. We
briefly outline the non-trivial aspects of such an implementation.
For each student si , build an array, ranksi , where ranksi (pj ) is the index of project pj in si ’s preference list.
Represent si ’s preference list by embedding doubly linked lists in an array, preferencesi . For each project pj ∈ Ai ,
preferencesi (ranksi (pj )) stores the list node containing pj . This node contains two next pointers (and two previous
pointers)—one to the next project in si ’s list (after deletions, this project may not be located at the next array position),
and another pointer to the next project p in si ’s list, where p and pj are both offered by the same lecturer. Construct
this list by traversing through si ’s preference list, using a temporary array to record the last project in the list offered by
each lecturer. Use virtual initialisation (described in [3, p. 149]) for these arrays, since the overall (nq) initialisation
cost may be super-linear in λ. Clearly, using these data structures, we can find and delete a project from a given student
in constant time, as well as efficiently delete all projects offered by a given lecturer.
Represent each lecturer lk ’s preference list Lk by an array preferencelk , with an additional pointer, lastlk . Initially,
lastlk stores the index of the last position in preferencelk . However, once lk is full, make lastlk equivalent to lk ’s worst
assigned student through the following method. Perform a backward linear traversal through preferencelk , starting at
lastlk , and continuing until lk ’s worst assigned student is encountered (each student stores a pointer to their assigned
project, or a special null value if unassigned). All but the last student on this traversal must be deleted, and so the cost
of the traversal may be attributed to the cost of the deletions in the student preference lists.
j
For each project pj offered by lk , construct a preference array corresponding to Lk . These project preference arrays
are used in much the same way as the lecturer preference array, with one exception. When a lecturer lk becomes over-
subscribed, the algorithm frees lk ’s worst assigned student si and breaks the assignment of si to some project pj . If
pj was full, then it is now under-subscribed, and lastpj is no longer equivalent to pj ’s worst assigned student. Rather
than update lastpj immediately, which could be expensive, wait until pj is full again. The update then involves the
same backward linear traversal described above for lk , although we must be careful not to delete pairs already deleted
in one of lk ’s traversals. Since we only visit a student at most twice during these backward traversals, once for the
lecturer and once for the project, the asymptotic running time remains linear.
D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90 81
Theorem 3.6. Algorithm SPA-student may be implemented to run in (λ) time and O(mn) space, where λ is the total
length of the preference lists, and n, m are the numbers of students and projects respectively, in a given SPA instance.
In this section we consider properties of the set of stable matchings in a given instance of SPA. We begin by proving
a result similar to Theorem 2.1, the Rural Hospitals Theorem for HR, in the context of a given SPA instance.
(i) Each lecturer has the same number of students in all stable matchings.
(ii) Exactly the same students are unassigned in all stable matchings.
(iii) A project offered by an under-subscribed lecturer has the same number of students in all stable matchings.
Proof. Let M be the student-optimal stable matching, and let M be any other stable matching.
(i) Suppose |M (lk )| < |M(lk )| for some lecturer lk . There must be some project pj ∈ Pk such that |M (pj )| <
|M(pj )|. So, lk and pj are both under-subscribed in M . Also, there exists si ∈ M(pj )\M (pj ) who is unassigned
in M or prefers pj to M (si ), since M is student-optimal. Hence, (si , pj ) blocks M , and, therefore, |M (lk )|
|M(lk )| for all lk . It follows that |M | |M|. However, |M | |M|, since M is student-optimal and therefore
matches the maximum number of students of any stable matching. Hence |M | = |M|, and for all lk , |M (lk )| =
|M(lk )|.
(ii) Let U and U be the sets of students unassigned in M and M respectively. By Theorem 3.5, U ⊆ U , since no
student unassigned in M can be assigned in M . But |U | = |U |, by (i), and so it follows that U = U .
(iii) Let lk be any lecturer who is under-subscribed in M . Suppose there is some project pj ∈ Pk such that |M (pj )| <
|M(pj )|. Then pj is under-subscribed in M , and there exists si ∈ M(pj )\M (pj ) who is unassigned in M
or prefers pj to M (si ). Hence, (si , pj ) blocks M , and, therefore, |M (pj )| |M(pj )|. Now, by (i) above,
|M (lk )| = |M(lk )|, and so |M (pj )| = |M(pj )| for all pj ∈ Pk . 2
It turns out that two key properties of the Rural Hospitals Theorem for HR have no analogue for SPA. Firstly, we
give an instance of SPA illustrating that a lecturer who is under-subscribed in one stable matching need not be assigned
the same set of students in all stable matchings. Note that the Rural Hospitals Theorem for HR states that any hospital
that is under-subscribed in one stable matching is assigned the same set of residents in all stable matchings. However
consider the SPA instance I1 shown in Fig. 3. Instance I1 admits the stable matchings M = {(s1 , p3 ), (s2 , p1 )} and
M = {(s1 , p1 ), (s2 , p3 )}. Lecturer l1 is under-subscribed in M (and hence in M by Part (i) of Theorem 4.1). However
M(l1 ) = {s2 } whilst M (l1 ) = {s1 }.
Secondly, we give an instance of SPA illustrating that a project offered by a lecturer who is full in one stable match-
ing need not be assigned the same number of students in all stable matchings. Note that the Rural Hospitals Theorem
for HR states that each hospital is assigned the same number of residents in all stable matchings. However consider the
SPA instance I2 shown in Fig. 4. Instance I2 admits the stable matchings M = {(s1 , p1 ), (s2 , p1 ), (s3 , p3 ), (s4 , p3 )}
and M = {(s1 , p3 ), (s2 , p4 ), (s3 , p1 ), (s4 , p2 )}. Lecturer l1 is full in M (and hence in M by Part (i) of Theorem 4.1).
However M(p1 ) = {s1 , s2 } whilst M (p1 ) = {s3 }.
Project capacities: ci = 1 (1 i 4)
Lecturer capacities: di = 2 (1 i 2)
Project capacities: c1 = 2, c2 = 1, c3 = 2, c4 = 1
Lecturer capacities: d1 = 2, d2 = 2
Finally we consider the issue of load balancing project supervision among lecturers. Theorem 4.1(i) might seem
to imply that this issue is not relevant in our model. However load balancing can be achieved if each lk ∈ L is
constrained (for example by the Head of Department) to set dk = qn (recall our assumption from Section 2 that
{cj : pj ∈ Pk } dk ). Once Algorithm SPA-student has been run, the matched students would be removed, any
unmatched student would be invited to submit a longer preference list chosen from the remaining under-subscribed
projects, and the capacities of the under-subscribed projects and lecturers would be suitably adjusted. Then a “second
round” of the algorithm could be used to assign the remaining students, ensuring that the students are distributed
equitably among the lecturers.
We now present the lecturer-oriented counterpart of Algorithm SPA-student. The lecturer-oriented algorithm for
an instance of SPA begins with the empty assignment, in which all students are free, and every project and lecturer is
totally unsubscribed. The algorithm then enters a loop, each iteration of which involves an under-subscribed lecturer
lk offering a project pj ∈ Pk to a student si . Student si must be the first student on lk ’s list who is currently free or
prefers an under-subscribed project in Pk to his/her current provisional assignment. Additionally, pj must be the first
such under-subscribed project from Pk on si ’s preference list. This offer is always accepted, and after breaking any
existing assignment involving si , si is provisionally assigned to pj and lk . Following this assignment, any pair (si , p),
where si prefers pj to p is deleted, which means that p is removed from si ’s preference list, and si is removed from
the projected preference list of lr for p, where lr is the lecturer who offers p. The algorithm continues in this loop
until no such lk , pj and si can be found.
SPA-lecturer(I ) {
assign each student, project and lecturer to be free;
while (some lecturer lk is under-subscribed and
there is some (student, project) pair (si , pj ) where
si is not provisionally assigned to pj and
j
pj ∈ Pk is under-subscribed and si ∈ Lk )
{
si = first such student on lk ’s list;
pj = first such project on si ’s list;
if (si is provisionally assigned to some project p)
break the provisional assignment between si and p;
/* lk offers pj to si */
provisionally assign si to pj ; /* and to lk */
for each successor p of pj on si ’s list
delete (si , p);
}
return {(si , pj ) ∈ S × P : si is provisionally assigned to pj };
}
The algorithm is described in pseudocode form in Fig. 5 as Algorithm SPA-lecturer. We will prove that, once the
main loop terminates, the assigned pairs constitute the stable matching that is simultaneously best-possible for all
lecturers.
The correctness of the algorithm, together with the optimality property of the constructed matching, may be estab-
lished by the following sequence of lemmas.
Proof. Each loop iteration involves a provisional assignment: either the first assignment for a student, or an assign-
ment that the student prefers to his/her previous assignment. Therefore, the number of iterations is bounded by the
total length of the student preference lists, which is linear in the size of the input. Finally, it is clear that, once the main
loop terminates, the assigned pairs constitute a matching. 2
Lemma 5.2. No pair deleted during an execution of Algorithm SPA-lecturer can block the constructed matching.
Proof. Let E be an arbitrary execution of the algorithm in which some pair (si , pj ) is deleted. Suppose for a con-
tradiction that (si , pj ) blocks M, the matching generated by E. Now (si , pj ) is deleted because si is provisionally
assigned to some project p, where si prefers p to pj . On subsequent iterations, si can only improve his/her assign-
ment, and so, by transitivity, si prefers his/her final assignment to pj . Therefore, (si , pj ) cannot form a blocking
pair. 2
Proof. By Lemma 5.1, let M be the matching generated by an arbitrary execution E of the algorithm. Suppose for a
contradiction that M is blocked by the pair (si , pj ), where lk is the lecturer offering pj . By Lemma 5.2, (si , pj ) is not
j
deleted, and so, upon termination of E, si ∈ Lk . Also, we have that (si , pj ) must satisfy (a), (b) or (c) of Condition 3
for a blocking pair. We show a contradiction in each case.
Now, since all assignments in M involving lk that were made after time T only involve projects from F (Prop-
erty 1) and all projects in F are full in M (Property 2), we have that
M(lk ) M (pf ) + M(pj ) + M (pg ).
pf ∈F \{pj } pg ∈Pk \F
Finally, we are given that pj is under-subscribed at the termination of E (Condition (b)). Therefore
M(lk ) < M (pf ) + M (pj ) + M (pg ) = M (lk ) dk
pf ∈F \{pj } pg ∈Pk \F
Proof. Suppose, for a contradiction, that (si , pj ) is the first stable pair deleted during an arbitrary execution E of
the algorithm. Let M be a stable matching containing (si , pj ). The deletion of (si , pj ) during E occurs because si is
provisionally assigned to a project p , where si prefers p to pj . Let l be the lecturer offering p , and let c and d be
the capacities of p and l respectively.
The number of stable pairs (s , p ) for which l prefers s to si must be less than c , for otherwise, one of these
pairs must be deleted before si is assigned to p during E, contradicting the assumption that (si , pj ) is the first stable
pair deleted in E. Therefore in M, since (si , p ) ∈ / M, either (i) p is under-subscribed, or (ii) p is full and assigned a
student inferior to si .
We will prove that (si , p ) blocks M. Firstly, we have that si prefers p to pj , and so (si , p ) satisfies Conditions 1
and 2 of a blocking pair. It remains to show that (si , p ) satisfies Condition 3(a), (b) or (c) of a blocking pair. If (ii)
above holds, then (si , p ) satisfies Condition 3(c). Otherwise, (i) holds, and p is under-subscribed in M.
If l is under-subscribed in M, then (si , p ) satisfies Condition 3(a). Otherwise l is full in M, and the only way
(si , p ) cannot satisfy Condition 3(b) is if l is assigned d students in M, each of whom he/she prefers to si . We will
show a contradiction for this case.
Since M is a stable matching, each of these d assignments forms a stable pair. Now, for l to offer p to si in E,
only 0 z < d of these stable pairs are assigned (since l must be under-subscribed to make an offer). However, none
of the d stable pairs is deleted before the offer to si in E, for otherwise (si , pj ) is not the first stable pair deleted. So,
it must be the case that for the d − z unassigned stable pairs in E, each of the projects in these pairs is full (otherwise,
the next offer from l in E would involve one of the unassigned stable pairs, not si and p ). But then l is full when
the offer of p is made to si in E, giving the required contradiction. 2
In the Hospitals/Residents problem, the hospital-oriented algorithm generates a stable matching M that is unequiv-
ocally optimal for the hospitals—as mentioned in Section 2.2, M satisfies the property that there is no stable matching
M and hospital h for which h prefers a resident in M (h)\M(h) to the worst resident in M(h). On the other hand, M
is the worst possible stable matching for the residents—no stable matching assigns any resident to a worse hospital.
In our context, the stable matching produced by Algorithm SPA-lecturer is again unequivocally student-pessimal.
However, the optimality situation is a little different. It can again be viewed as lecturer-optimal in a precise, if some-
what less emphatic sense.
In the example instance of Fig. 6, the matching M = {(s1 , p1 ), (s2 , p3 ), (s3 , p2 ), (s4 , p4 )} is produced by an exe-
cution of Algorithm SPA-lecturer. However the matching M = {(s1 , p3 ), (s2 , p1 ), (s3 , p4 ), (s4 , p2 )} is also stable. In
D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90 85
Fig. 6. A SPA instance to illustrate that lecturer optimality differs from that in HR.
M , each lecturer is assigned a student whom he/she prefers to one of the students whom he/she is assigned in M.
Hence it is not the case that, in M, either lecturer is assigned the best two students that he/she can be assigned in any
stable matching.
The somewhat weaker form of optimality that applies in this context can be described as follows. Let M and M be
two stable matchings for a given instance of SPA. By Theorem 4.1, we know that |M| = |M | and |M(lk )| = |M (lk )|.
For a given lecturer lk who is assigned different sets of students in M and M , let
Theorem 5.5. For a given instance of SPA, any execution of Algorithm SPA-lecturer constructs the stable matching
M satisfying the following properties.
(i) Each student is unassigned or is assigned to the worst project he/she has in any stable matching.
(ii) Each project pj is assigned the first xj students not deleted from the projected preference list for pj (where xj
is an integer independent of execution).
(iii) Each lecturer prefers M to any stable matching in which he/she has a different set of assigned students.
Proof.
(i) Let si be any student assigned in M. Algorithm SPA-lecturer deletes all successors of M(si ) from si ’s preference
list. Now, by Lemma 5.4, no stable pair is deleted, and so si can have no worse partner than M(si ) in any stable
matching. Hence, each student is either unassigned in M, and therefore in any stable matching (Theorem 4.1), or
assigned to the worst project that he/she has in any stable matching.
j
(ii) Suppose there is some (student, project) pair (si , pj ) ∈
/ M, such that si is not deleted from Lk , where lk is the
lecturer offering pj , and lk prefers si to the worst student s in M(pj ). Since (si , pj ) is not deleted in E, si is
either unassigned in M, or prefers pj to M(si ). So, (si , pj ) is a blocking pair, contradicting the stability of M.
(iii) Let M be any other stable matching, and let lk be an arbitrary lecturer who is assigned different sets of students
in M and M . We construct a one-to-one mapping f from M (lk ) \ M(lk ) to M(lk ) \ M (lk ) with the required
property.
Define a student s ∈ M (lk ) \ M(lk ) to be a dominated student in Lk if lk prefers every student in M(lk ) to s. For
each such student s we have a free choice for f (s). So we can complete the one-to-one mapping arbitrarily by
dealing with these students once f has been defined for the other students in M (lk ) \ M(lk ).
So let si1 be a student in M (lk ) \ M(lk ) who is preferred by lk to at least one of the students in M(lk ), and
suppose that (si1 , pj1 ) ∈ M , where lk offers pj1 . By part (i) above, si1 prefers pj1 to the project to which he/she
is assigned in M. So to avoid (si1 , pj1 ) being a blocking pair for M, either
86 D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90
• pj1 is fully subscribed in M with students whom lk prefers to si1 ; let si2 be such a student who is in M(pj1 ) \
M (pj1 ); or
• pj1 is under-subscribed in M but lk is fully subscribed in M with students preferable to si1 .
However, we may reject the second possibility in view of our assumption that si1 is not dominated in Lk , so we
can consider the student si2 .
/ M (lk ) we let f (si1 ) = si2 . Otherwise, by (i) above, there is a project pj2 offered by lk such that (si2 , pj2 ) ∈
If si2 ∈
M \ M, where si2 prefers pj2 to pj1 . To avoid (si2 , pj2 ) being a blocking pair for M, pj2 must be fully subscribed
in M with students whom lk prefers to si2 ; let si3 be such a student who is in M(pj2 ) \ M (pj2 ). (Note that, since
lk prefers si2 to si1 , and therefore cannot prefer all the students in M(lk ) to si2 , we may again ignore the other
possibility.)
/ M (lk ) we let f (si1 ) = si3 . Otherwise we continue in this way to generate a sequence si4 , . . . , sit of
If si3 ∈
students, each member of which is preferred by lk to its predecessor. Since the number of students is finite, this
sequence must terminate with a student sit ∈ M(lk ) \ M (lk ) such that lk prefers sit to si1 , and we set f (si1 ) = sit .
The sequence si1 , . . . , sit is such that
• si1 ∈ M (lk ) \ M(lk )
• sir ∈ M (lk ) ∩ M(lk ) for 1 < r < t
• sit ∈ M(lk ) \ M (lk )
• lk prefers sir to sir−1 for 1 < r t .
Additionally, we need to ensure that, if the same project occurs in the sequences originating with more than one
of the students in M (lk ) \ M(lk ), we can choose a unique student matched to that project in M \ M on each
occasion. For, suppose px is such a project that arises r times from pairs (su1 , px ), . . . , (sur , px ) ∈ M \ M. So,
arguing as before, px must be fully subscribed in M with students whom lk prefers to all of su1 , . . . , sur . Clearly
there must be at least r such students from which to choose, and a different one can be chosen in each sequence.
Finally, as indicated earlier, we complete the one-to-one mapping f in an arbitrary way for the dominated stu-
dents. Hence f is, as claimed, a one-to-one mapping from M (lk ) \ M(lk ) to M(lk ) \ M (lk ) with the property
that lk prefers f (s) to s for all s. Hence lk prefers M to M . The argument may be repeated for each relevant
lecturer, and the result follows. 2
In the next subsection, we show how to implement Algorithm SPA-lecturer so that it runs in linear time.
Even with the specialised data structures described in Section 3.3, it is not immediately clear whether Algorithm
SPA-lecturer can be implemented to run in linear time. Consider for example the execution trace in Fig. 7.
Fig. 7. A SPA instance I , together with an execution trace of Algorithm SPA-lecturer as applied to I .
D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90 87
The sequence of offers made by l1 , i.e. (s2 , p1 ), (s1 , p2 ), (s4 , p3 ), (s1 , p1 ), (s3 , p2 ) , highlights two major differ-
ences between Algorithm SPA-lecturer and the hospital-oriented algorithm for HR. Firstly, a lecturer can make more
than one offer to the same student (l1 offers both p2 and p1 to s1 ), and secondly, a lecturer may not make offers in
order of preference (l1 offers p3 to s4 before s3 is made an offer).
Of course, the reason for these differences is that a project and lecturer can become under-subscribed after being
full. For example, in step (ii) of the execution, p1 is full, and so s1 is assigned to his/her second preference, p2 . This
makes p2 full, which means that l1 is not immediately able to make an offer to s3 . However, in step (iv), s2 accepts a
more preferable project, thereby freeing p1 for s1 , which in turn frees p2 for s3 . Also l1 was full just after step (iii),
but under-subscribed just after step (iv).
The main problem then is how to efficiently find the next student to whom a given lecturer lk can make an offer
(since Pk may contain several projects that have become under-subscribed). It turns out that we can overcome this
problem by restricting the non-deterministic choice of lk in the main loop of Algorithm SPA-lecturer. Consider the
implementation given in Fig. 8.
For each lecturer lk , we maintain a pointer nextlk , which initially refers to the first student in Lk . Also, for each
j
project pj ∈ Pk , we maintain a pointer nextpj , which initially refers to the first student in Lk . In the implementation,
lk repeatedly makes an offer to nextlk , which moves left to right through Lk , advancing one student at a time. If
SPA-lecturer(I ) {
assign each student, project and lecturer to be free;
assign p to be undefined;
let S be a stack consisting of all lecturers;
while (S = ∅) {
/* we seek a provisional assignment of student si to project pj and lecturer lk */
if (p is defined) { /* p has just become under-subscribed */
pj = p;
lk = lecturer offering pj ;
si = nextpj ;
assign p to be undefined;
} else {
lk = S.pop();
if (lk is full or nextlk is undefined)
continue; /* to the next loop iteration */
si = nextlk ;
advance nextlk by one student;
S.push(lk );
if (si ’s list contains no under-subscribed project in Pk )
continue; /* to the next loop iteration */
pj = first such project on si ’s list;
}
advance nextpj by one student;
if (si is provisionally assigned to some project p and lecturer l ) {
if (p is full and nextp is defined and
(nextl is undefined or l prefers nextp to nextl ))
p = p ;
break provisional assignment between si , p and l ;
}
provisionally assign si to pj and lk ;
for (each successor p of pj on si ’s list) {
if (si == nextp )
advance nextp by one student;
delete (si , p );
}
}
return {(si , pj ) ∈ S × P : si is provisionally assigned to pj };
}
nextlk is already provisionally assigned to some project p and lecturer l , project p may become under-subscribed
having previously been full (since nextlk leaves p ). At this point, the next offer made by l can only involve one of
two students—nextl , or nextp , where nextp is maintained as the first student not assigned to p on the projected
preference list of l for p . If nextp is defined, and either nextl is undefined or l prefers nextp to nextl , we require
that l makes an offer to nextp in the next loop iteration. Alternatively, if l prefers nextl to nextp , student nextp is in
the scope of the variable nextl , and so l can revert to making offers to nextl as usual. By making this decision when
there are only two possibilities (nextp and nextl ), we avoid the problem of choosing among several students when l
next makes an offer.
We briefly outline the other data structures used in the linear-time implementation. For each student si , we construct
an array preferencesi , the kth element of which is the kth-ranked post in si ’s preference list. Additionally, as in
Algorithm SPA-student, we use next and previous pointers to link together the projects in this list that are offered by a
given lecturer. When a lecturer lk makes an offer to si , we can follow these pointers to find the first under-subscribed
project from Pk in si ’s list. Such a traversal happens at most once for each lecturer, and so no project in si ’s preference
list is visited more than a constant number of times. We also remark that all successors of a given project can be
deleted from si ’s preference list simply by traversing the underlying array.
For each lecturer lk , we build an array, ranklk , where ranklk (si ) is the index of student si in Lk . We represent Lk
by an array, preferencelk , where preferencelk (ranklk (si )) stores student si . Each lecturer lk also stores a count of the
number of students whom they are provisionally assigned, and a pointer nextlk into preferencelk , as described earlier.
For each project pj offered by lk , we build an array rankpj , where rankpj (si ) is the index of student si
j j j
in Lk . We represent Lk by embedding a doubly-linked list in an array preferencepj . For each student si ∈ Lk ,
j
preferencepj (rankpj (si )) stores the list node containing si . This node has a pointer to the next student in Lk , and
j
one to the previous student in Lk . Each project also stores a count of the number of students whom it is provisionally
assigned, and a pointer nextpj into preferencepj , as described earlier.
Using these data structures, we can find and delete a student from a project’s preference list in constant time. For
each preference list, we can also compare the ranks of any two students, and efficiently traverse through the sequence
of students, missing out any students that have been deleted.
The above discussion therefore leads to the following result.
Theorem 5.6. Algorithm SPA-lecturer may be implemented to run in (λ) time and O(mn) space, where λ is the total
length of the preference lists, and n, m are the numbers of students and projects respectively, in a given SPA instance.
6. Concluding remarks
The definition of a blocking pair (si , pj ) considered in this paper includes the possibility that si was already
assigned in M to a project offered by lk , where lk is the lecturer offering pj , and seeks to become assigned to a
preferred project pj offered by the same lecturer. Such a switch obviously cannot alter the total number of students
assigned to lk .
If pj is under-subscribed in M, then pj has room for si , and lk is implicitly indifferent about the switch, so would
not prevent it from taking place. However if pj is full in M, then the only way that the switch could occur is if lk
rejects a student from pj . Moreover, lk would agree to such a switch only if lk prefers si to the worst student s
assigned to pj in M. But this implies that, following the rejection of s , the number of students assigned to lk would
decrease by 1 if s is unable to move to a worse project offered by lk .
The following small SPA instance illustrates this phenomenon. We have two students, s1 , s2 , two projects, p1 , p2 ,
and one lecturer, l1 . Each of p1 and p2 has capacity 1, whilst l1 has capacity 2. Student s1 prefers p1 to p2 , whilst s2
finds only p1 acceptable. Lecturer l1 prefers s1 to s2 . Clearly then, the matching M1 = {(s1 , p2 ), (s2 , p1 )} admits the
blocking pair (s1 , p1 ), whilst M2 = {(s1 , p1 )} is the only stable matching.
In going from M1 to M2 , we satisfy the blocking pair (s1 , p1 ); however in doing so, l1 loses a student, so in practice
he/she may not agree to the switch. Hence one could alter Condition 3(c) of the blocking pair definition to prevent a
change such as this from taking place. However we make two counter-arguments.
D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90 89
Firstly, by allowing a matching such as M1 to be stable, we introduce an element of strategy into the problem. That
is, it could be in a student’s interest to submit a shorter preference list in order to obtain a more preferable project,
rather than to submit his/her true preferences. For example, in the above instance, s1 could list only p1 . In doing so,
s1 would be assigned to p1 under either definition of Condition 3(c). On the other hand, by not listing every project
that he/she finds acceptable, a student assumes a greater risk of being unassigned in the final matching.
Secondly, allowing both M1 and M2 to be stable would imply that this instance admits stable matchings of different
sizes. Hence, to match as many students as possible, we would seek a maximum cardinality stable matching. However
we conjecture that this problem is NP-hard. Evidence for this is given by the apparent lack of structure in this case:
if both M1 and M2 are stable, there is no student-optimal stable matching. This is in contrast with the structure that
follows from the definition of Condition 3(c) as adopted in this paper. In this context we have been able to prove several
desirable properties of SPA, including an analogue of the Rural Hospitals Theorem (Theorem 4.1), and the existence
of student-optimal and lecturer-optimal stable matchings (Theorems 3.5 and 5.5 respectively). With stable matching
problems in general, it is often the case [11] that the existence of structural properties and efficient algorithms are
closely related to one another.
In this paper we introduced SPA, and studied this problem from an algorithmic and structural point of view. A num-
ber of interesting open problems remain, including the following:
• Clearly many different formulations of the SPA model are possible. If only students supply preference lists, then
a matching that optimises the students’ satisfaction may be constructed using network flow techniques (see [1]
for further details). Additionally, as in this paper, lecturers may supply preference lists, but over the projects that
they offer rather than over students. We have considered this model from an algorithmic viewpoint—see [16]
for further details. Finally, lecturers may have preferences over (student, project) pairs. In this setting, Fleiner
[8] noted that the matroid-theoretic characterisation as described in Section 2.3 is applicable if a certain stability
definition is imposed. However with this definition of stability there are strategic issues similar to those outlined
in the previous subsection. It remains open as to whether a stability definition for this case can be formulated that
leads to efficient algorithms, whilst avoiding such issues of strategy.
• If we allow ties in the preference lists of students and lecturers, different stability definitions are possible. These
can be obtained by extending three stability definitions that have been applied to the Hospitals/Residents problem
with Ties [12,13]. Under the weakest of these stability criteria, so-called weak stability, every instance of SPA with
ties admits a stable matching (this follows by breaking the ties arbitrarily and applying Algorithm SPA-student to
the resulting instance of SPA, for example). However such matchings could be of different sizes for a given SPA
instance with ties, and the problem of finding a maximum weakly stable matching is NP-hard (this follows by
restriction, since the same problem has been shown to be NP-hard in the case of SMI with ties [15]). Under the
two stronger stability criteria, namely strong stability and super-stability, an instance of SPA with ties need not
admit a matching satisfying either criterion. However it remains open to construct algorithms for finding such a
matching in each case, or reporting that none exists, for a given instance of SPA with ties.
• A further natural extension arises when each project pj carries a lower bound xj 0. That is, pj cannot run
unless at least xj students are assigned to it. Clearly a stable matching need not exist that satisfies all the projects’
lower bounds. If lower bounds were present for hospitals in the case of HR, the problem of deciding whether a
stable matching exists that satisfies them would be trivial, in view of the Rural Hospitals Theorem (i.e. find one
stable matching, and if it does not satisfy the lower bounds, then no other stable matching does). However in
view of the discussion following Theorem 4.1, the same is not true in the case of SPA. It is open as to whether
there exists a polynomial-time algorithm for finding a stable matching if one exists, given an instance of SPA with
lower bounds for the projects.
Acknowledgements
We would like to thank Tamás Fleiner for helpful discussions concerning the SPA problem model, and also the
anonymous referees for their detailed comments, which have helped to improve the presentation of this paper.
90 D.J. Abraham et al. / Journal of Discrete Algorithms 5 (2007) 73–90
References
[1] D.J. Abraham, Algorithmics of two-sided matching problems, Master’s thesis, University of Glasgow, Department of Computing Science,
2003.
[2] A.A. Anwar, A.S. Bahaj, Student project allocation using integer programming, IEEE Transactions on Education 46 (3) (2003) 359–367.
[3] G. Brassard, P. Bratley, Fundamentals of Algorithmics, Prentice-Hall, 1996.
[4] J. Dye, A constraint logic programming approach to the stable marriage problem and its application to student-project allocation, BSc Honours
project report, University of York, Department of Computer Science, 2001.
[5] A. Eguchi, S. Fujishige, A. Tamura, A generalized Gale–Shapley algorithm for a discrete-concave stable marriage model, in: Proceedings of
ISAAC 2003: The 14th Annual International Symposium on Algorithms and Computation, in: Lecture Notes in Computer Science, vol. 2906,
Springer-Verlag, 2003, pp. 495–504.
[6] T. Fleiner, A matroid generalization of the stable matching polytope, in: Proceedings of IPCO ’01: The 8th Conference on Integer Programming
and Combinatorial Optimization, in: Lecture Notes in Computer Science, vol. 2081, Springer-Verlag, 2001, pp. 105–114.
[7] T. Fleiner, A fixed-point approach to stable matchings and some applications, Mathematics of Operations Research 28 (1) (2003) 103–126.
[8] T. Fleiner, Personal communication, 2004.
[9] D. Gale, L.S. Shapley, College admissions and the stability of marriage, American Mathematical Monthly 69 (1962) 9–15.
[10] D. Gale, M. Sotomayor, Some remarks on the stable matching problem, Discrete Applied Mathematics 11 (1985) 223–232.
[11] D. Gusfield, R.W. Irving, The Stable Marriage Problem: Structure and Algorithms, MIT Press, 1989.
[12] R.W. Irving, D.F. Manlove, S. Scott, The hospitals/residents problem with ties, in: Proceedings of SWAT 2000: The 7th Scandinavian Work-
shop on Algorithm Theory, in: Lecture Notes in Computer Science, vol. 1851, Springer-Verlag, 2000, pp. 259–271.
[13] R.W. Irving, D.F. Manlove, S. Scott, Strong stability in the hospitals/residents problem, in: Proceedings of STACS 2003: The 20th Annual
Symposium on Theoretical Aspects of Computer Science, in: Lecture Notes in Computer Science, vol. 2607, Springer-Verlag, 2003, pp. 439–
450.
[14] D. Kazakov, Co-ordination of student-project allocation, Manuscript, University of York, Department of Computer Science, 2002.
[15] D.F. Manlove, R.W. Irving, K. Iwama, S. Miyazaki, Y. Morita, Hard variants of stable marriage, Theoretical Computer Science 276 (1–2)
(2002) 261–279.
[16] D.F. Manlove, G. O’Malley, Student project allocation with preferences over projects, in: Proceedings of ACID 2005: The 1st Algorithms and
Complexity in Durham workshop, in: Texts in Algorithmics, vol. 4, KCL Publications, 2005, pp. 69–80.
[17] C. Ng, D.S. Hirschberg, Lower bounds for the stable marriage problem and its variants, SIAM Journal on Computing 19 (1990) 71–77.
[18] National Resident Matching Program, About the NRMP, Web document available at http://www.nrmp.org/about_nrmp/how.html.
[19] National Resident Matching Program, Why the Match? Web document available at http://www.nrmp.org/whythematch.pdf.
[20] L.G. Proll, A simple method of assigning projects to students, Operational Research Quarterly 23 (2) (1972) 195–201.
[21] A. Romero-Medina, Implementation of stable solutions in a restricted matching market, Review of Economic Design 3 (2) (1998) 137–147.
[22] A.E. Roth, The evolution of the labor market for medical interns and residents: a case study in game theory, Journal of Political Economy 92 (6)
(1984) 991–1016.
[23] A.E. Roth, On the allocation of residents to rural hospitals: a general property of two-sided matching markets, Econometrica 54 (1986)
425–427.
[24] A.E. Roth, M.A.O. Sotomayor, Two-Sided Matching: A Study in Game-Theoretic Modeling and Analysis, Econometric Society Monographs,
vol. 18, Cambridge University Press, 1990.
[25] C.-P. Teo, J. Sethuraman, W.-P. Tan, Gale–Shapley stable marriage problem revisited: strategic issues and applications, in: Proceedings of
IPCO ’99: The 7th Conference on Integer Programming and Combinatorial Optimization, in: Lecture Notes in Computer Science, vol. 1610,
Springer-Verlag, 1999, pp. 429–438.
[26] C.Y. Teo, D.J. Ho, A systematic approach to the implementation of final year project in an electrical engineering undergraduate course, IEEE
Transactions on Education 41 (1) (1998) 25–30.
[27] M. Thorn, A constraint programming approach to the student-project allocation problem, BSc Honours project report, University of York,
Department of Computer Science, 2003.