algorithm design and analysis cse 565...cse 565 course information 1. staff 2. course websites 3....

66
Sofya Raskhodnikova Algorithm Design and Analysis LECTURE 1 Analysis of Algorithms Course information Why study algorithms? Stable matching problem 8/22/2016 S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.1

Upload: others

Post on 22-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Sofya Raskhodnikova

Algorithm Design and Analysis

LECTURE 1Analysis of Algorithms

• Course information

• Why study algorithms?

• Stable matching problem

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.1

Page 2: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

CSE 565 Course information

1. Staff

2. Course websites

3. Textbook

4. Syllabus

5. Prerequisites

6. Name template

7. Background survey

8. Reading quizzes

9. Exams

10. Homework

11. Collaboration policy

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.2

Page 3: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Algorithm Design and Analysis

Theoretical study of how to solve computational

problems

• sorting a list of numbers

• finding a shortest route on a map

• scheduling when to work on homework

• answering web search queries

(Generally: precisely defined set of inputs and,

for each input, acceptable outputs)

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.3

Page 4: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

Etymology of “Algorithm”

Abu Abdullah Muhammad ibn Musa al-Khwarizmi (c. 780 -- 850 AD)

• Persian astronomer and mathematician

• lived in Baghdad, father of algebra

• “On calculating with hindu numerals”a treatise in Arabic, 825

• “Algoritmi de numero Indorum”translation into Latin, 12th century

• Author’s name, mistaken for a plural noun, came to mean “calculation methods”

Page 5: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Algorithms

• Definition: Finite set of unambiguous

instructions for solving a problem.

– An algorithm is correct if on all legitimate inputs, it

outputs the right answer in a finite amount of time

• Can be expressed as

– pseudocode

– text in a natural language (e.g. English)

– computer code

– pictures

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.5

Page 6: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Data Structures

• Data structures are ways to store information

for which there are algorithms for performing

particular operations (retrieving/manipulating

information), e.g.

– linked lists

– hash tables

– heaps

– red-black trees

– skip lists

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.6

Page 7: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Why study algorithms?

• Language for thinking about program behavior

– analyzing correctness and resource usage

– most computing research is algorithmic

• Standard set of algorithms and design techniques

• Feasibility (what can and cannot be done)

– halting problem, NP-completeness

• Successful companies (Google, Akamai, …)

• Computation is fundamental to understanding the world

– cells, brains, social networks, physical systems, …

• Exercise for your brain

• Fun!8/22/2016

S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.7

Page 8: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Performance isn’t everything

• Typical goal: Find most space- and time-efficient

algorithm for given problem.

• What else is important?

– modularity

– maintainability

– functionality

– robustness

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

– user-friendliness

– programmer time

– simplicity

– extensibility

– reliability

L1.8

Page 9: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Course Objectives

Material

• Classical algorithms

• Analysis of algorithms

• Design techniques

Skills

• Algorithmic Thinking

• Problem-solving & mathematical skills

• Technical writing

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.9

Page 10: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Prerequisite: CSE 465 or equivalent

Some of things you should have covered:

• Reading/writing Proofs (including induction, contradiction, …)

• Asymptotic notation (e.g. ``big-O'')

• Elementary data structures: lists, stacks, queues, sorted arrays

• Graphs and trees

– Depth- and breadth-first search, shortest paths, …

• Basic design paradigms:

– divide and conquer

– greedy algorithms

– dynamic programming

• Basic mathematical tools: arithmetic and geometric series,

counting permutations, vectors and matrices, etc

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.10

Page 11: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Co-requisite: 464/468 or equivalent

• Finite automata, Turing machines,

undecidability, complexity measures, “P”

nondeterminism and “NP”

• What we will need:

– abstractions of computation

– P / NP / NP-completeness

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.11

Page 12: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

A first problem:

Stable Matching

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.12

Page 13: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Matching Residents to Hospitals

• Goal: Given a set of preferences among hospitals and

medical school students, design a self-reinforcing

admissions process.

• Unstable pair: applicant 𝑥 and hospital 𝑦 are unstable if

– 𝑥 prefers 𝑦 to its assigned hospital, and

– 𝑦 prefers 𝑥 to one of its admitted students

• Stable assignment: no unstable pairs.

