What makes a good language Does the task you want Keeps you from making mistakes Supports debugging when you need it Has a strong tool kit.

Slides:



Advertisements
Similar presentations
Pecan cinnamon cookies. Walnut Cinnamon Cookies 1/2 cup unsalted butter 3/4 cup granulated sugar, divided 1/4 cup packed light brown sugar 1 large egg.
Advertisements

Chocolate Chip Cookies. Ingredients: ½ cup butter (1 stick) 1/3 c. brown sugar (packed) 1/3 c. granulated sugar (white) 1 egg 1/ 2 t. vanilla 1 cup +
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Semantics of Hoare Logic Aquinas Hobor and Martin Henz.
Baking Chocolate Chip Cookies Ms. Davis Life Skill Class July 11th, 2004.
Fractions with Mom’s Chocolate Chip Jumbles By Margie MacDonald.
Cookies In All Kinds and Colors My favorite cookies by Ms. Kampner.
Chapter 8 Representing Information Digitally.
White Chocolate Orange Cookies. 1 cup butter softened 1/2 cup white sugar 1/2 cup brown sugar 1 egg 1 tablespoon orange zest 2 1/4 cups all-purpose flour.
Writing a Program in a High- level Language Figure out what you want to do –Understand the rules that guide the process you are automating Make sure that.
1 CMSC 132: Object-Oriented Programming II Software Development I Department of Computer Science University of Maryland, College Park.
Algorithms November 27, Administrivia Homework Assignment 6 –If you forgot to put your name on it, let me know Homework Assignment 7 –Due next Tuesday.
Administrivia First pieces of assignment 5 Comments about assignment 5 Assignment 6 Labs 5 and 6.
New Mexico Computer Science For All Introduction to Algorithms Maureen Psaila-Dombrowski.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Scientific Computing Algorithm Convergence and Root Finding Methods.
USS Yorktown (1998) A crew member of the guided-missile cruiser USS Yorktown mistakenly entered a zero for a data value, which resulted in a division by.
Streptococcus pneumoniae. Fig. 6.3b Avery, McCarty and MacLoed, 1944.
How to Make Chocolate Chip Cookies By Sara Hokkala.
1.02 I Preparation Tasks List 11.02I Listing Preparation Tasks.
Baking Cookies English Club eats chocolate chip cookies!
Problem Solving 101 DEFN An algorithm is a group of instructions (often expressed informally) for performing some task. DEFN An algorithm is a group of.
Lecture 2 Fundamental Data Types. Variable Declaration.
Title slide Name of your food Your name (may be alone or with 1 partner) 1 cup butter, softenedbutter 1 cup granulated sugargranulated sugar 3/4 cup light.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Lecturer: Dr. AJ Bieszczad Chapter 11 COMP 150: Introduction to Object-Oriented Programming 11-1 l Basics of Recursion l Programming with Recursion Recursion.
Warm Up Photosynthesis Prediction Cards – Using the cards, work with a partner to predict the process of photosynthesis from beginning to end.
1.02 C Work Plans 1 The secret for success!. Why use a work plan? Helps meal preparation run smoothly Implement these steps: 1.02CWork Plans2 Steps 1-
The Algorithmic Model. What is Computer Science What is Programming Algorithms –Definition –Properties of Good Algorithms –Describing Algorithms –Examples.
Instructional Video Read the Recipe Select Ingredients And Equipment Prepare The Recipe BAKING COOKIES IN THE VIRTUAL WORLD HELP About LO.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
Fundamental Programming: Fundamental Programming K.Chinnasarn, Ph.D.
Computer Science An Introduction and Some Advanced Concepts Too! Prof. Paul Sivilotti Dept. of Computer & Info. Science The Ohio State University
By: Lokman Chan Recursive Algorithm Recursion Definition: A function that is define in terms of itself. Goal: Reduce the solution to.
Cookies !. Ingredients: 3/4 cup granulated sugar 3/4 cup packed brown sugar 1 cup butter or margarine, softened 1 teaspoon vanilla 1 egg 2 cups Gold Medal.
What you’ll need 2 ½ cups of all – purpose flour 1 teaspoon baking soda 1/2 teaspoon of salt 1 cup granulated sugar 2 eggs.
Functional Text. What is “functional text?” Instruction manuals Recipes Lists of facts (ex: nutrition facts) Table of contents Index Directions That is.
Are you ready to bake???? Coconut BallsChocolate Chip Cookies.
How to make chocolate chip cookies By Rose Savage.
CS Class 22 Today  A word from the Real World What happens when software goes bad…  Binary Search Announcements  Exam 3 – Nov. 25 th in class.
How to Make Chocolate Chip Cookies Caity Jozwiak Period 6.
The 5 Parts of a Recipe Obj. F2.01 Remember recipe parts & resources.
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Introduction to design and analysis algorithm
How to Make Chocolate Chip Cookies
REESES PEANUT BUTTER CUP COOKIES By:Darnita Coles.
Chocolate Chip Cookies Measurements. Measure Smarter 18 (v) oz. all-purpose flour 1/3 T baking soda 3/4 t & 2 pinches salt 2 sticks butter, softened 12.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
How to Make Chocolate Chip Cookies Fast, Easy, and Yummy Original Author Unknown Modified By: CTAE Resource Network.
1 Introduction to design and analysis algorithm. 2.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Kitchen Measuring Equipment. Measuring 2 Categories of Measuring Equipment Liquid Dry.
Chapter 2C The Mole. Mole Is a word that means a number…. If we talk about eggs… If we talk about shoes… If we talk about cards… If we talk about atoms.
Recipe Notes.
Lecture 2: Static Methods Expressions reading: 1.4 – 2.1
Teach A level Computing: Algorithms and Data Structures
Binary Search Back in the days when phone numbers weren’t stored in cell phones, you might have actually had to look them up in a phonebook. How did you.
The Top 10 bugs
Maple Peanut Butter Thumbprint Cookies
Writing to Inform Mrs. Darrell.
Welcome back to Software Development!
Concrete for Box Culverts – Wet Cast Concrete
Welcome back to Software Development!
CSc 110, Spring 2018 Lecture 3: Functions.
Basics of Recursion Programming with Recursion
Algorithms vs. Programming
Computer Organization COMP 210
COOKIE BAKING LESSON.
Algorithms vs. Programming
Presentation transcript:

