Posted by: rsachdev | September 26, 2010

Lecture 11

(Guest post by Robin Sachdev)

In this lecture we focused on the runtime analysis of the Gale – Shapley Algorithm.

We quickly went over the asymptotic notations

O <=
Ω >=
Θ =

Then we proceeded to quickly brush up the Gale – Shapely Algorithm and proved its correctness.

We then discussed the five questions mentioned below, all these questions are to display the efficiency of the Gale – Shapely Algorithm.

Ques 1) How to represent the input?

Ques 2) How do we find a free woman w?

Ques 3) How do we pick w’s “best unproposed man m?

Ques 4) How do we know who m is engaged to?

Ques 5) How do we decide if m prefers w’ to w?

Before we got into answering the questions we briefly discussed data structures.

We discussed Arrays and Linked List

We saw a diagram of both the Arrays and Linked List and discussed the time taken to perform various actions on each.

Action        Array                                Linked List

Access          O(1)                                      O(i)

search      O(n)(O(log n) if sorted)    O(n)

Insert        O(n)                                        O(1)

Delete        O(n)                                       O(1)

And finally, Arrays are static as opposed to Linked Lists which are dynamic.

So we went ahead to prove that Gale – Shapely Algorithm  can be implemented in O(n^2)

Ques 1) How to represent the input?

We assumed

M = {1, ….. , n}

W = {1, ….. , n}

n specifies M and W

We decided that the data can be represented through 2n arrays ( 2 Dimensional Array)

man-pref [m,i] -> i’th preferred woman for m

woman-pref [w,i] -> i’th preferred man for w

Ques 2) How do we find free woman ?

At the beginning all women are free.

Maintain a linked list of free women.
Initially all women are free.
Pick “first” free woman in the list.
Add new free woman at “first” pointer.

Ques i) Time for initialization ?

The time for initialization is O(n), since it occurs before the while loop.

Ques ii) Time for updates?

The time for updates is O(1), and it occurs with in the while loop.


Ques 3) w proposes to men according to her preference list

We create an Array next, where next[w] is the rank of next man w should propose to.

w proposes to woman-pref [w, next[w]].

Ques i) Intialization time? O(n)

Ques ii) Update time? O(1)

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: