CS3000:Algorithms&Data PaulHand
Lecture2:• FinishInduction• StableMatching:theGale-ShapleyAlgorithm
Jan9,2019
CourseWebsite
http://www.ccs.neu.edu/home/hand/teaching/cs3000-spring-2018/
• HomeworkwillbesubmittedonGradescope!• MoredetailsonWednesday• EntryCode:MKKEW2• https://www.gradescope.com/courses/36055
HomeworkPolicies
CourseStructureEnd4/17
Start1/7
DivideandConquer
DynamicProgramming
Graphs NetworkFlow
Textbook:AlgorithmDesignbyKleinbergandTardos
Moreresourcesonthecoursewebsite
FinalTBD
MidtermI2/20
MidtermII3/27
ProofsbyInduction
• Claim:Forevery,
• ProofbyInduction:
Exercise
n 2 N,n�1X
i=0
2i = 2n � 1
100000,0
Base cases n L 42 2 1 1
General case n I
Assume 02 I I
o2i f j2 it 27 271 2
2Mt I
StableMatchingProblemandtheGale-ShapleyAlgorithm
Processforsolvingcomputationalproblemswithalgorithms
• Formulateproblemandquestions• Playaround• Devisealgorithm• Determinehowlongittakestorun• Determineifalgorithmiscorrect• Determineappropriatedatastructures
StableMatchingProblem
• Manyjobcandidates(eg.doctors).Manyjobs(eg.residencyprograms).Youaretoassigncandidatestojobs.Howshouldyoudoit?
inputs to alg
Candidates G G Cnjobs I j2 Jn3
pair Ci Jsfirst isthjobperson
somorppl havea job
not EVERYone
itbelongsto
any of the followingprefers
note proofs of jd dont matter
Find a
c painthat both prefersEach other
0 UC 2732 c B
M l B Ca A 13,4Mz HA B 12,93
Gale-ShapleyAlgorithm
• Let M be empty • While (some job j is unmatched):
• If (j has offered a job to everyone): break • Else: let c be the highest-ranked candidate to which j has not yet offered a job
• j makes an offer to c: • If (c is unmatched):
• c accepts, add (c,j) to M • ElseIf (c is matched to j’ & c: j’ > j):
• c rejects, do nothing • ElseIf (c is matched to j’ & c: j > j’):
• c accepts, remove (c,j’) from M and add (c,j) to M
• Output M
Icoording to j
Gale-ShapleyDemo
1st 2nd 3rd 4th 5th
MGH Bob Alice Dorit Ernie Clara
BW Dorit Bob Alice Clara Ernie
BID Bob Ernie Clara Dorit Alice
MTA Alice Dorit Clara Bob Ernie
CH Bob Dorit Alice Ernie Clara
1st 2nd 3rd 4th 5th
Alice CH MGH BW MTA BID
Bob BID BW MTA MGH CH
Clara BW BID MTA CH MGH
Dorit MGH CH MTA BID BW
Ernie MTA BW CH BID MGH
D
XO
Activity:Whatarethefirst4stepsofG-Salgorithm?
• Jobs:1,2,3,4• Candidates:A,B,C,D
Jobs’Preferences Candidates’Preferences
(Assumeitstepsthroughjobsinorder1-4,afterwardsstartingoverwith1ifnecessary)
Observations• Atallsteps,thestateofthealgorithmisamatching
• Jobsmakeoffersindescendingorder
• Candidatesthatgetajobneverbecomeunemployed
• Candidatesacceptoffersinascendingorder
Gale-ShapleyAlgorithm
• QuestionsabouttheGale-ShapleyAlgorithm:• Willthisalgorithmterminate?Afterhowlong?• Doesitoutputaperfectmatching?• Doesitoutputastablematching?• Howdoweimplementthisalgorithmefficiently?
GSAlgorithm:Termination
• Claim:TheGSalgorithmterminatesaftern2iterationsofthemainloop,wherenisnumberofcandidates/jobs.
af most
At most n2 possible offasAt Each iter an offer ismade None repeated
So f n iteratus
GSAlgorithm:PerfectMatching
• Claim:TheGSalgorithmreturnsaperfectmatching(alljobs/candidatesarematched)
GSAlgorithm:StableMatching
• Stability:GSalgorithmoutputsastablematching• Proofbycontradiction:
• Supposethereisaninstability
GSAlgorithm:RunningTime
• RunningTime:• Astraightforwardimplementationrequiresatoperations,space(memory).
⇡ n3
⇡ n2
GSAlgorithm:RunningTime
• Let M be empty • While (some job j is unmatched):
• If (j has offered a job to everyone): break • Else: let c be the highest-ranked candidate to which j has not yet offered a job
• j makes an offer to c: • If (c is unmatched):
• c accepts, add (c,j) to M • ElseIf (c is matched to j’ & c: j’ > j):
• c rejects, do nothing • ElseIf (c is matched to j’ & c: j > j’):
• c accepts, remove (c,j’) from M and add (c,j) to M
• Output M
GSAlgorithm:RunningTime
• RunningTime:• Acarefulimplementationrequiresjusttimeandspace
⇡ n2
⇡ n2
GSAlgorithm:RunningTime
• RunningTime:• Acarefulimplementationrequiresjusttimeandspace
1st 2nd 3rd 4th 5th
Alice CH MGH BW MTA BID
Bob BID BW MTA MGH CH
Clara BW BID MTA CH MGH
Dorit MGH CH MTA BID BW
Ernie MTA BW CH BID MGH
MGH BW BID MTA CH
Alice 2nd 3rd 5th 4th 1st
Bob 4th 2nd 1st 3rd 5th
Clara 5th 1st 2nd 3rd 4th
Dorit 1st 5th 4th 3rd 2nd
Ernie 5th 2nd 4th 1st 3rd
GSAlgorithm:RunningTime
• RunningTime:• Acarefulimplementationrequiresjusttimeandspace
⇡ n2
⇡ n2
NotesforinstructorStudentsmayignorebecausetheyarerepeatedelsewhere
Top Related