What makes a good language Does the task you want Keeps you from making mistakes Supports debugging when you need it Has a strong tool kit

Big number bug On June 4, 1996 an unmanned Ariane 5 rocket launched by the European Space Agency exploded just forty seconds after its lift-off from Kourou, French Guiana. The rocket was on its first voyage, after a decade of development costing $7 billion. The destroyed rocket and its cargo were valued at $500 million. A board of inquiry investigated the causes of the explosion and in two weeks issued a report. It turned out that the cause of the failure was a software error in the inertial reference system. Specifically, a 64 bit floating point number relating to the horizontal velocity of the rocket with respect to the platform was converted to a 16 bit signed integer. The number was larger than 32,768, the largest integer that could be stored in a 16 bit signed integer, and so the conversion failed.

Pentium II bug Software bug encoded in hardware Division algorithm uses a lookup table of 1066 entries Only 1061 of the entries are downloaded to the PLA (programmed logic array from which the data are used) Intel had to recall all versions of the chip

Syntax “typo” bugs NASA Mariner 1, Venus probe (1992) Intended to be the first US spacecraft to visit another planet, it was destroyed by a range officer on 22 July 1962 when it behaved erratically four minutes after launch. –Essentially a period instead of a comma in a FORTRAN DO-Loop

Control flow bug AT&T long distance service fails for nine hours (Wrong BREAK statement in C code) January 15, 1990: 70 million of 138 million long distance customers in the US lost long distance service. Cost to ATT was between $ 75 Million and $100 Million (plus the loss of good will).

buffer overflow (1998) Several systems suffer from a "buffer overflow error", when extremely long addresses are received. The internal buffers receiving the addresses do not check for length and allow their buffers to overflow causing the applications to crash. Hostile hackers use this fault to trick the computer into running a malicious program in its place. Data structure management bug

Summary Programming is difficult –Have to thoroughly understand the task –Have to anticipate all possibilities –Code is written at a fairly primitive level –Impossible to anticipate what users might do Programming languages allow the user to use tools to build code But everything still has bugs The cost of a bug can be very large There is no Moore’s Law for software.

The big picture We built a computer We talked about languages and compilers to make programming the computer easier Next we talk about algorithms, which are implemented by programs

Algorithms Recipes for doing computations The underpinnings of programming –Think out your algorithm –Show that it works –Determine it’s efficiency –Write it as a program

What is an algorithm Algorithm is a recipe Has –Inputs –Rules –Evaluation Criteria –Output

When Do We Use Algorithms When we have a problem to solve Examples of problems –Baking cookies –Putting things in alphabetical order –Searching the Web

Chocolate chip cookies