– Individual self-interest will prevent any applicant/hospital deal

from being made.

• 2012 Nobel prize in economics for work on

matching algorithms (“mechanisms”)8/22/2016

S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.13

Page 14: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Stable Matching Problem

• Goal: Given n men and n women, find a "suitable"

matching.

–Participants rate members of opposite sex.

–Each man lists women in order of preference from best to worst.

–Each woman lists men in order of preference from best to worst.

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

Zeus Amy ClareBertha

Yancey Bertha ClareAmy

Xavier Amy ClareBertha

1st 2nd 3rd

Men’s Preference Profile

favorite least favorite

Clare Xavier ZeusYancey

Bertha Xavier ZeusYancey

Amy Yancey ZeusXavier

1st 2nd 3rd

Women’s Preference Profile

favorite least favorite

L1.14

Page 15: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Stable Matching Problem

• Unstable pair: man m and woman w are unstable if

– m prefers w to his assigned match, and

– w prefers m to her assigned match

• Unstable pairs have an incentive to elope

• Stable matching: no unstable pairs.

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

Zeus Amy ClareBertha

Yancey Bertha ClareAmy

Xavier Amy ClareBertha

1st 2nd 3rd

Men’s Preference Profile

favorite least favorite

Clare Xavier ZeusYancey

Bertha Xavier ZeusYancey

Amy Yancey ZeusXavier

1st 2nd 3rd

Women’s Preference Profile

favorite least favorite

L1.15

Page 16: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Stable Matching Problem

• Input: preference lists of n men and n women

• Goal: find a stable matching if one exists

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

Zeus Amy ClareBertha

Yancey Bertha ClareAmy

Xavier Amy ClareBertha

1st 2nd 3rd

Men’s Preference Profile

favorite least favorite

Clare Xavier ZeusYancey

Bertha Xavier ZeusYancey

Amy Yancey ZeusXavier

1st 2nd 3rd

Women’s Preference Profile

favorite least favorite

L1.16

Page 17: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Stable Matching Problem

• Q. Is assignment X-C, Y-B, Z-A stable?

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

favorite least favorite favorite least favorite

Zeus Amy ClareBertha

Yancey Bertha ClareAmy

Xavier Amy ClareBertha

1st 2nd 3rd

Men’s Preference Profile

Clare Xavier ZeusYancey

Bertha Xavier ZeusYancey

Amy Yancey ZeusXavier

1st 2nd 3rd

Women’s Preference Profile

L1.17

Page 18: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Stable Matching Problem

• Q. Is assignment X-C, Y-B, Z-A stable?

• A. No. Bertha and Xavier will hook up.

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

favorite least favorite favorite least favorite

Zeus Amy ClareBertha

Yancey Bertha ClareAmy

Xavier Amy ClareBertha

Clare Xavier ZeusYancey

Bertha Xavier ZeusYancey

Amy Yancey ZeusXavier

1st 2nd 3rd 1st 2nd 3rd

Men’s Preference Profile Women’s Preference Profile

L1.18

Page 19: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Stable Matching Problem

• Q. Is assignment X-A, Y-B, Z-C stable?

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

favorite least favorite favorite least favorite

Zeus Amy ClareBertha

Yancey Bertha ClareAmy

Xavier Amy ClareBertha

Clare Xavier ZeusYancey

Bertha Xavier ZeusYancey

Amy Yancey ZeusXavier

1st 2nd 3rd 1st 2nd 3rd

Men’s Preference Profile Women’s Preference Profile

L1.19

Page 20: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Stable Matching Problem

• Q. Is assignment X-A, Y-B, Z-C stable?

• A. Yes. X and Y got their first choice; Z is the last choice for every woman. No man can participate in an unstable pair.

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

favorite least favorite favorite least favorite

Zeus Amy ClareBertha

Yancey Bertha ClareAmy

Xavier Amy ClareBertha

Clare Xavier ZeusYancey

Bertha Xavier ZeusYancey

Amy Yancey ZeusXavier

1st 2nd 3rd 1st 2nd 3rd

Men’s Preference Profile Women’s Preference Profile

L1.20

Page 21: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Existence of Stable Matching

• Q. Do stable matchings always exist?

• A. Not obvious a priori.

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.21

