Posted by: jrplewak | September 26, 2010

## Lecture 11

(Guest post by Jeff Plewak)

Today we discussed the implementation and analysis portion of the
Gale-Shapley algorithm.

Implementation Steps:

(i) How to represent input?

Can we choose data structures?

(ii) How to find a free woman w ?
Represent Same information in multiple forms

(iii) How would w pick her best unproposed man m?

(iv) How do we know who m is engaged to w?

(v) How do we decide if m prefers w’ to w?

We will be showing how we can implements steps i – v in O(1) time.

_____________________________________
Access ith         O(1)      O(i)
element
Is e present?      O(n)*     O(n)

insert                  O(n)      O(1) given pointer

delete                  O(n)      O(1) given pointer

Static vs Dynamic    Static    Dynamic

* nlogn if sorted

The goal is to show how the following can be implemented in O(1) time.

Assume:

M = { 1 . . . n }
W = { 1. . . n }

n specifies M and W

• 2n Arrays ( 2 two dimensional Arrays )
• Woman – Pref[w,i]

How to find free woman?

• Use Linked Lists. O(1) insertion/deletion
• Maintain Linked list of free woman.
• Initially all woman are in this list.
• Pick “first” free woman in the list
• Adding woman to the front of the list at “first” pointer

• w proposes to men according to her preference list.
• Use array, Next
• Next[w] = rank of next man she would propose to.
• w proposes to Woman – Pref[w, Next[w]]

Initialization? O(n)
Update time? O(1)

next[w]++ after every proposal

We saw how to answer three of those five questions.

– Jeff Plewak