390 likes | 627 Views
CPSC 320: Intermediate Algorithm Design and Analysis. July 2, 2014. Instructor and Course Structure. Instructor. Jonatan Schroeder jonatan@cs.ubc.ca Office: ICICS/CS 247 Office hours: Mon/Wed/Fri: 12-1pm Or by appointment. Teaching Assistants. Alireza Shafaei Anupam Srivastava
E N D
CPSC 320: Intermediate AlgorithmDesign and Analysis July 2, 2014
Instructor Jonatan Schroeder jonatan@cs.ubc.ca Office: ICICS/CS 247 Office hours: Mon/Wed/Fri: 12-1pm Or by appointment
Teaching Assistants AlirezaShafaei Anupam Srivastava Jianing Yu Juyoung Moon Reza Babanezhad
Pre-requisites Listed student numbers should come to me after class If you fail to act, you may be dropped from the course Walk-in advising hours: Today 4-5pm: ICCS 391 (Paul Carter) Thu 10:30-11:30am: ICCS 391 (Paul Carter) Thu 3-4pm: ICCS 307 (George Tsiknis) Additional hours may be listed in front of CS main office
Learning Goals Understand techniques used to design efficient algorithms Prove (or disprove) that designed algorithms are correct Prove that designed algorithms are efficient
Course Outline Introduction and basic concepts Asymptotic notation Greedy algorithms Graph theory Amortized analysis Recursion Divide-and-conquer algorithms Randomized algorithms Dynamic programming algorithms NP-completeness
Schedule Lectures: Mon/Wed/Fri 9:30-12:00 Tutorials: T2A: Wed/Fri 1-2pm (Anupam) T2B: Wed/Fri 2-3pm (Anupam) T2C: Wed/Fri 3-4pm (Alireza)
Piazza All course announcements will be posted on Piazza All course-related questions should be asked on Piazza Instructors and TAs will direct your questions to Piazza when relevant Questions including part of a possible solution should be made private Instructors may change a private question to public if deemed useful for other students Students are encouraged to answer questions as well
Piazza (continued) Please take a minute to understand how Piazza works Students’ response is for answering questions, not follow-ups Remember to mark follow-ups as resolved If you found the answer on your own, please add an answer (don’t delete the question)
Marking scheme 6 or 7 assignments: 20% 5 quizzes: 30% Final exam: 50% You must pass the exam to pass the course You must pass in the average of the quizzes You must submit at least five of the assignments
Assignments 6 or 7 assignments Electronic submission or physical copy submission? Please answer a poll on Piazza today before 6PM!!! Assignment 1 will be posted some time today
Quizzes Quiz 1: Wed, July 9 Quiz 2: Wed, July 16 Quiz 3: Wed, July 23 Quiz 4: Wed, July 30 Quiz 5: Wed, August 6 Closed book, closed notes, no calculator Individual component: about 30 minutes Group component: about 15 minutes The group component is to be done in groups of 3-4 Group will solve one of the questions in the individual component
Textbook John Kleinberg and ÉvaTardos, Algorithm Design, Addison-Wesley Publishing company, 2005, ISBN 0-321-29535-8. Optional: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein, Introduction to Algorithms, 3rd edition, MIT Press, 2009, ISBN 0-262-03384-4.
Representative Problem The Stable Matching Problem
Algorithm Sequence of steps to solve a specific task or problem Takes an input, provides a result Each step depends solely on the input and on previous steps Stops in finite time
Algorithm Analysis Does the algorithm terminate? How long does it take (as a function of the input size)? Does it produce a valid result? Is the produced result correct? Is the produced result optimal?
Stable Matching Problem Given men and women Each man ranks all women in preferred order and vice-versa Assign every man to exactly one woman (and vice-versa) Assignment needs to be stable Matching If there is a pair such that prefers over and prefers over then matching is unstable
Example Assume the input: M = {Alvin, Bob, Chuck, Donald} W = {Janice, Kelly, Linda, Madison} Preference ranking:
Example Example matching: (A, L), (B, J), (C, K), (D, M) Unstable (D prefers J, J prefers D)
Example Example matching: (A, L), (B, M), (C, K), (D, J) Stable (no changes give better option)
Example Example matching: (A, L), (B, M), (C, K), (D, J) Stable (no changes give better option)
Discussion What strategies can be used to find a matching? Is there an optimal solution? What defines optimal in this case? Design an algorithm
Gale-Shapley Algorithm set all and to free while some free woman hasn’t proposed to every man do ← the highest-ranking man hasn’t proposed to ifis free then engage else ← s current fiancée ifprefers to then set to free engage return the set of engaged pairs
What should we do now? Does the algorithm produce a matching? Result includes every woman and every man? Each woman is assigned to exactly one man? Each man is assigned to exactly one woman? Is the matching stable? How long (in the worst case) does the algorithm take to terminate?
Complexity Does the algorithm terminate? What happens to a man m as the algorithm progresses? How many times can a man get engaged? What happens to a woman w as the algorithm progresses? How many times can a woman get engaged? What happens overall as the algorithm progresses?
Complexity Theorem: the algorithm terminates in no more than iterations Every iteration contains one proposal Every woman proposes to a man she hasn’t proposed to before At most, each woman proposes to men There are women Number of iterations:
Complexity (discussion) So, does the algorithm run in ? How long to find a free woman? How long to find the preferred man to propose? How long to decide if a man should switch? How long to add/replace a pair from the matching set?
Correctness: Is the result a matching? Does the resulting matching include every woman? Every man, once engaged, is always engaged If there is a free woman, there is a free man Free woman will find a free man Is each man engaged to one woman only? If a man is free during proposal, he will be engaged to one woman If a man is not free, he may replace one woman for another Is each woman engaged to one man only? Only free women propose
Correctness: Is matching stable? By contradiction, suppose matching is unstable and are matched prefers , prefers Three possible cases: never proposed to proposed to , but got rejected proposed to , but got replaced
Correctness: Is matching stable? Case 1: never proposed to proposed to , since they got a matching Since proposes in order of preference, proposed to first Contradiction
Correctness: Is matching stable? Case 2: proposed to , but got rejected Men only reject if they are engaged to someone preferred If rejects when engaged to : prefers to , contradiction If rejects when engaged to someone else () rejects because he prefers over later engages to because he prefers over So, prefers over and over , so prefers over , contradiction
Correctness: Is matching stable? Case 3: proposed to , but got replaced If replaces with , prefers over , contradiction Finally, since all cases generate a contradiction, an unstable matching is never generated by this algorithm QED
Discussion Is the result optimal? What is considered optimal? Who gets it better, women or men? How could this be changed?
Equivalent problems Matching students and co-op jobs Matching medical students and hospitals Matching potential students and college openings
Variations and Similar Problems Hospitals can take several students Number of men and women is different Restrictions and limited preference lists Stable roommate problem (matched pairs from same set) Hospital/student matching with couples Taxis and customers (reduced cost of pick up)
Machine Model In all algorithms we will assume: Sequential execution One processor Memory position can hold arbitrarily large integer Unless otherwise specified, we will discuss the worst case Best case: usually not very useful Average case: depends on input distribution assumptions
Upper Bound Describes the upper bound of the growth rate of the function Assume