{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Final Exam 2010

# B 1 point translate line 2 of the pseudocode into sql

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ference, marry the men and women off such that there are no two people of opposite sex who would both rather have each other than their current partners. If there are no such people, all the marriages are "stable". The (arguably old-fashioned) algorithm at Wikipedia has the following pseudocode: 1 function stableMatching { 2 Initialize all m ∈ M and w ∈ W to free 3 while ∃ free man m who still has a woman w to propose to { 4 w = m's best ranked such woman who he has not proposed to yet 5 if w is free 6 (m, w) become engaged 7 else some pair (m', w) already exists 8 if w prefers m to m' 9 (m, w) become engaged 10 m' becomes free 11 else 12 (m', w) remain engaged 13 } 14 } We will implement a batch-oriented scalable version of this algorithm in SQL using the following schema. The first two tables are the input to the algorithm, the last four are used in the implementation.  ­ ­ for each male, store a pref for each female  ­ ­ the lower the better (1 is best, 2 is 2nd ­best, etc). status is either  ­ ­ ‘f’ for free, or ‘e’ for engaged, and should preserve the FD mID ­>status. CREATE TABLE M (mID integer, fID integer, pref integer, status char, PRIMARY KEY (mID, fID));  ­ ­ similarly for each female, store a pref for each male, but here preserve fID  ­> status. CREATE TABLE F (fID integer, mID integer, pref integer, status char, PRIMARY KEY (fID, mID));  ­ ­ keep track of prior proposals (for tests in lines 3 ­4) CREATE TABLE proposals (mID integer, fID integer);  ­ ­ keep track of engagements CREATE TABLE engaged (mID integer, fID integer);  ­ ­ each round we will have a set of new proposals to consider CREATE TABLE newproposals (mID integer, fID integer);  ­ ­ some rounds we may find engaged women who would prefer to upgrade to a new proposal (lines 8 ­9) CREATE TABLE upgrades (newMan integer, fID integer, old...
View Full Document

{[ snackBarMessage ]}