DOC PREVIEW
Princeton COS 116 - lecture 3

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 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 20 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 20 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 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

DiscussionTelling a computer how to behave ( via pseudocode, a workaround for Computing’s Tower of Babel.)Recall: ScribblerRecall: Scribbler’s “Language”Scribbler language illustrates essential features of all computer languagesFor a computer, everything’s a numberA simple problemSolutionSimilar question in different setting Memory: a simplified viewExamplesArraysProcedure findminAnother way to express the same procedure.New problem for robot: sortingSolutionSwappingAlgorithmDiscussion Did last week’s lectures and the assigned reading from “Flesh and Machines” make you look at things around you in a new way? How would you summarize Brooks’ key insights that led him to design Genghis?Telling a computer how to behave( via pseudocode, a workaround for Computing’s Tower of Babel.)2/14/2006COS 116Instructor: Sanjeev AroraFace valueSt Lawrence of GoogleJan 12th 2006Paul Saffo at Silicon Valley's Institute for the Future says that “Google is a religion posing as a company.”Playing GodIf Google is a religion, what is its God?It would have to be The Algorithm.Recall: ScribblerLight outputsSpeakerLight sensorsObstacle sensor emitterObstacle sensor detectorStall sensorLine sensor (underneath)Motor/wheelsInputs OutputsRecall: Scribbler’s “Language” Several types of simple instructions E.g. “Move forward for 1 s” Two types of compound instructionsIf <condition> Then{List of instructions}Else{List of instructions}Do for i = 1 to x{List of instructions}Conditional (a.k.a. Branching)LoopScribbler language illustrates essential features of all computer languages Fundamental features of human languages:nouns/verbs/adjectives, subjects/objects, pronouns, etc. Computer languages also share fundamental features, e.g. conditional and loop statements, variables, ability to perform arithmetic, etc.JavaC++BASICPythonComputing’s Tower of BabelFor a computer, everything’s a numberAudio waveformSequence of Numbers representing frequency, amplitude, etc.Sequence of Numbers representing red/green/blue color value of each pixel.ImageA simple problem Say your robot is getting ready for a big date… How would a robot identify the cheapest bottle? (Say it can scan prices)Solution Pick up first bottle, check price Walk down aisle, for each bottle, do the following: If price on bottle < price on bottle in hand, put down the one in you hand and pick up the new bottleSimilar question in different setting  Suppose 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”Examplesi ← 5i ← ji ← j + 1Sets i to value 5Sets i to whatever value is in j; leaves j unchangedSets i to j + 1; leaves junchangedArrays A is an array of n values, A[ i ] is the i’thvalue Example: A[3] = 52.9940.99 62.99 52.99…22.99A =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 express the same procedure.best ← 1;i ← 2Do while (i <= n){if (A[ i ] < A[best]) then{ best ← i }i ← i + 1;}New problem for robot: sortingArrange them so prices increase from left to right.SolutionDo for i=1 to n-1{Find cheapest bottle among those numbered i to nSwap that bottle and the i’th bottle.}“selection sort”Swapping Suppose x and y are variables. How do you swap their values? Need extra variable!tmp ← xx ← yy ← tmpAlgorithm A precise unambiguous procedure for accomplishing a task Named for Abu Abdullah Muhammad bin Musa al-Khwarizmi For example, addition, long division, selection


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

37 pages

lecture 3

lecture 3

23 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?