0% found this document useful (0 votes)
47 views

Lecture 1 Introduction Marriage

This document provides an introduction to algorithms and the stable marriage problem. It defines what an algorithm is and criteria for evaluating algorithms like correctness, definiteness, and efficiency. It then introduces the stable marriage problem, gives an example, and presents the Gale-Shapley algorithm to solve it. The algorithm is proven to always terminate with a stable matching and runs in O(n^2) time. While the algorithm produces the best outcome for men, it results in the worst matches for women. Extensions to the basic problem are also discussed.

Uploaded by

Mulugeta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Lecture 1 Introduction Marriage

This document provides an introduction to algorithms and the stable marriage problem. It defines what an algorithm is and criteria for evaluating algorithms like correctness, definiteness, and efficiency. It then introduces the stable marriage problem, gives an example, and presents the Gale-Shapley algorithm to solve it. The algorithm is proven to always terminate with a stable matching and runs in O(n^2) time. While the algorithm produces the best outcome for men, it results in the worst matches for women. Extensions to the basic problem are also discussed.

Uploaded by

Mulugeta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

SWEG 5012

ADVANCED ALGORITHMS
AND PROBLEM SOLVING

LECTURE 1 INTRODUCTION
BEAKAL GIZACHEW

Based on slides of Serdar Taşıran and PiyushKumar and


adapted by Alptekin Küpçü
ALGORITHMS
• Algorithm: Named after the 9th century mathematician el-Harezmi (al-
Khwarizmi)
• An algorithm: A tool for solving a well-specified computational problem.
• Problem statement:
• Inputs, outputs
• The desired input/output relationship
• Algorithm describes a specific computational procedure for producing
the required output
• Definiteness : Each step should be defined precisely
• Correctness : Should produce correct output for each input
• Finiteness : Should produce desired output after a finite number of steps
• Effectiveness: Each step should be performed exactly in a finite amount of time
• Generality: Should be applicable to any case (not just particular inputs)

We are interested in designing algorithms and


analyzing their performance in this course.
2
EFFICIENCY
• Hardware and memory are fast and cheap. Computing
getting cheaper and cheaper. Intelligent manpower is
expensive
• Assumptions:
• Single processor, random-access machine
• Algorithm steps are executed sequentially
• Each steps take 1 unit of time
• Makes our results machine-independent
• Otherwise impossible to compare!
• I also assume you already know:
• Big-Oh notation and asymptotic complexity analysis
• Basic data structures and algorithms
• How to analyze recurrence relations

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.)

O(n2) 2 n2 109 2000 sec.


algorithm instructions inst/second
O(n log n) 50 n log n 109 1 sec.
algorithm instructions inst/second

• Interactive graphics: Algorithms must terminate in 1/30 of a sec.

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.

• Different metrics possible:


• Maximize the number of people who get their first match?
• Maximize the average satisfaction?
• Maximize the minimum satisfaction?
• Can anything go wrong?

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

unstable pair: man m and women w are unstable if


• m prefers w to his assigned match
• w prefers m to his assigned match
What is wrong?
Unstable pairs: (X,C) and (B,Y)
X and B prefer each other to their current pairs.
8
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

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.

• Solution Idea: Allow the pairs to keep breaking up and


reforming until they become stable

• Can we argue that the couples will not continue breaking up


and reforming forever?

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)

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)

assign m and w as engaged


else if (w prefers m to her fiancé m')
assign m and w as engaged, and m' to be free
else
w rejects m

13
ANALYSIS
• Proof of Correctness
• Does the algorithm terminate?
• Matches everyone (Perfect matching) and
• Outputs a stable matching
• Running time and Space requirement Complexity?

Improvement Lemma: If a woman has a committed suitor, then she


will always have someone at least as good, from that point in time
onwards (and on the termination of the algorithm).
Corollary: Each woman will marry her absolute favorite of the men
who proposed to her.
Demotion Lemma: The sequence of women to whom a man m
proposes gets worse and worse (in terms of his preference list)
14
LEMMA 1
• No Man can be rejected by all the Women.
• Proof: by contradiction

Suppose Abebe is rejected by all the


women. At that point:
• Each women must have a suitor other than
Abebe (By Improvement Lemma, once a
woman has a suitor she will always have at
least one)
• The n women have n suitors, Abebe not among
them.
• Thus, there must be at least n+1 men !
15
COROLLARY OF LEMMA 1
• If a man m is free at some point in the execution of the algorithm,
then there is a woman to whom he has not yet proposed.

• The algorithm returns a perfect matching at the end. (Since there is


no free man or woman left.)

A perfect matching is a matching which covers


all vertices of the graph.

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.

• A pairing is (woman-) man-pessimal if every (woman) man gets


(her) his worst valid partner. This is the worst of all possible
stable worlds for every (woman) man simultaneously.

• The Gale-Shapley algorithm always produces a man-optimal and


woman-pessimal pairing.

20
CONCLUSION: MARRY WELL!

21
ADVICE TO FEMALES

Learn to make the first move.

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)

assign m and w as engaged


else if (w prefers m to her fiancé m')
assign m and w as engaged, and m' to be free
else
w rejects m
Complexity and Space requirements?

24

You might also like