Announcements You survived midterm 2! No Class / No Office hours Friday.

Slides:



Advertisements
Similar presentations
12-Apr-15 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
Advertisements

Chapter 14: Topics in Computer Science: Speed. Chapter Objectives.
Speed CS A109. Big speed differences Many of the techniques we’ve learned take no time at all in other applications Select a figure in Word. –It’s automatically.
Chapter 2 Machine Language.
Fundamentals of Python: From First Programs Through Data Structures
Analysis And Algorithms CMSC 201. Search Sometimes, we use the location of a piece of information in a list to store information. If I have the list [4,
Computer Memory GCSE Computing.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Introduction to Analysis of Algorithms
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
Analysis of Algorithms. Time and space To analyze an algorithm means: –developing a formula for predicting how fast an algorithm is, based on the size.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Cmpt-225 Algorithm Efficiency.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
Elementary Data Structures and Algorithms
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Search Lesson CS1313 Spring Search Lesson Outline 1.Searching Lesson Outline 2.How to Find a Value in an Array? 3.Linear Search 4.Linear Search.
The Study of Computer Science Chapter 0 Intro to Computer Science CS1510, Section 2.
Computing Hardware Starter.
Computer Hardware and Software Chapter 1. Overview Brief History of Computers Hardware of a Computer Binary and Hexadecimal Numbers Compiling vs. Interpreting.
Computing hardware CPU.
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Week 2 CS 361: Advanced Data Structures and Algorithms
Overview of Computing. Computer Science What is computer science? The systematic study of computing systems and computation. Contains theories for understanding.
The Study of Computer Science Chapter 0 Intro to Computer Science CS1510.
An Introduction to Computers August 12, 2008 Mrs. C. Furman.
Analysis of Algorithms
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
IT253: Computer Organization
Lecture 8 February 29, Topics Questions about Exercise 4, due Thursday? Object Based Programming (Chapter 8) –Basic Principles –Methods –Fields.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale.
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
Announcements: Project 5 Everything we have been learning thus far will enable us to solve interesting problems Project 5 will focus on applying the skills.
© GCSE Computing Computing Hardware Starter. Creating a spreadsheet to demonstrate the size of memory. 1 byte = 1 character or about 1 pixel of information.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
CSC 1010 Programming for All Lecture 1 Some material courtesy of Python for Informatics: Exploring Information (
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Week 12 - Friday.  What did we talk about last time?  Finished hunters and prey  Class variables  Constants  Class constants  Started Big Oh notation.
27-Jan-16 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
Georgia Institute of Technology Speed part 1 Barb Ericson Georgia Institute of Technology May 2006.
Searching Topics Sequential Search Binary Search.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Unit 1: Computing Fundamentals. Computer Tour-There are 7 major components inside a computer  Write down each major component as it is discussed.  Watch.
 A computer is an electronic device that receives data (input), processes data, stores data, and produces a result (output).  It performs only three.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Algorithm Analysis with Big Oh ©Rick Mercer. Two Searching Algorithms  Objectives  Analyze the efficiency of algorithms  Analyze two classic algorithms.
CSE 351 Caches. Before we start… A lot of people confused lea and mov on the midterm Totally understandable, but it’s important to make the distinction.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
Algorithm Complexity is concerned about how fast or slow particular algorithm performs.
The Study of Computer Science Chapter 0
Chapter 2.1 CPU.
Analysis of Algorithms
The Study of Computer Science Chapter 0
Introduction to Algorithms
Algorithm Analysis CSE 2011 Winter September 2018.
Computer Architecture
Teach A level Computing: Algorithms and Data Structures
The Study of Computer Science
Software Programming J. Holvikivi 2014.
A451: Computer Systems and Programming
Lesson 15: Processing Arrays
Big O Notation.
Asst. Dr.Surasak Mungsing
The Study of Computer Science
Analysis of Algorithms
Analysis of Algorithms
The Study of Computer Science Chapter 0
Analysis of Algorithms
Presentation transcript:

Announcements You survived midterm 2! No Class / No Office hours Friday

Its all about speed! … well usually, sometimes its about memory Portable devices, low power devices Today we will focus on: What makes computers fast/slow How to reason about algorithms We have seen many ways to do a particular task How do we choose which way we should write our program?

Big speed differences Many of the techniques we’ve learned take no time at all in other applications Select a figure in Word. It’s automatically inverted as fast as you can click. Color changes in Photoshop happen as you change the slider Increase or decrease red? Play with it and see it happen live.

What makes my program fast? Is it that Photoshop is so fast? Or that Python is so slow? It’s some of both—it’s not a simple problem with an obvious answer. We’ll consider two issues: How fast can computers get What’s not computable, no matter how fast you go

What a computer really understands Computers really do not understand Python, nor Java, nor any other language. The basic computer only understands one kind of language: machine language. Machine language consists of instructions to the computer expressed in terms of values in bytes. These instructions tell the computer to do very low-level activities.

Machine language trips the right switches The computer doesn’t really understand machine language. The computer is just a machine, with lots of switches that make data flow this way or that way. Machine language is just a bunch of switch settings that cause the computer to do a bunch of other switch settings. We interpret those switches to be addition, subtraction, loading, and storing. In the end, it’s all about encoding. A byte of switches

Assembler and machine language Machine language looks just like a bunch of numbers. Assembler language is a set of words that corresponds to the machine language. It’s often one-to-one relationship. A word of assembler equals one machine language instruction, typically. (Often, just a single byte.)

Assembler instructions Assembler instructions tell the computer to do things like: Store numbers into particular memory locations or into special locations (variables) in the computer. Test numbers for equality, greater-than, or less-than. Add numbers together, or subtract them.

An example assembly language program LOAD 10,R0; Load special variable R0 with 10 LOAD 12,R1; Load special variable R1 with 12 SUM R0,R1; Add R0 and R1, Put the result in R1 STOR R1,#45; Store the result into memory location #45 Recall that we talked about memory as a long series of boxes. Each one has a location (number) (like #45). The “special variables” are often called “registers”. That is why they begin with the letter “R”.

Assembler -> Machine LOAD 10,R0; Load special variable R0 with 10 LOAD 12,R1; Load special variable R1 with 12 SUM R0,R1; Add R0 and R1, Put the result in R1 STOR R1,#45; Store the result into memory location #45 Might appear in memory as just 12 bytes:

Machine language is executed very quickly Imagine a relatively slow computer today (not latest generation) having a clock rate of 1.5 Gigahertz. What that means exactly is hard to explain, but let’s interpret it as processing 1.5 billion bytes per second. Those 12 bytes would execute inside the computer, then, in 12/1,500,000,000 th of a second!

Other factors affect speed Processor Speed Cache located on the processor Memory speed (and size!) Hard Drive speed Operating System efficiency

Hard Drive Slowest form of storage Unlike RAM, Hard Drive storage is “permanent” It survives after you turn the power off

Storage relationships If you have too little RAM, your computer will store some things on hard disk. It will be slower to bring back into RAM for the computer to use it. The system bus describes how fast things can move around your computer. Network is even slower than the hard drive If you’re grabbing a web page from the network, onto the hard drive, and into RAM, the network speed will be the limiting factor.

How do we compare algorithms? There’s more than one way to search. How do we compare algorithms to say that one is faster than another? Computer scientists use something called Big-O notation It’s the order of magnitude of the algorithm Big-O notation tries to ignore differences between languages, even between compiled vs. interpreted, and focus on the number of steps to be executed.

What question are we trying to answer? If I am given a larger problem to solve (more data), how is the performance of the algorithm affected? If I change the input, how does the running time change?

We want to choose the algorithm with the best complexity We want an algorithm which will be fast A “lower” complexity mean an algorithm will perform better on large input

Finding something in the phone book O(n) algorithm Start from the beginning. Check each page, until you find what you want. Not very efficient Best case: One step Worse case: n steps where n = total entries in phone book Average case: n/2 steps

Implementing a Linear Search – slightly different def findInList(something, alist): status = False for item in alist: if (item == something): status = True return status

Running our Search Algorithm >>> print(findInList ("bear",["apple","bear","cat","dog","elephant"])) True >>> print(findInList ("giraffe",["apple","bear","cat","dog","elephant"])) False

Why is it linear? Step 1) What is the input to the algorithm? Well the function takes a list and an element we are looking for Step 2) How much work are we doing? We compare each element in the list to the element we are looking for Lets assume we can test equality in one “step” or one “unit of work”

