Lecture 1 Introduction Marriage
Lecture 1 Introduction Marriage
ADVANCED ALGORITHMS
AND PROBLEM SOLVING
LECTURE 1 INTRODUCTION
BEAKAL GIZACHEW
3
ANALYZING ALGORITHMS
Is the algorithm correct?
• Does it terminate on all inputs?
• Does it produce the required output?
What amount of resources does the algorithm use up?
• Memory
• Communication bandwidth
• Number of logic gates (if implemented in hardware), speed (depth) of
logic circuit
• Running time
4
EFFICIENT ALGORITHMS
A bad approach uses up computing power faster than you might
think. Examples:
• Sorting a million numbers (emails, files, etc.)
5
OUR FIRST ALGORITHM:
STABLE MARRIAGE
6
THE PROBLEM
• Input: There are n men and n women
• Each man has a preference list, so does each woman.
• These lists have no ties.
• Devise a system by which each of the n men and n women can end
up getting married.
7
SAMPLE PREFERENCE LISTS
st nd rd st nd rd
Man 1 2 3 Woman 1 2 3
X A B C A Y X Z
Y B A C B X Y Z
Z A B C C X Y Z
st nd rd st nd rd
Man 1 2 3 Woman 1 2 3
X A B C A Y X Z
Y B A C B X Y Z
Z A B C C X Y Z
Anything wrong?
No pair creating instability.
9
ANOTHER STABLE MATCHING
st nd rd st nd rd
Man 1 2 3 Woman 1 2 3
X A B C A Y X Z
Y B A C B X Y Z
Z A B C C X Y Z
10
STABILITY IS PRIMARY
• Any reasonable list of criteria must contain the stability
criterion.
• A pairing is doomed if it contains a rogue couple.
11
Review Question
• Brute force algorithm – an algorithm that checks every
possible solution
• In terms of n, what is the running time for brute force for
Stable Matching?
• What is the space complexity ??
st nd rd st nd rd
Man 1 2 3 Woman 1 2 3
X A B C A Y X Z
Y B A C B X Y Z
Z A B C C X Y Z
12
MEN PROPOSE (WOMEN DISPOSE)
13
ANALYSIS
• Proof of Correctness
• Does the algorithm terminate?
• Matches everyone (Perfect matching) and
• Outputs a stable matching
• Running time and Space requirement Complexity?
16
LEMMA 2
• Gale-Shapley algorithm returns a stable matching.
• Proof: by contradiction
Abebe Chala
Almaz
Martha
• Assume there is an unstable pair: Abeba and Martha
• This means Abebe likes Martha more than his partner, Almaz.
• Thus, Abebe proposed to Martha before he proposed to Almaz.
• Martha must have rejected Abebe for someone she preferred.
• By the Improvement lemma, she must like her partner Chala
more than Abebe.
• Pairs are not unstable. Contradiction!
17
QUESTION!
Who is better
off,
the men or the
women?
18
BEST (VALID) PARTNER FOR
Abebe?
• Best woman for “Abebe”? The woman at the top of Abebe’s list?
• A woman w is a valid partner of a man m if there is a stable
matching that contains (m,w).
• A man’s best valid partner is the highest ranked woman for
whom there is some stable pairing in which they are matched
• She is the best woman he can conceivably be matched in a stable
world.
• A Man’s worst valid partner is the lowest ranked woman in his
preference list that is a valid partner.
19
DATING DILEMMA
• A pairing is (woman-) man-optimal if every (woman) man gets
(her) his best valid partner. This is the best of all possible stable
worlds for every (woman) man simultaneously.
20
CONCLUSION: MARRY WELL!
21
ADVICE TO FEMALES
22
EXTENSIONS
Extensions
• Sets of unequal size
• Unacceptable partners
• Indifference
• Many-to-many assignments
Deceit, Coalitions and Strategy
• In general, lying cannot be totally discouraged in Stable Marriage
Problem. (sounds familiar??)
Other similar problems
• Internship assignments: Given a set of companies and students, pair
them.
• Given airlines and pilots, pair them.
• Computer Vision: Given two images, pair the points belonging to the
same point in 3D to extract depth from the two images.
• Dorm room assignments.
• Hospital residency assignments.
23
REVIEW PROBLEM
Gale-Shapley Algorithm (men propose)
Initialize each person to be free.
while (some man m is free and hasn't proposed to every woman)
w = first woman on m's list to whom m has not yet proposed
if (w is free)
24