Input –flour (2 ¼ c) –baking soda (1t) –salt (1t) –butter (1c) –granulated sugar (3/4 c) –brown sugar(3/4c) –vanilla(1t) –eggs (2) –chocolate chip morsels (2c) –chopped nuts (1c) Output –5 dozen cookies

Chocolate chip cookies: Steps Combine flour, baking soda, and salt in small bowl. Beat butter, granulated sugar, brown sugar and vanilla in large bowl Add eggs one at a time Beating after adding each egg Gradually beat in flour mixture Stir in morsels and nuts Drop by rounded tablespoons onto ungreased baking sheets Bake 9-11 minutes Let stand for 2 minutes

Chocolate chip cookie algorithm Primitives –Inputs Flour, baking soda, salt, butter, brown sugar, granulated sugar, vanilla, egg, morsels, nuts Alternatively, chocolate chip cookie mix Alternatively, wheat, sugar cane, … –Operators Combine, Beat, Gradually beat, Stir, Drop, Bake, Let stand

Chocolate chip cookie algorithm Execution –First 2 steps can be done in parallel? Parbegin (Combine(),Beat()) Parend –Machine dependencies Ovens vary (Bake 9-11 minutes) Ingredients vary and so need to be handled differently

Chocolate chip cookie algorithm Algorithm testing –Proof of the pudding is in the eating –How do we mechanize this?

Chocolate chip cookie algorithm Comparing different algorithms –Quality of results –User time –Machine (oven) time

Putting things in alphabetical order Data set sizes –Course list for COS students –PU directory assistance10,000 people –Manhattan phone book1 million people –Social Security database1 billion records –Long distance call billing records 100 billion/year Different methods for different tasks –Fast for large –Simple for small

A simple method for sorting Find smallest value -- put it first in list Find second smallest value -- put it second … Find next smallest value – put it next … When no more values, you’re done

How it works

How it works Find smallest value -- put it first in list

How it works Find second smallest value -- put it second

How it works Finish the sorting

A simple method for sorting To sort array x = {x[1],x[2], …, x[n]} For I = 1 to n For J = I+1 to n If (x[I] > x[J]) Then swap their values next

Another sorting algorithm Sorting by Merging Key idea  It’s easy to merge 2 sorted lists

Merging 2 sorted lists

Merging 2 sorted lists Start at the top of each list

Merging 2 sorted lists is bigger than 155

Merging 2 sorted lists Record 155 and move the arrow

Merging 2 sorted lists is less than 255

Merging 2 sorted lists is less than 255

Merging 2 sorted lists is less than 463

Merging 2 sorted lists Finished when at the end of each list

Sorting by Merging Key idea  It’s easy to merge 2 sorted lists Sort larger lists by –Sorting smaller lists –Merging the results How do we sort smaller lists?

Sort then merge Subdivide

Sort then merge Subdivide Sort pieces By merging

Sort then merge Subdivide Sort piecesMerge

SortMerge algorithm Function SortMerge(x,1,n) -- sort list of n elements x If n = 1 then Return -- nothing to sort End if Mid = (1+ n)/2-- midpoint of list SortMerge(x,1, Mid )-- sort first half of list SortMerge(x, Mid +1, n)-- sort second half of list Merge(x,1, Mid, Mid +1, n)-- merge sorted halves End Function

Does it work? Have to be careful about stopping There are always a lot of things going on Sort(n) Sort(n/2) Merge Sort(n/4) Merge Sort(n/2) Merge Sort(n/8) Merge Sort(n/4) Merge Sort(n/2) Merge

Divide and conquer Use recursion –reduce solving for problem of size n to solving two problems of size n/2 –then combine the solutions S(n) = 2 S(n/2) + M(n/2,n/2) Solving a sorting problem of size n requires solving 2 sorting problems of size n/2 and doing a merge of 2 sets of size n/2

Comparing running times NInsertion (ms) SortMerge(ms) , , ,000,

Comparing running times NInsertion (ms) SortMerge(ms) , , ,000, Reducing 20 hours to 3 seconds

Searching Once a list is in alphabetical order, how do you find things in it? For example, is COS 111 on the list of courses that satisfy the (EC) Epistemology and Cognition requirement?

EC courses PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200

Searching for COS 111 Compare to the middle AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 COS 111

Searching Compare to the middle If smaller search first half If larger search second half AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 COS 111

Repeat Compare to the middle If smaller search first half If larger search second half AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 COS 111

Building indices PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 AAS ANT COS FRS GER HUM LIN PHI PSY

Search indices then data PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 AAS ANT COS FRS GER HUM LIN PHI PSY COS 111