objectives
play

Objectives Finish implementation of Stable Matching Get out your - PDF document

1/16/19 Objectives Finish implementation of Stable Matching Get out your handouts Survey of common running times Jan 16, 2019 Sprenkle - CSCI211 1 Wiki Feedback Is coming! Edited the wikis fixing sidebars, adding pages


  1. 1/16/19 Objectives • Finish implementation of Stable Matching Ø Get out your handouts • Survey of common running times Jan 16, 2019 Sprenkle - CSCI211 1 Wiki Feedback • Is coming! • Edited the wikis – fixing sidebars, adding pages • Content – For each section Ø Brief summary of the section • ~1 paragraph of about 5-10 sentences per section • feel free to write more if that will help you Ø Include motivations for the given problem, as appropriate Ø For algorithms, brief sketch of algorithm, intuition, and implementation • Include runtime for algorithms Ø Questions you have about motivation/solution/proofs/analysis Ø Discuss anything that makes more sense after reading it again, after it was presented in class (or vice versa) Ø Anything that you want to remember, anything that will help you Ø Say something about how readable/interesting the section was on scale of 1 to 10 Jan 16, 2019 Sprenkle - CSCI211 2 1

  2. 1/16/19 Get out handouts from last time Review • Run times: Ø What does O(f(n)) mean? • Intuitive • More precise definition Ø What are the other bounds we discussed? • Implementing Stable Matching Algorithm Ø What do we need to model/represent? Ø What are the differences between a list and an array? • What is the cost to convert from an array to a list? Ø Which data structure(s) makes the most sense for the Stable Matching Problem? Jan 16, 2019 Sprenkle - CSCI211 3 Stable Matching Implementation • What do we need to represent? • How should we represent them? Data How represented Men, Women Preference lists Unmatched men Who men proposed to Engagements Jan 16, 2019 Sprenkle - CSCI211 4 2

  3. 1/16/19 Stable Matching Implementation • What do we need to represent? • How should we represent them? Data How represented Men, Women Integers (ids) Preference lists 2 Array of arrays (2D array) Unmatched men List Who men proposed to Integer for each man à Array of integers (maps man’s id to “next” woman) Engagements 2 Arrays, length n Jan 16, 2019 Sprenkle - CSCI211 5 Asymptotic Analysis of Gale-Shapley Alg Initialize each person to be free while (some man is free and hasn't proposed to every woman) Choose such a man m w = 1 st 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 What is the running time of each part of the algorithm? What is the total running time of the algorithm? Jan 16, 2019 Sprenkle - CSCI211 6 3

  4. 1/16/19 Efficient Implementation • Women rejecting/accepting: determine does woman w prefer man m to man m' ? Ø For each woman, create array of men with her preference • inverse of preference list Ø Constant time access for each query after O(n) preprocessing Amy 1 st 2 nd 3 rd 4 th 5 th 6 th 7 th 8 th Contains man’s id Pref 8 3 7 1 4 5 6 2 For each man, how does he rank? Amy 1 2 3 4 5 6 7 8 Amy prefers man 3 to 6 since inverse[3] < inverse[6] Inverse 4 th 8 th 2 nd 5 th 6 th 7 th 3 rd 1 st 2 7 for i = 1 for = 1 to to n inverse[ inverse[ pref[i pref[i] ] = ] ] = i Jan 16, 2019 Sprenkle - CSCI211 7 Asymptotic Analysis of Gale-Shapley Alg Initialize each person to be free while (some man is free and hasn't proposed to every woman) Choose such a man m w = 1 st 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 What is the running time of each part of the algorithm? What is the total running time of the algorithm? Jan 16, 2019 Sprenkle - CSCI211 8 4

  5. 1/16/19 Asymptotic Analysis of Gale-Shapley Alg Not explicitly in the algorithm, but we need to make the inverse array before the while loop too. O(n) Initialize each person to be free O(n 2 ) while (some man is free and hasn't proposed to every woman) O(1) Choose such a man m O(1) w = 1 st woman on m's list to whom m has not yet proposed O(1) if (w is free) O(1) assign m and w to be engaged Using inverse O(1) else if (w prefers m to her fiancé m') array O(1) assign m and w to be engaged and m' to be free else O(1) w rejects m Total: O(n 2 ) Jan 16, 2019 Sprenkle - CSCI211 9 Looking Ahead • Problem Set 1 due Friday, before class Jan 16, 2019 Sprenkle - CSCI211 10 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend