CS 111 Green: Program Design I Lecture 27: Speed (cont.); parting thoughts

Similar documents
Python Programming: An Introduction to Computer Science

CS 111: Program Design I Lecture # 7: First Loop, Web Crawler, Functions

n Some thoughts on software development n The idea of a calculator n Using a grammar n Expression evaluation n Program organization n Analysis

Lecture Notes 6 Introduction to algorithm analysis CSS 501 Data Structures and Object-Oriented Programming

CS 111: Program Design I Lecture 16: Module Review, Encodings, Lists

CSC 220: Computer Organization Unit 11 Basic Computer Organization and Design

Analysis Metrics. Intro to Algorithm Analysis. Slides. 12. Alg Analysis. 12. Alg Analysis

CMPT 125 Assignment 2 Solutions

CSE 111 Bio: Program Design I Class 11: loops

Chapter 1. Introduction to Computers and C++ Programming. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

CSE 111 Bio: Program Design I Lecture 17: software development, list methods

CS 111: Program Design I Lecture #26: Heat maps, Nothing, Predictive Policing

CS 111: Program Design I Lecture 19: Networks, the Web, and getting text from the Web in Python

CS 111: Program Design I Lecture 21: Network Analysis. Robert H. Sloan & Richard Warner University of Illinois at Chicago April 10, 2018

Python Programming: An Introduction to Computer Science

One advantage that SONAR has over any other music-sequencing product I ve worked

CS 111: Program Design I Lecture # 7: Web Crawler, Functions; Open Access

Ones Assignment Method for Solving Traveling Salesman Problem

CS 111: Program Design I Lecture 20: Web crawling, HTML, Copyright

CS 11 C track: lecture 1

CS 111: Program Design I Lecture 15: Modules, Pandas again. Robert H. Sloan & Richard Warner University of Illinois at Chicago March 8, 2018

CHAPTER IV: GRAPH THEORY. Section 1: Introduction to Graphs

How do we evaluate algorithms?

COP4020 Programming Languages. Compilers and Interpreters Prof. Robert van Engelen

What are we going to learn? CSC Data Structures Analysis of Algorithms. Overview. Algorithm, and Inputs

Lecture 9: Exam I Review

CS 111: Program Design I Lecture 15: Objects, Pandas, Modules. Robert H. Sloan & Richard Warner University of Illinois at Chicago October 13, 2016

. Written in factored form it is easy to see that the roots are 2, 2, i,

Lecture 1: Introduction and Strassen s Algorithm

Threads and Concurrency in Java: Part 1

Chapter 9. Pointers and Dynamic Arrays. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Threads and Concurrency in Java: Part 1

Recursion. Recursion. Mathematical induction: example. Recursion. The sum of the first n odd numbers is n 2 : Informal proof: Principle:

Lecture 28: Data Link Layer

Basic Design Principles

EE University of Minnesota. Midterm Exam #1. Prof. Matthew O'Keefe TA: Eric Seppanen. Department of Electrical and Computer Engineering

Recursion. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Review: Method Frames

Major CSL Write your name and entry no on every sheet of the answer script. Time 2 Hrs Max Marks 70

Message Integrity and Hash Functions. TELE3119: Week4

Analysis of Algorithms

CSE 417: Algorithms and Computational Complexity

Chapter 4 The Datapath

Term Project Report. This component works to detect gesture from the patient as a sign of emergency message and send it to the emergency manager.

Examples and Applications of Binary Search

Abstract. Chapter 4 Computation. Overview 8/13/18. Bjarne Stroustrup Note:

CSC165H1 Worksheet: Tutorial 8 Algorithm analysis (SOLUTIONS)

CS 111: Program Design I Lecture 14: Encodings & Files concluded; Pandas, Modules, legal data analytics

CS 111: Program Design I Lecture 18: Web and getting text from it

Pseudocode ( 1.1) Analysis of Algorithms. Primitive Operations. Pseudocode Details. Running Time ( 1.1) Estimating performance

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5

Designing a learning system

Parabolic Path to a Best Best-Fit Line:

Morgan Kaufmann Publishers 26 February, COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 5.

Chapter 11. Friends, Overloaded Operators, and Arrays in Classes. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

GE FUNDAMENTALS OF COMPUTING AND PROGRAMMING UNIT III

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. Chapter 4. The Processor. Part A Datapath Design

1.2 Binomial Coefficients and Subsets

n Maurice Wilkes, 1949 n Organize software to minimize errors. n Eliminate most of the errors we made anyway.

Designing a learning system

CMSC Computer Architecture Lecture 12: Virtual Memory. Prof. Yanjing Li University of Chicago

Running Time. Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring, Instructions:

A graphical view of big-o notation. c*g(n) f(n) f(n) = O(g(n))

Intermediate Statistics

Math Section 2.2 Polynomial Functions

Exact Minimum Lower Bound Algorithm for Traveling Salesman Problem

10/23/18. File class in Java. Scanner reminder. Files. Opening a file for reading. Scanner reminder. File Input and Output

Running Time ( 3.1) Analysis of Algorithms. Experimental Studies. Limitations of Experiments

Analysis of Algorithms

Outline and Reading. Analysis of Algorithms. Running Time. Experimental Studies. Limitations of Experiments. Theoretical Analysis

COSC 1P03. Ch 7 Recursion. Introduction to Data Structures 8.1

Weston Anniversary Fund

Data Structures and Algorithms. Analysis of Algorithms

condition w i B i S maximum u i

Algorithm. Counting Sort Analysis of Algorithms

Switching Hardware. Spring 2018 CS 438 Staff, University of Illinois 1

Announcements. Reading. Project #4 is on the web. Homework #1. Midterm #2. Chapter 4 ( ) Note policy about project #3 missing components

Lecture 5. Counting Sort / Radix Sort

Lower Bounds for Sorting

ECE4050 Data Structures and Algorithms. Lecture 6: Searching

Last class. n Scheme. n Equality testing. n eq? vs. equal? n Higher-order functions. n map, foldr, foldl. n Tail recursion

ENGR Spring Exam 1

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

The number n of subintervals times the length h of subintervals gives length of interval (b-a).

The isoperimetric problem on the hypercube

implement language system

Today s objectives. CSE401: Introduction to Compiler Construction. What is a compiler? Administrative Details. Why study compilers?

15-859E: Advanced Algorithms CMU, Spring 2015 Lecture #2: Randomized MST and MST Verification January 14, 2015

Lecture 7 7 Refraction and Snell s Law Reading Assignment: Read Kipnis Chapter 4 Refraction of Light, Section III, IV

Basic allocator mechanisms The course that gives CMU its Zip! Memory Management II: Dynamic Storage Allocation Mar 6, 2000.

Administrative UNSUPERVISED LEARNING. Unsupervised learning. Supervised learning 11/25/13. Final project. No office hours today

Threads and Concurrency in Java: Part 2

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Project 2.5 Improved Euler Implementation

Chapter 8. Strings and Vectors. Copyright 2015 Pearson Education, Ltd.. All rights reserved.

Introduction to Sigma Notation

CS 111: Program Design I Lecture 20: Web crawling, HTML, Copyright

Chapter 8. Strings and Vectors. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

CIS 121 Data Structures and Algorithms with Java Spring Stacks, Queues, and Heaps Monday, February 18 / Tuesday, February 19

top() Applications of Stacks

Transcription:

CS 111 Gree: Program Desig I Lecture 27: Speed (cot.); partig thoughts By Nascarkig - Ow work, CC BY-SA 4.0, https://commos.wikimedia.org/w/idex.php?curid=38671041 Robert H. Sloa (CS) & Rachel Poretsky (Bio) Uiversity of Illiois, Chicago December 5, 2017

Please complete the post-class survey (ow) https://uic.ualtrics.com/jfe/form/sv_9lycb6ztepivoll Lik also available from frot page of course Blackboard site

Questios o Phylogeetic Tree Assigmet?

How are you doig? It's the ed of the semester, a stressful time, for all of us, ad ed of the semester for our first year i college for may of us, a particularly stressful time. A. Not a care i the world B. Awfully busy but I'm feelig really fie C. Somewhat stressed D. Quite stressed E. Very stressed

SPEED AND LANGUAGE TRANSLATION: COMPILED VS. INTERPRETED

Some fial course mechaics: Profs do read Piazza Next class: Etirely review for fial if fial_exam(studet) >= 80: replace_ay_lower_hour_exams(studet)

