Docsity

Stable Matching, Asymptotic Notation - Algorithm Design and Analysis | CSE 565, Study notes of Computer Science

Partial preview of the text

Download Stable Matching, Asymptotic Notation - Algorithm Design and Analysis | CSE 565 and more Study notes Computer Science in PDF only on Docsity!

8/27/

Adam Smith

Algorithm Design and Analysis

LECTURE 2

• Analysis of Stable Matching

• Asymptotic Notation

8/27/

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.

Zeus Amy Bertha Clare Yancey Bertha Amy Clare Xavier Amy Bertha Clare 1 st^2 nd^3 rd Men’s Preference Profile favorite least favorite Clare Xavier Yancey Zeus Bertha Xavier Yancey Zeus Amy Yancey Xavier Zeus 1 st^2 nd^3 rd Women’s Preference Profile favorite least favorite

8/27/

Review Questions

• In terms of n, what is the length of the input to

the Stable Matching problem, i.e., the number of

entries in the tables?

(Answer: 2 n

list entries, or 2 n

log n bits)

8/27/

Review Question

• Brute force algorithm: an algorithm that

checks every possible solution.

• In terms of n, what is the running time for the

brute force algorithm for Stable Matching

Problem? (Assume your algorithm goes over all

possible perfect matchings.)

(Answer: n! × (time to check if a matching is stable) = Θ( n! n

8/27/ Proof of Correctness: Termination

  • Claim. Algorithm terminates after at most n 2 iterations of while loop.
  • Pf. Each time through the loop a man proposes to a new woman. There are only n 2 possible proposals. ▪ Wyatt Victor 1 st A B 2 nd C D 3 rd C B Zeus A Yancey Xavier C D A B B A D C 4 th E E 5 th A D E E D C B E Bertha Amy 1 st W X 2 nd Y Z 3 rd Y X Erika V Diane Clare Y Z V W W V Z X 4 th V W 5 th V Z X Y Y X W Z An instance where n(n-1) + 1 proposals required

8/27/ 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/27/ 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. ▪ men propose in decreasing order of preference women only trade up

8/27/

Efficient Implementation

• We describe O(n

) time implementation.

• 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[m], and husband[w].

  • set entry to 0 if unmatched
  • if m matched to w then wife[m]=w and husband[w]=m

• Men proposing data structures:

– an array men-pref[m,i]= i

th

women on m

th

list

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

8/27/

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 stable matching always exists)

• Time and space complexity:

O(n

2

) , linear in the input size.

Brief Syllabus

• Reminders

– Worst-case analysis

– Asymptotic notation

– Basic Data Structures

• Design Paradigms

– Greedy algorithms, Divide and conquer, Dynamic

programming, Network flow and linear programming

• Analyzing algorithms in other models

– Parallel algorithms, Memory hierarchies (?)

• P, NP and NP-completeness

8/27/