Telling a computer how to behave (via pseudocode -- a workaround for Computing’s Tower of Babel.) COS 116, Spring 2012 Adam Finkelstein.

Slides:



Advertisements
Similar presentations
Blah blah blah. Zoes shark Thanks to the conference artist Phoebe.
Advertisements

ZeusBerthaAmyDianeErikaClare YanceyAmyClareDianeBerthaErika XavierBerthaClareErikaDianeAmy WyattDianeAmyBerthaClareErika VictorBerthaDianeAmyErikaClare.
Piyush Kumar (Lecture 3: Stable Marriage) Welcome to COT5405.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 2.
1 Overview of Graph Theory Addendum “The Stable Marriage Problem” Instructor: Carlos Pomalaza-Ráez Fall 2003 University of Oulu, Finland.
Naveen Garg, CSE, IIT Delhi
Matching Theory.
Matching problems Toby Walsh NICTA and UNSW. Motivation Agents may express preferences for issues other than a collective decision  Preferences for a.
CSC 430 Lecture1: Introduction and Python Primer.
Telling a computer how to behave (via pseudocode -- a workaround for Computing’s Tower of Babel.) COS 116, Spring 2010 Adam Finkelstein.
ZeusBerthaAmyDianeErikaClare YanceyAmyClareDianeBerthaErika XavierBerthaClareErikaDianeAmy WyattDianeAmyBerthaClareErika VictorBerthaDianeAmyErikaClare.
Lecture 4 CSE 331 Sep 9, Blog posts for lectures Starts from today See Sep 8 post on the blog.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne COS 423: Theory of Algorithms Princeton University Spring, 2001 Kevin Wayne.
Lecture 5 CSE 331 Sep 11, HW 1 out today Will be handed out at the END of the lecture Read the homework policy document carefully START EARLY! ©ehow.com.
Lecture 8 CSE 331 Sep 18, Homeworks Hand in your HW 1 HW 2 and solutions to HW 1 out at the end of class Not naming your collaborators is same as.
Telling a robot how to behave Adam Finkelstein COS 116: Spring 2012.
Creating new worlds inside the computer COS 116: 2/10/2011 Sanjeev Arora.
Week 11 - Friday.  What did we talk about last time?  Exam 2 post mortem  Cycle detection  Connectivity.
Lecture 6 CSE 331 Sep 10, Homeworks HW 1 posted online: see blog/piazza Pickup graded HW 0 in TA OHs.
Introduction CSE 1310 – Introduction to Computers and Programming
CSC 430 Lecture1: Introduction and Python Primer.
The Stable Marriage Problem
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 1.
1 Chapter 1 Introduction: Some Representative Problems Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Stable Matching Problem Goal. Given n men and n women, find a "suitable" matching. n Participants rate members of opposite sex. n Each man lists women.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
By the end of this session you should be able to...
Lecture 4 CSE 331 Sep 6, TA change Swapnoneel will leave us for 531 Jiun-Jie Wang will join us.
Lecture 2 CSE 331. Day 1 Survey On UBlearns Day 1 Survey (talking points) Security MS PhD for research Building PC’s for 442 It’s ok to play games –
Lecture 5 CSE 331 Sep 11, Submit the form I’ll need confirmation in writing. No graded material will be handed back till I get this signed form.
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
1 The Stable Marriage Problem Algorithms and Networks 2014/2015 Hans L. Bodlaender Johan M. M. van Rooij.
1 Today’s Material Iterative Sorting Algorithms –Sorting - Definitions –Bubble Sort –Selection Sort –Insertion Sort.
Stable Matching Lecture 7: Oct 3. Matching A B C DE Boys Girls Today’s goal: to “match” the boys and the girls in a “good” way.
1 Chapter 1 Introduction: Some Representative Problems Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Design & Co-design of Embedded Systems Final Project: “The Match Maker” Second Phase Oral Presentation Safa S. Mahmoodian.
Bipartite Matching. Unweighted Bipartite Matching.
The Stable Marriage Problem
Matching Lecture 19: Nov 23.
Telling a computer how to behave (via pseudocode -- a workaround for Computing’s Tower of Babel.) COS 116, Spring 2011 Sanjeev Arora.
CSCI 256 Data Structures and Algorithm Analysis lecture 1 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Fair Shares.
Introduction CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
CSCI 256 Data Structures and Algorithm Analysis Lecture 2 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Market Design and Analysis Lecture 2 Lecturer: Ning Chen ( 陈宁 )
COMP9007: Algorithms Stable Matching. What's in an algorithm? Algorithms can have huge impact For example – A report to the White House from 2010 includes.
Matching Boys Girls A B C D E
Cybernetica AS & Tartu University
Stable Matching.
Chapter 1 Introduction: Some Representative Problems
Stable Marriage Problem
Introduction to the Design and Analysis of Algorithms
The Stable Marriage Problem
Introduction CSE 1310 – Introduction to Computers and Programming
CSE 421: Introduction to Algorithms
Lecture 5 CSE 331 Sep 10, 2010.
S. Raskhodnikova; based on slides by K. Wayne
CSE 421: Introduction to Algorithms
1.1 A First Problem: Stable Matching
Discrete Math for CS CMPSC 360 LECTURE 9 Last time: Strong induction
Lecture 5 CSE 331 Sep 6, 2013.
Lecture 5 CSE 331 Sep 7, 2012.
Blah blah blah.
Chapter 1 Introduction: Some Representative Problems
Richard Anderson Winter 2019 Lecture 1
Piyush Kumar (Lecture 3: Stable Marriage)
Week 10 - Wednesday CS221.
Presentation transcript:

Telling a computer how to behave (via pseudocode -- a workaround for Computing’s Tower of Babel.) COS 116, Spring 2012 Adam Finkelstein

Today’s theme

Algorithm A precise unambiguous procedure for accomplishing a task Named for Abu Abdullah Muhammad bin Musa al-Khwarizmi  His book "Al-Jabr wa-al-Muqabilah" evolved into today's high school algebra text. Examples: recipe, long division, selection sort.

Example: Adding two numbers Discussion Time Imagine you are describing this task to somebody who has never done it. How would you describe it?

How can we describe an algorithm precisely enough so there is no ambiguity?

Scribbler Light outputs Speaker Light sensors Obstacle sensor emitter Obstacle sensor detector Stall sensor Line sensor (underneath) Motor/wheels InputsOutputs

Scribbler’s “Language” Several types of simple instructions  E.g. “Move forward for 1 s” Two types of compound instructions If condition Then { List of instructions } Else { List of instructions } Do 5 times { List of instructions } ConditionalLoop

Scribbler language illustrates essential features of all computer languages Java C++ BASIC Python Computing’s Tower of Babel Features of human languages: nouns/verbs/subjects/objects, etc. Features of computer languages: variables, simple arithmetic instructions, conditional/loop statements

For a computer, everything’s a number Audio waveform Sequence of Numbers representing frequency, amplitude, etc. Sequence of Numbers representing color value of each pixel. Image

General task faced by computer Given: Sequence of numbers in memory (eg, mp3 song) Goal: Process these numbers to achieve a desired sequence of numbers as output (eg, electrical signals that drive the headphones and reproduce the song) … 22.99

A simple problem Our robot is getting ready for a big date… How would it identify the cheapest bottle? (Say it can pick up a bottle & scan prices.)

Solution Pick up first bottle, check price Walk down aisle. For each bottle, do this:  If price on bottle is less than price in hand, exchange it with the one in hand.

Similar question in different setting Robot has n prices stored in memory Want to find minimum price

Memory: a simplified view A scratchpad that can be perfectly erased and re-written any number of times A variable: a piece of memory with a name; stores a “value” 22.99i = valuename

Examples i  5 Sets i to value 5 j  i Sets j to whatever value is in i. Leaves i unchanged i  j + 1 Sets i to j + 1. Leaves j unchanged i  i + 1 Sets i to 1 more than it was.

Arrays A is an array of n values A[ i ] is the i’th value Example: A[3] = … 22.99A =

Solution Pick up first bottle, check price Walk down aisle. For each bottle, do this:  If price on bottle is less than price in hand, exchange it with the one in hand.

Procedure findmin n items, stored in array A Variables are i, best best  1 Do for i = 2 to n { if ( A[i] < A[best] ) then best  i }

Another way to do the same best  1; i  1 Do while (i < n) { i  i + 1; if ( A[i] < A[best] ) then best  i }

New problem for robot: sorting Arrange them so prices increase from left to right.

I have to sort n bottles. Let me find the cheapest bottle and move it to leftmost position. Then I only have to the other bottles to its right.

Solution Do for i=1 to n-1 { Find cheapest bottle among those numbered i to n Swap that bottle and the i ’th bottle. } “selection sort” Note: we know how to do this!

Swapping Suppose x and y are variables. How do you swap their values? Need extra variable! tmp  x x  y y  tmp

Love, Marriage & Broken Hearts Standard disclaimer.

Stable Matching Problem Problem: Given N men & N women, find “suitable” matching  Everyone lists their preferences from best to worst. ZeusBerthaAmyDianeErikaClare YanceyAmyClareDianeBerthaErika XavierBerthaClareErikaDianeAmy WyattDianeAmyBerthaClareErika VictorBerthaDianeAmyErikaClare Man 1 st 2 nd 3 rd 4 th 5 th Men’s Preference List worstbest

Stable Matching Problem ErikaYanceyZeusWyattXavierVictor DianeVictorYanceyZeusXavierWyatt ClareWyattYanceyXavierZeusVictor BerthaXavierYanceyWyattVictorZeus AmyZeusWyattVictorYanceyXavier Woman 1 st 2 nd 3 rd 4 th 5 th Women’s Preference List worstbest Problem: Given N men & N women, find “suitable” matching  Everyone lists their preferences from best to worst.

Stable Matching Problem What do we mean by “suitable”?  PERFECT: everyone matched monogamously.  STABILITY: no incentive for some pair to elope. a pair that is not matched with each other is UNSTABLE if they prefer each other to current partners unstable pair: improve by dumping spouses and eloping STABLE MATCHING (Gale and Shapley, 1962) = perfect matching with no unstable pairs.

Lavender assignment is a perfect matching. Are there any unstable pairs? Men’s Preference List Women’s Preference List Zeus Yancey Xavier Man A B A 1 st B A B 2 nd C C C 3 rd Clare Bertha Amy Woman X X Y 1 st Y Y X 2 nd Z Z Z 3 rd  Yes. Bertha and Xavier form an unstable pair. They would prefer each other to current partners. B X Example

Green assignment is a stable matching. A B A CX X Y Y Y X Z Z Z Men’s Preference List Women’s Preference List Zeus Yancey Xavier Man1 st B A B 2 nd C C 3 rd Clare Bertha Amy Woman1 st 2 nd 3 rd

Example Gray assignment is also a stable matching. AX X Y Y Z Z Men’s Preference List Women’s Preference List Zeus Yancey Xavier Man1 st A B 2 nd C C 3 rd Clare Bertha Amy Woman1 st 2 nd 3 rd B A B C X Y Z

Propose-And-Reject Algorithm Guarantees a stable matching. Initialize each person to be free. while (some man m is free and hasn't proposed to every woman) { w = first woman on m's list to whom he has not yet proposed if (w is free) assign m and w to be engaged else if (w prefers m to her fiancé f) assign m and w to be engaged, and f to be free else w rejects m } Gale-Shapley Algorithm (men propose)

Extensions Unacceptable partners  Every woman is not willing to marry every man, and vice versa.  Some participants declare others as “unacceptable.” Sets of unequal size  Unequal numbers of men and women, e.g. 100 men & 90 women Limited Polygamy  e.g., Bill wants to be matched with 3 women.

Matching Residents to Hospitals Hospitals ~ Men (limited polygamy allowed). Residents ~ Women (more than hospitals) Started just after WWII (before computer usage). Ides of March, 13,000+ residents are matched. Rural hospital dilemma.  Certain hospitals (mainly in rural areas) were unpopular and declared unacceptable by many residents.  How to find stable matching that benefits rural hospitals?

Homework for next Thurs ( your answers to by 2/23 noon as part of Write out pseudocode for selection sort. Try Gale-Shapley algorithm for previously-shown Amy-Erica / Victor-Zeuss preference lists, but vary the order of choosing man m. Does this affect the outcome? Try the version where women propose. Does this affect the outcome? Bonus question: Try to justify this statement: When the Gale-Shapley algorithm finishes, there are no unstable pairs.

Lessons Learned Powerful ideas learned in computer science. Sometimes deep social ramifications.  Hospitals and residents…  Historically, men propose to women. Why not vice versa?  Computer scientists get the best partners!!! Thursday: the perfect storm…