Example from last time: 4 Lies Assembler LOAD R1,#65536 TEST R1,#13 JUMPTRUE #32768 CALL #16384 ; Get a character from keyboard ; Is it a ASCII 13 (Eter)? ; If true, go to aother part of the program ; If false, call fuc. to process the ew lie Machie Laguage (13 bytes): 05 01 255 255 10 01 13 20 127 255 122 63 255

Machie laguage is executed very uickly A mid-rage laptop these days has a clock rate of 1.3 2.6 Gigahertz. What that meas exactly is hard to explai, but let s iterpret it as processig 1.5 billio bytes per secod. Probably correct to withi multiplicative factor of 8 Certaily correct to withi multiplicative factor of 100 Those 13 bytes would execute iside the computer, the, i 13/1,500,000,000 th of a secod!

Applicatios are typically compiled Applicatios like Adobe Photoshop ad Microsoft Word are compiled. This meas that they execute i the computer as pure machie laguage. They execute at that level speed. However, Pytho, Java*, JavaScript, PHP, R, ad may other laguages are (i may cases) iterpreted. They execute at a slower speed. Why? It s the differece betwee traslatig istructios ad directly executig istructios. *Java techically itermediate case (complied to bytecode)

Why do we write programs? Oe reaso we write programs is to be able to do the same thig over-ad-over agai, without havig to rehash the same steps at the Pytho commad lie i the iterpreter widow each time

Applicatios are compiled Applicatios like Photoshop ad Word are writte i laguages like C or C++ These laguages are the compiled dow to machie laguage. That stuff that executes at a rate of 1.5 billio bytes per secod. Pytho programs are iterpreted.

High-level laguages must be traslated to machie laguage High-level laguage meas ay computer laguage except assembly laguage ad machie laguage All higher-level laguages must be traslated to machie laguage before they ca be executed. Two kids of traslators from source to target: Compiler: C, C++, FORTRAN Iterpreter: Pytho, JavaScript, PHP, Flash, PDF, Java*

Iterpreter idea (Usig Pytho to illustrate) Traslates Pytho code to machie laguage 1 lie at a time ad executes it Pytho Code Iterpreter prit ("Hello, World!") Probably i file hello.py somewhere For us, lower-right cosole widow of Spyder; could also use termial widow

Compiler idea (Usig C++ to illustrate) C++ Code #iclude <iostream> it mai() { cout << "Hello, World!"; } Compiler Machie Laguage a.out file This is a app you ca ru from, e.g., a termial widow.

Which is faster for same program & iputs? A. Ruig Pytho program B. Startig with C++ source code, traslatig it usig a C++ compiler, ad the ruig that program C. Not eough iformatio; it might be close betwee them D. No Clue

Which is faster for same program & iputs? A. Ruig Pytho program B. Startig with the result of compilig C++ source code, ad the ruig that compiled executable C. Not eough iformatio; it might be close betwee them D. No Clue

Java programs typically do t compile to machie laguage. Recall that every processor has its ow machie laguage. How, the, ca you create a program that rus o ay computer? The people who iveted Java also iveted a make-believe processor a virtual machie. It does t exist aywhere. Java compiles to ru o the virtual machie The Java Virtual Machie (JVM) The laguage it compiles to is called Java Bytecode

What good is it to ru oly o a computer that does t exist?!? Machie laguage is a very simple laguage. A program that iterprets the machie laguage of some computer is ot hard to write. def VMiterpret(program): for istructio i program: if istructio == 1: #It's a load... if istructio == 2: #It's a add...

Java rus o everythig Everythig that has a JVM o it! Each computer that ca execute Java has a iterpreter for the Java machie laguage, Java bytecode Iterpretig Java bytecode is pretty easy Takes oly a small fast program Devices as small as wristwatches ca ru Java VM iterpreters. Itermediate betwee compiled ad iterpreted laguage, with some of the beefits of both

Is it ay woder that Pytho programs ca be slower? Photoshop ad Word simply execute At 1.5 Ghz ad faster! Pytho programs iterpreted So for flat-out speed, people do't use Pytho But: 1. Some of the Java itermediate represetatio trick ideas have bee adopted by other laguages, icludig Pytho, so 2017 Pytho lots faster tha 2005 Pytho 2. Not so may thigs eed flat out speed today

Which is least likely to be developed i Pytho? A. Google puttig up results page for a Google search B. Large data sciece applicatio, like studyig Chicago crime rates by locatio, icome, educatio C. Graphics-itese multi-player computer game D. Large computatioal biology applicatios E. Automatig the testig of large pieces of software for errors

Why iterpret? For us, to have iterpreter area o RHS of Spyder Compiled laguages do t typically have a commad area where you ca prit thigs ad try out fuctios. Iterpreted laguages help the learer figure out what s goig o. Same advatage for scietist data user ad data scietist Aswer developers first; software developers secod ("ru oce") For others, to maitai portability. Java ca be compiled to machie laguage. I fact, some VMs will actually compile the virtual machie laguage for you while ruig o special compilatio eeded. But oce you do that, the result ca oly ru o oe kid of computer. Programs for Java (.jar files typically) ca be moved from ay kid of computer to ay other kid of computer ad just work.

Why else iterpret? Iterpreted laguages are usually more flexible, optimizig programmer time, ot ruig time. With great speedups i computers (Moore s) law, iterpreted laguages ted to be fast eough for most thigs today Hot laguages 1997 2007 maily iterpreted: Java*, Pytho, Perl, Flash Ad of those, Pytho ad Java still hot today ad (iterpreted) JavaScript ad R more importat today tha the

THERE ARE WORSE THINGS THAN BEING A LITTLE SLOWER THAN THE BEST

Iterpreted vs. compiled is't so bad Is at worst a costat multiplicative factor Ad so may good optimizatio tricks for Pytho by 2017 that it's ot a big multiplicatio factor

The Travelig Salesma Problem Imagie that you re a sales perso, ad you re resposible for a buch of differet cliets. Let s say 30 To be efficiet, you wat to fid the shortest path that will let you visit each cliet exactly oce, ad ot more tha oce. Beig a smart graduate of CS 111, you decide to write a program to do it.

The Travelig Salesma Problem curretly ca t be solved The best kow algorithm that gives a optimal solutio for the Travelig Salesma Problem takes! steps (That s factorial) There are algorithms that are better that give close-to but ot guarateed-best paths For 30 cities, the umber of steps to be executed is 265,252,859,812,191,058,636,308,480,000,000 (30!) The Travelig Salesma Problem is real. For example, several maufacturig problems actually become this problem, e.g., movig a robot o a factory floor to process thigs i a optimal order.

Class P, Itractable, ad Class NP May problems (like sortig elemets) ca be solved with a polyomial # of steps, like 2 We call that Class P problems. Other problems, like optimizatio, have kow solutios but are so hard ad big that we kow that we just ca t solve them a reasoable amout of time for eve reasoable amouts of data. We call these itractable Still other problems, like Travelig Salesma Problem seem itractable, but maybe there s a solutio i Class P that we just have t foud yet. We call these class NP Does P=NP? BIG QUESTION! (Also $1 millio prize)

The there are impossible problems There are some problems that are provably impossible. We kow that o algorithm ca ever be writte to solve this problem. The most famous of these is the Haltig Problem Which is, essetially, to write a program to completely uderstad ad debug aother program.

The Haltig Problem We could have writte programs that could read aother program (ope a file!). Spyder is i the ed just a program Ca we write a program that will iput aother program (say, from a file) ad tell us if the program will ever stop or ot? Thik about while loops with some complex expressio will the expressio ever be false? Now thik about ested while loops, all complex It s bee prove that such a program ca ever be writte.

Ala Turig Brilliat mathematicia ad computer scietist. Came up with mathematical defiitio of what a computer could do before oe was eve built! The Turig machie was iveted i aswer to the uestio of what the limits of mathematics were: What is computable by a fuctio? Proved that haltig problem had o solutio i 1936 almost 10 years before first computers were built.

Proof No program for Haltig Pr Imagie that there IS a program to check if a iput program halts or rus forever def doesithalt(prog, iput): We do t have its code; we re just assumig it exists, takes two iputs, returs True or False Will derive cotradictio/paradox

Gettig the Paradox def trouble(fuctio): if doesithalt(fuctio, fuctio): while (True): #I.e., ALWAYS! x = 1 else: retur #What does trouble(text-of-trouble) do?????

Ca we write a program that thiks? Are huma beigs doig (mere?) computatio? Ca huma itelligece be captured i a algorithm? Yes, we ca create ad uderstad programs, but some of our programs write programs too. Is it Class P? Class NP? Itractable? Are humas just computers i flesh? These are uestios that artificial itelligece researchers ad philosophers study today.