Page 22: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Stable Roommate Problem

• Stable roommate problem

– 2n people; each person ranks others from 1 to 2n-1.

– Assign roommate pairs so that no unstable pairs.

• Observation. Stable matchings do not always

exist for stable roommate problem.

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

B

Bob

Chris

Adam C

A

B

D

D

Doofus A B C

D

C

A

1st 2nd 3rd

A-B, C-D B-C unstableA-C, B-D A-B unstableA-D, B-C A-C unstable

L1.22

Page 23: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

An Algorithm for Stable Matching

• Propose-and-reject algorithm. [Gale-Shapley 1962]

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

Initialize each person to be free.

while (some man is free and hasn't proposed to every woman) {

Choose such a man m

w = 1st woman on m's list to whom m has not yet proposed

if (w is free)

assign m and w to be engaged

else if (w prefers m to her fiancé m')

assign m and w to be engaged, and m' to be free

else

w rejects m

}

L1.23

Page 24: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Page 25: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Victor proposes to Bertha.

Victor

Bertha

Page 26: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Victor proposes to Bertha.

- Bertha accepts sincepreviously unmatched.

Victor

Bertha

Page 27: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Wyatt proposes to Diane.

Victor

Bertha

Diane

Wyatt

Page 28: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Wyatt proposes to Diane.

- Diane accepts sincepreviously unmatched.

Victor

Bertha

Diane

Wyatt

Page 29: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Xavier proposes to Bertha.

Victor

Bertha

Diane

Wyatt

Bertha

Xavier

Page 30: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Xavier proposes to Bertha.

- Bertha dumps Victorand accepts Xavier.

Victor

Bertha

Diane

Wyatt

Bertha

Xavier

Page 31: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Diane

Wyatt

Bertha

Xavier

Victor proposes to Amy.

Amy

Victor

Victor

Bertha

Page 32: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Victor proposes to Amy.

- Amy accepts sincepreviously unmatched.

Victor

Bertha

Page 33: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Yancey proposes to Amy.

Amy

Yancey

Victor

Bertha

Page 34: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Amy

Yancey

Yancey proposes to Amy.

- Amy rejects since sheprefers Victor.

Victor

Bertha

Page 35: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Yancey proposes to Diane.

Diane

Yancey

Amy

Yancey

Victor

Bertha

Page 36: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Diane

Yancey

Yancey proposes to Diane.

- Diane dumps Wyattand accepts Yancey.

Amy

Yancey

Victor

Bertha

Page 37: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Diane

Yancey

Wyatt proposes to Bertha.

Bertha

Wyatt

Diane

Wyatt

Amy

Yancey

Victor

Bertha

Page 38: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Victor

Bertha

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Wyatt proposes to Bertha.

- Bertha rejects since sheprefers Xavier.

Page 39: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Diane

Yancey

Wyatt proposes to Amy.

Amy

Wyatt

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Bertha

Wyatt

Page 40: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Diane

Yancey

Wyatt proposes to Amy.

- Amy rejects since sheprefers Victor.

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Bertha

Wyatt

Amy

Wyatt

Page 41: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Victor

Bertha

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Wyatt proposes to Clare.

Clare

Wyatt

Page 42: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Diane

Yancey

Clare

Wyatt

Wyatt proposes to Clare.

- Clare accepts sincepreviously unmatched.

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Bertha

Wyatt

Amy

Wyatt

Page 43: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Diane

Yancey

Clare

Wyatt

Zeus proposes to Bertha.Bertha

ZeusVictor

Bertha

Diane

Wyatt

Amy

Yancey

Bertha

Wyatt

Amy

Wyatt

Page 44: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Diane

Yancey

Clare

Wyatt

Zeus proposes to Bertha.

- Bertha rejects sinceshe prefers Xavier.

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Bertha

Wyatt

Amy

Wyatt

Bertha

Page 45: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Diane

Yancey

Clare

Wyatt

Zeus proposes to Diane.Diane

Zeus

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Bertha

Wyatt

Amy

Wyatt

Bertha

Page 46: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Victor

Bertha

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Clare

Wyatt

Bertha

Zeus

Diane

Zeus

Zeus proposes to Diane.

- Diane rejects Yanceyand accepts Zeus.

Page 47: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Clare

Wyatt

Diane

Zeus

Yancey proposes to Clare.

Clare

Yancey

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Bertha

Zeus

Page 48: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Victor

Bertha

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Clare

Wyatt

Bertha

Zeus

Diane

Zeus

Clare

Yancey

Yancey proposes to Clare.

- Clare rejects sinceshe prefers Wyatt.

Page 49: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Clare

Wyatt

Diane

Zeus

Yancey proposes to Bertha.

Bertha

Yancey Victor

Bertha

Diane

Wyatt

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Bertha

Zeus

Clare

Yancey

Page 50: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Victor

Bertha

Diane

Wyatt

Bertha

Xavier

Amy

Victor

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Clare

Wyatt

Bertha

Zeus

Diane

Zeus

Clare

Yancey

Bertha

Yancey

Yancey proposes to Bertha.

- Bertha rejects sinceshe prefers Xavier.

Page 51: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Clare

Wyatt

Diane

Zeus

Yancey proposes to Erika.

Erika

Yancey

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Bertha

Zeus

Clare

Yancey

Bertha

Yancey

Page 52: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Clare

Wyatt

Diane

Zeus

Erika

Yancey

Yancey proposes to Erika.

- Erika accepts sincepreviously unmatched.

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Bertha

Zeus

Clare

Yancey

Bertha

Yancey

Page 53: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Clare

Wyatt

Diane

Zeus

Erika

Yancey

STOP

- Everyone matched.- Stable matching!

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Bertha

Zeus

Clare

Yancey

Bertha

Yancey

Page 54: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Propose-and-Reject Algorithm

• Propose-and-reject algorithm. [Gale-Shapley 1962]

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

Initialize each person to be free.

while (some man is free and hasn't proposed to every woman) {

Choose such a man m

w = 1st woman on m's list to whom m has not yet proposed

if (w is free)

assign m and w to be engaged

else if (w prefers m to her fiancé m')

assign m and w to be engaged, and m' to be free

else

w rejects m

}

L1.54

Page 55: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Proof of correctness

Three claims: The algorithm always

1. terminates,

2. matches everyone (matching is “perfect”), and

3. outputs a stable matching

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.55

Page 56: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Bertha

Xavier

Amy

Victor

Clare

Wyatt

Diane

Zeus

Erika

Yancey

STOP

- Everyone matched.- Stable matching!

Victor

Bertha

Diane

Wyatt

Amy

Yancey

Diane

Yancey

Bertha

Wyatt

Amy

Wyatt

Bertha

Zeus

Clare

Yancey

Bertha

Yancey

L1.56

Page 57: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Proof of Correctness: Termination

• Claim. Algorithm terminates after at most n2

iterations of while loop.

• Proof. Each time through the loop a man

proposes to a new woman.

There are only n2 possible proposals. ▪

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

Wyatt

Victor

1st

A

B

2nd

C

D

3rd

C

B

AZeus

Yancey

Xavier C

D

A

B

B

A

D

C

4th

E

E

5th

A

D

E

E

D

C

B

E

Bertha

Amy

1st

W

X

2nd

Y

Z

3rd

Y

X

VErika

Diane

Clare Y

Z

V

W

W

V

Z

X

4th

V

W

5th

V

Z

X

Y

Y

X

W

Z

An instance where n(n-1) + 1 proposals required

L1.57

Page 58: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Propose-and-Reject Algorithm

• Observation 1. Men propose to women in

decreasing order of preference.

• Observation 2. Once a woman is matched, she

never becomes unmatched; she only "trades up."

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

Zeus Bertha AmyDiane Erika Clare

Yancey Amy ClareDiane Bertha Erika

Xavier Bertha ClareErika Diane Amy

Wyatt Diane AmyBertha Clare Erika

Victor Bertha DianeAmy Erika Clare

0th 1st 2nd 3rd 4th

Men’s Preference Profile

Bertha

Amy

Clare

Erika

Bertha

Diane

Amy Diane

Bertha Amy

Bertha

Clare Bertha

Erika Yancey ZeusWyatt Xavier Victor

Diane Victor YanceyZeus Xavier Wyatt

Clare Wyatt YanceyXavier Zeus Victor

Bertha Xavier YanceyWyatt Victor Zeus

Amy Zeus WyattVictor Yancey Xavier

0th 1st 2nd 3rd 4th

Women’s Preference Profile

Xavier

Victor

Wyatt

Yancey

Victor

Wyatt

Yancey

Yancey

Wyatt

Wyatt

Zeus

Yancey

Yancey

L1.58

Page 59: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Proof of Correctness: Perfection

• Claim. All men and women get matched.

• Proof: (by contradiction)

– Suppose, for sake of contradiction, some guy, say

Zeus, is not matched upon termination of algorithm.

– Then some woman, say Amy, is not matched upon

termination.

– By Observation 2, Amy was never proposed to.

– But Zeus proposes to everyone, since he ends up

unmatched. ▪

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.59

Page 60: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Proof of Correctness: Stability

•Claim. No unstable pairs.

•Proof: (by contradiction)

– Suppose A-Z is an unstable pair: they prefer each other to their

partners in Gale-Shapley matching S*.

– Case 1: Z never proposed to A.

Z prefers his GS partner to A.

A-Z is stable.

– Case 2: Z proposed to A.

A rejected Z (right away or later)

A prefers her GS partner to Z.

A-Z is stable.

– In either case A-Z is stable, a contradiction. ▪

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

men propose in decreasingorder of preference

women only trade up

L1.60

Page 61: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Stable Roommate Problem

• Stable roommate problem

– 2n people; each person ranks others from 1 to 2n-1.

– Assign roommate pairs so that no unstable pairs.

• Exercise. Where does the correctness proof break

down for the roommates version?

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

B

Bob

Chris

Adam C

A

B

D

D

Doofus A B C

D

C

A

1st 2nd 3rd

A-B, C-D B-C unstableA-C, B-D A-B unstableA-D, B-C A-C unstable

L1.61

Page 62: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Two more exercises

• Does the order in which unmatched men are

selected change the final matching?

• If women propose (instead of men), what

changes? Is it better to propose or to receive

proposals?

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

Page 63: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Efficient Implementation

• We describe O(n2) time implementation.

(in Python: http://euler.slu.edu/~goldwasser/courses/slu/csci314/2006_Spring/lectures/marriageAlgorithm/)

• Assume men have IDs 1,…, n, and so do women.

• Engagements data structures:

– a list of free men, e.g., a queue.

– two arrays wife[𝑚], and husband[𝑤].

• set entry to 0 if unmatched

• if 𝑚 is matched to 𝑤 then wife[𝑚]=𝑤 and husband[𝑤]=𝑚

• Men proposing data structures:

– an array men-pref[𝑚,𝑖]= 𝑖th women on 𝑚’s list

– an array count[𝑚] = how many proposals 𝑚 made.

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.63

Page 64: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Efficient Implementation

• Women rejecting/accepting data structures

– Does woman 𝑤 prefer man 𝑚 to man 𝑚′?

– For each woman, create inverse of preference list of men.

– Constant time queries after 𝑶(𝒏) preprocessing per woman.

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne

for i = 1 to n

inverse[pref[i]] = i

Pref

1st

8

2nd

7

3rd

3

4th

4

5th

1 5 26

6th 7th 8thAmy

Inverse 4th 2nd8th 6th5th 7th 1st3rd

1 2 3 4 5 6 7 8Amy

Amy prefers man 3 to 6since inverse[3] < inverse[6]

2 7

L1.64

Page 65: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Summary

• Stable matching problem. Given n men and n

women, and their preferences, find a stable

matching if one exists.

• Gale-Shapley algorithm. Guarantees to find a

stable matching for every problem instance.– (Also proves that a stable matching always exists)

• Time and space complexity:

O(n2), linear in the input size.

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.65

Page 66: Algorithm Design and Analysis CSE 565...CSE 565 Course information 1. Staff 2. Course websites 3. Textbook 4. Syllabus 5. Prerequisites 6. Name template 7. Background survey 8. Reading

Assignments

• Reading for Wednesday:

Chapters 2.1-2.4 of KT book

(Asymptotic Analysis)

• To be completed on Canvas by Tuesday night:

– Reading Quiz

– Background survey

8/22/2016S. Raskhodnikova; based on slides by E. Demaine, C. Leiserson, A. Smith, K. Wayne L1.66