Objec&ves Proving correctness of Stable Matching algorithm - - PDF document

objec ves
SMART_READER_LITE
LIVE PREVIEW

Objec&ves Proving correctness of Stable Matching algorithm - - PDF document

1/12/18 Objec&ves Proving correctness of Stable Matching algorithm Analyzing algorithms Asympto&c running &mes If youre interested, join the W&L Computer Science Facebook Group! Jan 12, 2018 Sprenkle - CSCI211 1


slide-1
SLIDE 1

1/12/18 1

Objec&ves

  • Proving correctness of Stable Matching algorithm
  • Analyzing algorithms
  • Asympto&c running &mes

Jan 12, 2018 Sprenkle - CSCI211 1

If you’re interested, join the W&L Computer Science Facebook Group!

Review

  • What is the stable matching problem?

Ø What is given? Ø What is our goal?

  • Provide a sketch of the algorithm
  • What were our observa&ons? What have we

shown so far?

Jan 12, 2018 Sprenkle - CSCI211 2

slide-2
SLIDE 2

1/12/18 2

Propose-And-Reject Algorithm

Jan 12, 2018 Sprenkle - CSCI211 3

Initialize each person to be free Initialize each person to be free while while (some man is free and hasn't proposed to every woman) (some man is free and hasn't proposed to every woman) Choose such a man Choose such a man m w = 1 = 1st

st woman on m's list to whom

woman on m's list to whom m has not yet proposed has not yet proposed if if w is free w is free assign assign m and and w to be engaged to be engaged else else if if w prefers m to her fiancé m' w prefers m to her fiancé m' assign assign m and and w to be engaged and to be engaged and m' to be free ' to be free else else w rejects rejects m

[Gale-Shapley 1962]

Review: Observa&ons about the Algorithm

  • What can we say about any woman’s partner

during the execu&on of the algorithm?

Ø Observa&on 1. He gets “beTer” à she prefers him

  • ver her last partner
  • How does a woman’s state change over the

execu&on of the algorithm?

Ø Observa&on 2. Once a woman is matched, she never becomes unmatched; she only "trades up”

  • What can we say about a man’s partner?

Ø Observa&on 3. She gets “worse”

Jan 12, 2018 Sprenkle - CSCI211 4

slide-3
SLIDE 3

1/12/18 3

Review: Proof of Correctness: Termina&on

  • Claim. Algorithm terminates aZer at most n2

itera&ons of while loop

Ø (not yet commen&ng on the &me required for the body of the while loop)

  • Pf. Each &me through the while loop, a man

proposes to a new woman. There are only n2 possible proposals.

5 Jan 12, 2018 Sprenkle - CSCI211

Number of proposals is a good measure for termination à strictly increases; limited

Review: Proof of Correctness: Perfec&on

  • Claim. All men and women get matched.
  • Pf. (by contradic&on)

Ø Suppose that m is not matched upon termina&on of algorithm Ø Then some woman, say w, is not matched upon termina&on. Ø By Observa&on 2, w was never proposed to. Ø But, last man proposed to everyone, since he ends up unmatched

  • (by the while loop’s condi&on)

Ø Contradic&on ▪

6 Jan 12, 2018 Sprenkle - CSCI211

slide-4
SLIDE 4

1/12/18 4

Proof of Correctness: Stability

  • Claim. No unstable pairs.

7

Bertha-Zeus Amy-Yancey S* . . .

Jan 12, 2018 Sprenkle - CSCI211

What does it mean for a given matching S* to be unstable? How do you think we should approach this proof?

Proof of Correctness: Stability

  • Claim. No unstable pairs.
  • Pf. (by contradic&on)

Ø Suppose m-w is an unstable pair: m, w prefers each other to partner in Gale-Shapley matching S*.

8

Bertha-Zeus Amy-Yancey S* . . .

Jan 12, 2018 Sprenkle - CSCI211

What are the possibilities that lead to this?

slide-5
SLIDE 5

1/12/18 5

Proof of Correctness: Stability

  • Claim. No unstable pairs.
  • Pf. (by contradic&on)

Ø Suppose m-w is an unstable pair: m, w prefers each other to partner in Gale-Shapley matching S*. Ø Case 1: m never proposed to w ⇒ m prefers his GS partner to w. ⇒ m-w is stable. Ø Case 2: m proposed to w ⇒ w rejected m (right away or later) ⇒ w prefers her GS partner to m. ⇒ m-w is stable. Ø In either case m-w is stable, a contradic&on. ▪

9

Bertha-Zeus Amy-Yancey S* . . .

men propose in decreasing order of preference women only trade up

Jan 12, 2018 Sprenkle - CSCI211

Summary So Far…

  • 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 any input

10 Jan 12, 2018 Sprenkle - CSCI211

Remaining Questions:

  • If there are multiple stable matchings, which one does GS

find? (see book)

  • How to implement GS algorithm efficiently? (Wednesday)
  • What is our goal running time?
slide-6
SLIDE 6

1/12/18 6

Review: Our Process

  • 1. Understand/iden&fy problem

Ø Simplify as appropriate

  • 2. Design a solu&on
  • 3. Analyze

Ø Correctness, efficiency Ø May need to go back to step 2 and try again

  • 4. Implement

Ø Within bounds shown in analysis

Jan 12, 2018 Sprenkle - CSCI211 11

Lloyd Shapley

  • 2012 Nobel Memorial Prize in Economic Sciences

“for the theory of stable alloca&ons and the prac&ce of market design.”

Jan 10, 2018 Sprenkle - CSCI211 12

1980 2012

slide-7
SLIDE 7

1/12/18 7

Stable Matching Summary

  • Stable matching problem. Given preference

profiles of n men and n women, find a stable matching.

  • Gale-Shapley algorithm. Finds a stable matching

in O(n2) &me.

Ø Claim: can implement algorithm efficiently

13

no man and woman prefer to be with each other than assigned partner

Jan 12, 2018 Sprenkle - CSCI211

TODAY’S GOAL: DEFINE ALGORITHM EFFICIENCY

Jan 12, 2018 Sprenkle - CSCI211 14

slide-8
SLIDE 8

1/12/18 8

Our Process

  • 1. Understand/iden&fy problem

Ø Simplify as appropriate

  • 2. Design a solu&on
  • 3. Analyze

Ø Correctness, efficiency Ø May need to go back to step 2 and try again

  • 4. Implement

Ø Within bounds shown in analysis

Jan 12, 2018 Sprenkle - CSCI211 15

(On Wednesday)

Computa&onal Tractability

Jan 12, 2018 Sprenkle - CSCI211 16

Charles Babbage (1864) As soon as an Analytic Engine exists, it will necessarily guide the future course of the science. Whenever any result is sought by its aid, the question will arise - By what course of calculation can these results be arrived at by the machine in the shortest time?

  • - Charles Babbage

Analytic Engine (schematic)

http://plan28.org/

slide-9
SLIDE 9

1/12/18 9

Brute Force

  • For many non-trivial problems, there is a natural

brute force search algorithm that checks every possible solu&on

Ø Typically takes 2N &me or worse for inputs of size N Ø Unacceptable in prac&ce

Jan 12, 2018 Sprenkle - CSCI211 17

Example: How many possible solutions are there in the stable matching problem?

In other words, how many possible perfect matchings are there? For each perfect match, we’ll check if it’s stable. “Exponential”

Brute Force

  • For many non-trivial problems, there is a natural

brute force search algorithm that checks every possible solu&on

Ø Typically takes 2N &me or worse for inputs of size N Ø Unacceptable in prac&ce

  • Example: Stable matching: n! with n men and n

women

Ø If n increases by 1, what happens to the running &me?

Jan 12, 2018 Sprenkle - CSCI211 18

“Exponential”

slide-10
SLIDE 10

1/12/18 10

How Do We Measure Run&me?

Jan 12, 2018 Sprenkle - CSCI211 19

Worst-Case Running Time

  • Obtain bound on largest possible running &me of

algorithm on input of a given size N

Ø Generally captures efficiency in prac&ce Ø Draconian view but hard to find effec&ve alterna&ve

Jan 12, 2018 Sprenkle - CSCI211 20

What are alternatives to worst-case analysis?

slide-11
SLIDE 11

1/12/18 11

Average Case Running Time

  • Obtain bound on running &me of algorithm on

random input as a func&on of input size N

Ø Hard (or impossible) to accurately model real instances by random distribu&ons Ø Algorithm tuned for a certain distribu&on may perform poorly on other inputs

Jan 12, 2018 Sprenkle - CSCI211 21

Towards a Defini&on of Efficient…

  • Desirable scaling property: When input size

doubles, algorithm should only slow down by some constant factor C

Ø Doesn’t grow mul&plica&vely

Jan 12, 2018 Sprenkle - CSCI211 22

slide-12
SLIDE 12

1/12/18 12

Polynomial-Time

ü

Desirable scaling property: When input size doubles, algorithm should only slow down by some constant factor C

Ø What happens if we double N?

  • Defn. An algorithm is polynomial 4me (or

poly4me) if the above scaling property holds.

Jan 12, 2018 Sprenkle - CSCI211 23

  • Defn. There exists constants c > 0 and d > 0

such that on every input of size N, its running time is bounded by c Nd steps.

Algorithm Efficiency

  • Defn. An algorithm is efficient if its running &me is

polynomial

  • Jus&fica&on: It really works in prac&ce!

Ø In prac&ce, poly-&me algorithms that people develop almost always have low constants and low exponents Ø Breaking through the exponen&al barrier of brute force typically exposes some crucial structure of the problem

  • Excep&ons

