You are on page 1of 2

Algorithm 2 Deferred Acceptance (Full version allowing multiple rounds and multiple candi-

dates with the same rank)


INPUTS:
Candidates A, Programs P
For each x ∈ A:
Preference list Pref(x)
Optional input: integer i(x). Default value i(x) = 1. (Start from beginning of preference
list by default.)
For each p ∈ P:
Capacity c(p) and merit list Merit(p).
Optional input: WaitList(p).
Optional input: Min-Cutoff(p). 0 by default.
Optional input: Q a queue of candidates. By default contains all candidates x with
Length(Pref(x)) > 0.

OUTPUTS:
For each candidate x ∈ A, the allocation µ(x) ∈ P ∪ {∅} and i(x).
Also for each program p ∈ P, the list of admitted candidates WaitList(p)

1: for all p ∈ P do
2: Create an empty ordered list WaitList(p) that will consist of
3: candidates ordered by their rank in Merit(p)
4: end for
5: Create an empty queue Q
6: for all x ∈ A do
7: i(x) ← 1 . Initialize list position to 1.
8: if Length(Pref(x)) > 0 then
9: Enqueue(x,Q) . x enters queue Q
10: end if
11: end for
12: while Q is non-empty do
13: x ← Dequeue(Q) . x is any candidate removed from queue Q
14: p ← px,i(x) . x applies to program px,i(x)
15: if x is not eligible for p OR c(p) = 0 then
16: Reject(x)
17: continue . move to next person in Q
18: end if
19: Insert x into ordered list WaitList(p) at correct location
20: if Length(WaitList(p)) ≤ c(p) then continue . space in program
21: end if
22: y ← Last candidate in WaitList(p)
23: if rank(y)>MinCutOff(p) then RemoveAndReject(y, p)
24: end if
25: end while

14
26: for all x ∈ A do
27: if i(x) ≤ Length(Pref(x)) then
28: µ(x) ← px,i(x)
29: else . x reached the end of her list
30: µ(x) ← ∅
31: end if
32: end for
33: return µ(x), i(x) for all x ∈ A and WaitList(p) for all p ∈ P
34: function Reject(x) . The function is assumed to have access to i(x), Pref(x), Q
35: Increment i(x)
36: if i(x) ≤ Length(Pref(x)) then . x wants to apply further
37: Enqueue(x,Q) . x enters queue Q again
38: end if
39: end function
40: function RemoveAndReject(w, p)
41: G ← |WaitList(p)|
42: L ← number of people with rank same as w . L is at least 1
43: if (G − L) ≥ c(p) then
44: for all x ∈ WaitList(p) with Rank(x, p) = Rank(w, p) do
45: Remove x from WaitList(p)
46: Reject(x)
47: end for
48: end if
49: end function

15

You might also like