This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Stable Matching Data Structures and Algorithms
Andrei Bulatov Data Structures and Algorithms — Stable Matching Stable Matching Problem: Formalism Apair (m,w’) is an instability with respect toa matching S if (m,w’)
does not belong to S, but both m and w’ prefers each other to
their current matches. Amatching is stable if it is (i) perfect, and (ii) has no instabilities Problem
There are n men and n women with their preference lists.
(a) Does there exist a stable matching?
(b) If a stable matching exists, how can we find it? We have GaleShapley algorithm to solve it 2—2 Data Structures and Algorithms — Stable Matching Stable Matching Problem: Analysis Theorem
G.S. algorithm returns a stable matching Theorem G.S. algorithm terminates after at most n
loop 2 iterations of the while 2—3 Data Structures and Algorithms — Stable Matching Brute Force For many problems there is a very simple algorithm For example, for the Stable Matching Problem we could try all perfect
matchings Difficulty: there are too many of them, n!
Such an algorithm is called a brute force algorithm:
enumerate all possible configurations and choose the right one An efficient algorithm should outperform the brute force algorithm
 substantially
 provany / analytically 2—4 Data Structures and Algorithms  Stable Matching Polynomial Time Good criterion of scaling: If the instance size is doubled the running
time increases by a constant factor Natural example: polynomials
Let the running time is f(n) 2 3nd + 2n2 + n
When doubling the instance size
f(2n) = 3(2n)d + 2(2n)2 + 2n s 20! (3nd + 2n2 + n) An algorithm has polynomial running time, or is a polynomial time
algorithm if its running time is bounded from above by a polynomial Isitgood? 2—5 Data Structures and Algorithms  Stable Matching Polynomial Time (cntd) Contras:
there are bad polynomial time algorithms
there are good nonpoly time algorithms
it does not capture the ‘practical’ complexity of algorithms Pros:
usually if there is a poly time algorithm, there is a good one
it captures something 2—6 Runnmg
tune 3 3 Data Structures and Algorithms  Stable Matching O
[\D
O 00
O
.h
C)
01
C) .00001
seconds .00002
seconds .00003
seconds .00004
seconds .00005
seconds .00006
seconds .0001
seconds .0004
seconds .0009
seconds .0016
seconds .0025
seconds .0036
seconds .001
seconds .008
seconds .027
seconds .064
seconds .125
seconds .216
seconds 32
seconds 24u3
seconds 1.7
mmums 52
mmums 130 seconds Innuﬂes .001 1.0
seconds seconds 170
mmums 12]
days 35(7
years 366
centunes I .059 58
seconds rnhuﬂes 6&5
years 3855
centudes 2x108
centudes 1.3x10B
centudes 27 Data Structures and Algorithms  Stable Matching Asymptotics We don’t want to compute the exact running time
VVhy?
 Do we care if the running time is 2.53112 +3.42n or
2.55112 + 3.3911?
 We will mostly represent algorithms by pseudocode.
Implementation details can change running time by some constant  We are interested in more conceptual differences between
algorithms, and will be happy with a rough classification Then 2.53n2 +3.42n is more or less similar to n2 2—8 Data Structures and Algorithms  Stable Matching Asymptotic Notation For two functions f,g: N —> R g is in O(f) if there is c such that starting
from some k: g(n)Scf(n) g is in @(f) if there are c,d > 0
such that starting from some k:
d  f(n) S g(n) S c  f(n) Data Structures and Algorithms  Stable Matching Asymptotic Notation g is in o(f) if for any c starting
from some k(c): g(n) < c ~ f(n) g is in £2(f) if there is c such
that starting from some k:
g(n)20  f(n) Read about asymptotic notation 2—10 Data Structures and Algorithms — Stable Matching 2—11 Stable Matching Problem: GaleShapley Algorithm Input sets M and w of men and women with preference 1ists Output: a stabie matching initia11y a11 meM and wew are free whi1e there is a free man do
1et w He the highest ranked woman for m to whom he
hasn’t yet proposed if w is free then (m,w) become engaged
eise if w is currentiy engaged to m’
if w prefers m’ to m then m remains free
e1se w prefers m to m’
(m,w) become engaged
m’ becomes free
endif
endif
endwhi1e
Return the set S of engaged pairs Data Structures and Algorithms  Stable Matching 2—12 Implementation: Choosing Data Structures The choice of data structures is determined by what we have to do with
data Ideally, every operation with data should take constant time For Stable matching we need:
 to identify a free man  for a man m to indentify his highest ranked woman he hasn’t
proposed  forawoman w to decide if w is engaged, and if yes who is her
current partner  forawoman w and two men m and m’ to decide, whom w
prefers Data Structures and Algorithms  Stable Matching 2—13 Arrays A list of elements:
 fixed length
 direct (constant time) access to element # i Array operations:
 read element #i: 0(1)
 find a required element: O(n) ifunordered
O(Iog n) if ordered
 insert an element: O(n) Data Structures and Algorithms  Stable Matching 2—14 Lists A list of elements:
 variable length
 no direct access to element #i Linked list — pointer pointer pointer pointer Double linked list Data Structures and Algorithms  Stable Matching 2—15 List Operations  add an element 0(1)  delete element 0(1)  find an element O(n) Data Structures and Algorithms  Stable Matching 2—16 Data Structures for Stable Matching Let M and W contain n elements each
adding/finding/removing a free  preference lists: arrays ma” 0(1) Manpreﬂm’ﬂ’ Womanpreﬂw’l] finding next woman to propose  next woman to propose: array M anpreﬂm’N exﬂmn 0(1)
Next[m]  current partner of a woman: array deciding on woman’s current
CurrentM partner 0(1)  set of free men: linked list
FreeMan deciding whom a woman prefers  ranking of men: array Ranking[Wim] < RarikinQ[W,m’] Ranking[w,m] 0(1) Data Structures and Algorithms  Stable Matching 2—17 Homework Write pseudocode for G.S. algorithm with data structures ...
View
Full Document
 Fall '09
 A.BULATOV
 Data Structures

Click to edit the document details