he algorithm 1s very similar to the basic Gale-Shapley algorithm from the text. At any
point in time, a stulent is either “rommitted” to a hospital ar “free.” A hospital either has
ayailable positions, or it is “full.” ‘The algorithm is the following:
While sone hospital fh; has available positions
h; offers a position to the next student s; on its pro:
if sj 18 Tree then
8; accepts the offer
else (s; is already committed to a hospital hy)
Af sj prefers fy to fy then
3) remains committed to hu
else 5; becomes committed to hy
‘The number of available positions at /i, Increases vy one.
the number of available positions at hi, decreases by one.
‘The algorithin terminates in O(n) steps becansc cach hospital offers a positions to a
student at most once, and in each iteration, some hospital offers a position to some student.
Suppose there are p; > 0 positions available at hospital hy. The algorithm terminates
with an assignment in which all available positions are filled, because any hospital that die
not fill all its positions must have offered one to every student; but then, all these students
would be committed to some hospital, which contradicts our assumption that, 37", ps