Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.

Slides:



Advertisements
Similar presentations
compilers and interpreters
Advertisements

Announcements You survived midterm 2! No Class / No Office hours Friday.
MATH 224 – Discrete Mathematics
Dr. Ken Hoganson, © August 2014 Programming in R COURSE NOTES 2 Hoganson Language Translation.
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.
Programming and Data Structure
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture3: Algorithm Analysis Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
COS 312 DAY 16 Tony Gauvin. Ch 1 -2 Agenda Questions? Next progress report is March 26 Assignment 4 Corrected – 3 A’s, 1 C, 1 D, 1 F and 1 MIA Assignment.
Chapter 11 Analysis of Algorithms. Chapter Scope Efficiency goals The concept of algorithm analysis Big-Oh notation The concept of asymptotic complexity.
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Algorithm Analysis (Big O) CS-341 Dick Steflik. Complexity In examining algorithm efficiency we must understand the idea of complexity –Space complexity.
Introduction to Analysis of Algorithms
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Simple Sorting Algorithms. 2 Bubble sort Compare each element (except the last one) with its neighbor to the right If they are out of order, swap them.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
© Janice Regan, CMPT 128, Feb CMPT 128: Introduction to Computing Science for Engineering Students Running Time Big O Notation.
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Georgia Institute of Technology Student Computer Simulation Barbara Ericson Georgia Tech Sept 2005.
Georgia Institute of Technology Speed part 3 Barb Ericson Georgia Institute of Technology May 2006.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Analysis of Algorithms Chapter 11 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013.
COMP 232 Intro Lecture. Introduction to Course Me – Dr. John Sigle Purpose/goals of the course Purpose/goals Prerequisites - COMP 132 (Java skill & Eclipse)
COS 312 DAY 16 Tony Gauvin. Ch 1 -2 Agenda Questions? Next Capstone progress report is March 26 Assignment 4 Corrected – 3 A’s, 1 C, 1 D, 1 F and 1 MIA.
Recursion, Complexity, and Sorting By Andrew Zeng.
Analysis of Algorithms
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Objectives - 11  We will work with processing Arrays.  Objectives:  Describe the concept of an array and its benefits.  Define the terms index, traverse,
Complexity of Algorithms
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Georgia Institute of Technology Manipulating Pictures, Arrays, and Loops Barb Ericson Georgia Institute of Technology August 2005.
Georgia Institute of Technology Movies Barb Ericson Georgia Institute of Technology April 2006.
Georgia Institute of Technology Speed part 6 Barb Ericson Georgia Institute of Technology May 2006.
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
Algorithm Analysis (Big O)
Georgia Institute of Technology Speed part 1 Barb Ericson Georgia Institute of Technology May 2006.
Searching Topics Sequential Search Binary Search.
04-ManipulatingPictures-part21 Manipulating Pictures, Arrays, and Loops part 2 Barb Ericson Georgia Institute of Technology June 2008.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
LECTURE 22: BIG-OH COMPLEXITY CSC 212 – Data Structures.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
What Do Computers Do? A computer system is
14 Compilers, Interpreters and Debuggers
Introduction to Analysis of Algorithms
Manipulating Pictures, Arrays, and Loops part 3
Algorithm Analysis CSE 2011 Winter September 2018.
Manipulating Pictures, Arrays, and Loops part 2
Chapter 12: Analysis of Algorithms
Introduction to Java, and DrJava part 1
Chapter 2 Analysis of Algorithms
Big O Notation.
Manipulating Pictures, Arrays, and Loops part 3
Variables variable: A piece of the computer's memory that is given a name and type, and can store a value. Like preset stations on a car stereo, or cell.
Variables variable: A piece of the computer's memory that is given a name and type, and can store a value. Like preset stations on a car stereo, or cell.
Manipulating Pictures, Arrays, and Loops
Introduction to Java, and DrJava
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Introduction to Java, and DrJava
Analysis of Algorithms
Introduction to Java, and DrJava part 1
Dasar-Dasar Pemrograman 2: Java Basics
Presentation transcript:

Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006

Georgia Institute of Technology Learning Goals Computing Concepts –Understand what happens when Java is compiled and executed –Explain the advantages of using a virtual machine –Explain that some speed difference is due to the algorithm used to solve a problem –Explain ways to compare algorithms Space Time

Georgia Institute of Technology Java Java was created to be interpreted –When you compile Java code you create byte codes for a virtual machine One that doesn't necessarily exist –When you run a main method in a class You are starting a Java Virtual Machine which interprets the virtual machine byte codes –The goal is to write once in Java and run on any machine Without recompiling Today, Java uses just-in-time compiling –As the JVM runs it compiles the code to machine lang

Georgia Institute of Technology A virtual machine that doesn't exist? Machine language is a very simple language. A program that interprets the machine language of some computer is not hard to write. def VMinterpret(program): for instruction in program: if instruction == 1: #It's a load... if instruction == 2: #It's an add...

Georgia Institute of Technology Why use a Virtual Machine? Can use the same code on many machines and devices –From cell phones to appliances to large computers Not locked into a processor type –If you write code for a cell phone and the manufactures changes the processor You don't have to change or recompile the code Can make the code safer –Less apt to cause problems on the machine it is running on Like stop an out of bounds access of an array

Georgia Institute of Technology How fast can we go? Photoshop and Word are faster –In part because they are compiled to machine language –But, also because of the design of the algorithms they use Many different algorithms can be used to solve a problem Some algorithms take longer to execute than others Some algorithms won't finish executing in your lifetime Some can't even be written!

Georgia Institute of Technology What is an algorithm? A description of the steps to take in solving a problem Many programs in different languages can implement the same algorithm There is always more than one algorithm to solve any problem Some computer scientist study algorithms –And compare them –And try to come up with better ones

Georgia Institute of Technology Programs implement Algorithms We have seen several programs that implement the same algorithm –We scaled a picture and a sound down by skipping every other value –We blended two pictures and two sounds together –We mirrored pictures and sounds

Georgia Institute of Technology Comparing Algorithms How do we decide which algorithm is better? –We can compare the amount of space each takes What if an algorithm required us to keep every frame of a movie in memory at the same time? –We can compare the amount of time each takes Not really execution time, but the magnitude of the number of steps (Big-Oh (O())

Georgia Institute of Technology How Many Steps? We count each declaration, assignment, and math expression as 1 step We count the number of times a loop executes –But the body of the loop as just 1 step For nested loops we multiply –the number of times the inner loop executes –by the number of times the outer loop executes

Georgia Institute of Technology How Many Steps? What is the output from this code? int count = 0; for (int x = 0; x < 5; x++) { for (int y = 0; y < 3; y++) { count++; System.out.println("Ran " + count + " times with x=" + x + " and y=" + y); }

Georgia Institute of Technology Exercise How many times will the following code print out the message? String message = "I will be good"; for (int i = 1; i <= 5; i++) { for (int j = 10; j > 0; j--) { System.out.println(message ) ; }

Georgia Institute of Technology Big-Oh Notation Really how much slower does the program get as the amount of data gets really big? –If we have 2x the amount of data An O(n) algorithm will take twice as long An O(n 2 ) algorithm will take four times as long How do we determine the Big-Oh for an algorithm? –Roughly the biggest factor in an expression of the number of steps

Georgia Institute of Technology Big-Oh for Picture Programs Any of the programs that processed all of the pixels of a picture is said to be O(n) where n is the number of pixels –If we have twice as many pixels it would take twice as long to run Any of the programs that processed all of the sound values in a sound is O(n) where n is the number of sound values –If we have twice as many sound values it would take twice as long to run

Georgia Institute of Technology Sorting Algorithms Sort data into alphabetical or numerical order –Bubble sort or insertion sort are O(n 2 ) Sorting 100 elements can take 10,000 steps –Quicksort is O(nlogn) Sorting 100 elements can take 460 steps This kind of difference is important for businesses –Create an index for a catalog of 100 elements

Georgia Institute of Technology Exercise Lookup how to do a bubble sort and write a method to sort an array of student names using bubble sort Lookup how to do insertion sort and write a method to sort an array of student names using insertion sort Lookup how to do quicksort and write a method to sort an array of student names using quicksort

Georgia Institute of Technology Summary Java programs compile to byte codes for a virtual machine –One that doesn't necessarily exist Virtual machines can be useful –Code doesn't depend on the processor –Can do safety checks There are many different algorithms that can be used to solve a problem –Some are better than others We can compare two algorithms –To see how much slower they get as the size of the data increases