Implementing a Linear Search def findInList(something, alist): status = False for item in alist:  how much work we perform if (item == something):  piece of work status = True return status

Implementing a Linear Search – slightly better def findInList(something, alist): for item in alist: if (item == something): return True return False

So why do we bother with linear search? Our data might not be ordered! Notice that our faster algorithms required our data to be ordered We say that ordered data is sorted Challenge question: Is it faster to linearly search through unordered data, or to sort it, and then use a binary search? We will answer this next week!

A better search in a sorted list O(log n) (log 2 n = x where 2 x =n) Split the phone book in the middle. Is the name you’re at before or after the page you’re looking at? If after, look from the middle to the end. If before, look from the start to the middle. Keep repeating until done More efficient: Best case: It’s the first place you look. Average and worst case: log n steps

Implementing a binary search def findInSortedList(something, alist ): start = 0 end = len(alist) – 1 status = False while start <= end: checkpoint = int(( start+end )/2.0) if alist[checkpoint ]== something: return True if alist[checkpoint]<something: start=checkpoint +1 if alist[checkpoint]>something: end=checkpoint -1 return status

print("Checking at: "+str(checkpoint )+" Start:"+str(start )+" End:"+str(end)) >>> findInSortedList("giraffe",["apple","bear","cat”,"dog"]) Checking at: 1 Start :0 End:3 Checking at: 2 Start :2 End:3 Checking at: 3 Start :3 End:3 False >>> findInSortedList("apple” ["apple","bear","cat”,"dog"]) Checking at: 1 Start :0 End:3 Checking at: 0 Start :0 End:0 True >>> findInSortedList("dog",["apple","bear","cat”,"dog"]) Checking at: 1 Start :0 End:3 Checking at: 2 Start :2 End:3 Checking at: 3 Start :3 End:3 True Running the binary search

Clicker Question Did you come to class today? A) yes B) no

Homework Read Chapter 9