Ø Some poly-&me algorithms do have high constants and/

  • r exponents (6.02 × 1023 × N20) and are useless in

prac&ce Ø Some exponen&al-&me (or worse) algorithms are widely used because the worst-case instances seem to be rare

Jan 12, 2018 Sprenkle - CSCI211 24

slide-13
SLIDE 13

1/12/18 13

Running Times

Jan 12, 2018 Sprenkle - CSCI211 25

Input Size

Polynomial

Visualizing Running Times

Jan 12, 2018 Sprenkle - CSCI211 26

  • Huge difference from polynomial to not polynomial
  • Differences in runtime matter more as input size increases

Polynomial 2n 1.5n n10 n3

0.000001 1E+10 1E+26 1E+42 1E+58 1E+74 1E+90 1E+106 1E+122 1E+138 1E+154 1E+170 1E+186 1E+202 1E+218 1E+234 1E+250 1E+266 1E+282 1 10 100 1000

Running Time Input Size

n2 n

slide-14
SLIDE 14

1/12/18 14

Comparing 10000 n2 and n3

Jan 12, 2018 Sprenkle - CSCI211 27

As input size increases, n3 dominates large constant * n2 è Care about running time as input size approaches infinity è Only care about highest-order term

n3 10000 n2

0.000001 0.0001 0.01 1 100 10000 1000000 100000000 1E+10 1E+12 1E+14 1E+16 1E+18 1E+20 1E+22 1E+24 1 10 100 1000 10000 1000000 10000000 100000000

Running Time Input Size

Asympto&c Order of Growth: Upper Bounds

  • T(n) is the worst case running &me of an

algorithm

  • We say that T(n) is O(f(n)) if there exist constants

c > 0 and n0 ≥ 0 such that for all n ≥ n0, we have T(n) ≤ c · f(n)

Jan 12, 2018 Sprenkle - CSCI211 28

sufficiently large n T(n) is bounded above by a constant multiple of f(n)

èT is asymptotically upperbounded by f

c cannot depend on n “order f(n)”

slide-15
SLIDE 15

1/12/18 15

Asympto&c Order of Growth: Upper Bounds

Jan 12, 2018 Sprenkle - CSCI211 29

f(n) T(n)

n0

Point at which f(n) > T(n)

Upper Bounds Example

  • Find an upperbound for

T(n) = pn2 + qn + r

Ø p, q, r are posi&ve constants

Jan 12, 2018 Sprenkle - CSCI211 30

Motivation: Why can we simplify to just the largest term?

slide-16
SLIDE 16

1/12/18 16

Upper Bounds Example

  • Find an upperbound for

T(n) = pn2 + qn + r

Ø p, q, r are posi&ve constants

Jan 12, 2018 Sprenkle - CSCI211 31

Idea: Let’s inflate the terms in the equation so that all terms are n2

Upper Bounds Example

  • T(n) = pn2 + qn + r

Ø p, q, r are posi&ve constants

  • For all n ≥ 1,

è T(n) ≤ cn2, where c = p+q+r è T(n) = O(n2)

  • Also correct to say that T(n) = O(n3)

Jan 12, 2018 Sprenkle - CSCI211 32

T(n) = pn2 + qn + r ≤ pn2 + qn2 + rn2 = (p+q+r) n2 = c n2

slide-17
SLIDE 17

1/12/18 17

Nota&on

  • T(n) = O(f(n)) is a slight abuse of nota&on

Ø Asymmetric:

  • f(n) = 5n3; g(n) = 3n2
  • f(n) = O(n3) = g(n)
  • But f(n) ≠ g(n).

Ø BeQer notaRon: T(n) ∈ O(f(n))

  • Meaningless statement. Any comparison-based

sor&ng algorithm requires at least O(n log n) comparisons

Ø Use Ω for lower bounds

Jan 12, 2018 Sprenkle - CSCI211 33

Asympto&c Order of Growth: Lower Bounds

  • Complementary to upper bound
  • T(n) is Ω(f(n)) if there exist constants ε > 0 and

n0 ≥ 0 such that for all n ≥ n0 , we have T(n) ≥ ε · f(n)

Jan 12, 2018 Sprenkle - CSCI211 34

èT is asymptotically lowerbounded by f

sufficiently large n T(n) is bounded below by a constant multiple of f(n) ε cannot depend on n

slide-18
SLIDE 18

1/12/18 18

Looking Ahead

  • Con&nue reading Chapter 2

Ø Covering later sec&ons on Wednesday

  • Journal for 2 pages of Preface, Chapter 1 - 2.2 due

Tuesday

Ø No journal for Chapter 1.2

  • Problem Set 1 due next Friday before class

Ø Proof, stable matching, asympto&c bound Ø Start early!

  • Read problems and let your brain start thinking about

them

  • Solved exercises in book

Ø Honor Code

Jan 12, 2018 Sprenkle - CSCI211 35