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.

Trade offs Array vs Linked List

Array    Linked List
_____________________________________
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

Answering (i):

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


Answering (ii):

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


Answering (iii)

  • 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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: