DOC PREVIEW
Princeton COS 116 - Lecture 3

This preview shows page 1-2-17-18-19-36-37 out of 37 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Telling a computer how to behave (via pseudocode -- a workaround for Computings Tower of Babel.) COS 116, Spring 2012 Adam FinkelsteinToday’s themeSearch Romance RomancehelpPin All Your Romantic Hopes on GoogleWhen you think about it, love is just another search problem. And we’ve thoughtabout it. A lot. Google Romance™ is our solution.Google Romance is a place where you can post all types of romantic informationand, using our Soulmate Search™, get back search results that could, in theory,include the love of your life. Then we'll send you both on a Contextual DateTM,which we'll pay for while delivering to you relevant ads that we and our advertisingpartners think will help produce the dating results you're looking for.With Google Romance, you can:Upload your profile – tell the world who you are, or, more to the point,who you’d like to think you are, or, even more to the point, who you wantothers to think you are.Search for love in all (or at least a statistically significant majority of) theright places with Soulmate Search, our eerily effective psychographicmatchmaking software.Endure, via our Contextual Dating option, thematically appropriatemultimedia advertising throughout the entirety of your free date.Learn more: Take the Tour, Press Release, FAQTake the tourPost yourGoogle Romance profilePost multiple profiles witha bulk upload file, you sleazeUser A: “Finally I’ve foundmy Soulmate! Thanks,Google Romance!”User B: "I never thoughtI’d be writing an onlinedating testimonial.Until I met User A…”©2010 Google - Google Home - About GoogleGoogle Romance http://www.google.com/romance/1 of 1 2/9/10 7:26 AMAlgorithm  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 Inputs OutputsScribbler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 } Conditional LoopScribbler 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 statementsFor a computer, everythings a number Audio waveform Sequence of Numbers representing frequency, amplitude, etc. Sequence of Numbers representing color value of each pixel. ImageGeneral 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) 40.99 62.99 52.99 … 22.99A 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 priceMemory: 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.99 i = value nameExamples 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] = 52.99 40.99 62.99 52.99 … 22.99 A =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 ← tmpLove, 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. Zeus Bertha Amy Diane Erika Clare Yancey Amy Clare Diane Bertha Erika Xavier Bertha Clare Erika Diane Amy Wyatt Diane Amy Bertha Clare Erika Victor Bertha Diane Amy Erika Clare Man 1st 2nd 3rd 4th 5th Mens Preference List worst bestStable Matching Problem Erika Yancey Zeus Wyatt Xavier Victor Diane Victor Yancey Zeus Xavier Wyatt Clare Wyatt Yancey Xavier Zeus Victor Bertha Xavier Yancey Wyatt Victor Zeus Amy Zeus Wyatt Victor Yancey Xavier Woman 1st 2nd 3rd 4th 5th Womens Preference List worst best 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 


View Full Document

Princeton COS 116 - Lecture 3

Documents in this Course
Lecture 5

Lecture 5

15 pages

lecture 7

lecture 7

22 pages

Lecture

Lecture

32 pages

Lecture

Lecture

16 pages

Midterm

Midterm

2 pages

Lecture

Lecture

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

24 pages

Lecture

Lecture

22 pages

Lecture

Lecture

28 pages

Lecture

Lecture

21 pages

Lecture

Lecture

50 pages

Lecture

Lecture

19 pages

Lecture

Lecture

28 pages

Lecture

Lecture

32 pages

Lecture

Lecture

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

19 pages

Lecture

Lecture

22 pages

Lecture

Lecture

21 pages

Logic

Logic

20 pages

Lab 7

Lab 7

9 pages

Lecture

Lecture

25 pages

Lecture 2

Lecture 2

25 pages

lecture 8

lecture 8

19 pages

Midterm

Midterm

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

29 pages

Lecture

Lecture

40 pages

lecture 3

lecture 3

23 pages

lecture 3

lecture 3

20 pages

Lecture

Lecture

21 pages

Lecture

Lecture

24 pages

Lecture

Lecture

19 pages

Load more
Download Lecture 3
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 3 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 3 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?