CS2852 Week 2, Class 1 Today Generics (Section 051) Big-O runtime analysis Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See.

Slides:



Advertisements
Similar presentations
CS1104: Computer Organisation School of Computing National University of Singapore.
Advertisements

CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
Introduction to Analysis of Algorithms
Complexity Analysis (Part I)
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.
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Lecture 3 Aug 31, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis discussion of lab – permutation generation.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Elementary Data Structures and Algorithms
Lecture 3 Feb 7, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis Image representation Image processing.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
analysis, plug ‘n’ chug, & induction
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
David Luebke 1 8/17/2015 CS 332: Algorithms Asymptotic Performance.
COMP s1 Computing 2 Complexity
1 Complexity Lecture Ref. Handout p
CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing.
Chapter Complexity of Algorithms –Time Complexity –Understanding the complexity of Algorithms 1.
Week 2 CS 361: Advanced Data Structures and Algorithms
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
Week 2 - Monday.  What did we talk about last time?  Exceptions  Threads  OOP  Interfaces.
Algorithms and their Applications CS2004 ( ) Dr Stephen Swift 3.1 Mathematical Foundation.
SE-3910 Real-time Systems Week 5, Class 2 – Lab turn-in page is up! – Lost-and-not-found power supply – Quick-Quiz (Ungraded) – Use interrupts in a Linux/C.
DR. Gatot F. Hertono, MSc. Design and Analysis of ALGORITHM (Session 2)
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Algorithms & Flowchart
CS-2852 Data Structures Week 10, Class 1 Lab 8 notes Big-O revisited CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
Today Quiz Multithreading Options Qt socket buffers between threads Quiz today & Tuesday in lab SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
CS2910 Week 1, Class 2 Today Announce Prof. Michael Vieau’s S-341 6p Thurs Wk 2 Assignment for tomorrow Data Encoding, Part 1 Parsing Data Muddiest Point.
CS2910 Week 1, Class 1 Today Introductions Class/Lab Layout Safety Review - Note about Lab Safety Review Announce Prof. Michael Vieau’s S-341 6p Thurs.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Problem of the Day  I am thinking of a question and propose 3 possible answers. Exactly one of the following is the solution. Which is it? A. Answer 1.
CS2910 Week 2, Class 1 Today Data Encoding, Part 1 Parsing Data Python Muddiest Point Lab 2 – Bring text In Class, Thursday: Quiz Week 6, Monday: Midterm.
CSC – 332 Data Structures Generics Analysis of Algorithms Dr. Curry Guinn.
CS2852 Week 3, Class 2 Today Stacks Queues SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Today Nervous System Response Time SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 3, Class 2.
Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
Recap……Last Time [Variables, Data Types and Constants]
CS2852 Week 6, Class 1 Today The run-time stack Writing and proving recursive methods SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2852 Week 5, Class 2 Today Queue Applications Circular Queue Implementation Testing SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
CS2852 Week 7, Class 1 Today Binary Search Tree Implementing add Implementing find Return Quiz 4 (second attempt) Both sections are graded SE-2811 Slide.
Week 12 - Monday.  What did we talk about last time?  Defining classes  Class practice  Lab 11.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
CS2852 Week 6, Class 2 Today Class exercise: Implementing a recursive method Binary Search Trees Tomorrow: Quiz at start of lab Implementing a recursive.
Today Return Quiz First true release of final project (Lab 8) Multithreading Options Qt socket buffers between threads SE-2811 Slide design: Dr. Mark L.
Today Quiz not yet graded Final report requirements posted More on Multithreading Happens-Before in Java SE-2811 Slide design: Dr. Mark L. Hornick Content:
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
CS2852 Week 3, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
CS2852 Week 2, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
CS2910 Week 8, Class 2 Today Return Quiz Look at Schedule TCP implementation! Week 8, Monday Quiz on SMTP May include some questions requiring you to interpret.
CS2910 Week 7, Class 1 Today Capturing SMTP with Thunderbird Tomorrow Extra office hour at 11 am (right after lab) Friday Office hour cancelled SE-2811.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
CS-2852 Data Structures Week 4, Class 1 - Review Review! Thursday Exam I - Review Implementing ArrayList Big-O Iterators – High-level description Linked.
Week 9, Day 1 Proxy SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Winter 2015.
SE3910 Week 8, Class 2 Week 4 Lab: Please return your graded Lab 4 to me so I can enter it in my gradebook Week 7, Class 2 (Wednesday) Half-Exam 2 Done.
CS-2852 Data Structures Week 5, Class 3 – Testing and Recursion Queue Implementing finite queues Binary Search Recursion Tomorrow – Quiz, Lab demos, Lab.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
CS 201 Fundamental Structures of Computer Science
Slide design: Dr. Mark L. Hornick
CS-2852 Data Structures Week 1, Class 1 Data Structures Syllabus
Slide design: Dr. Mark L. Hornick
Estimating Algorithm Performance
Slide design: Dr. Mark L. Hornick
Presentation transcript:

CS2852 Week 2, Class 1 Today Generics (Section 051) Big-O runtime analysis Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide) Connect the Dots Generator Main instructions now posted SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1

Untested code is buggy code I believe you can raise your grade by about one letter grade if you… Write a few tests for every method in the ArrayList class Write at least seven different kinds of tests (see Section 021 boardshot) Fix all the bugs in our class implementation of ArrayList The quiz in Lab will include writing a method from the ArrayList class. CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 2

The main purpose of the compiler is… (Section 051) To generate errors Generics The main purpose of Generics is to generate compiler errors SE-2811 Dr.Yoder 3

Type Erasure (Section 051) The compiler knows about generics It treats a “generic” type as the real type Helps find errors The virtual machine does not To it, a “generic” type is just an “Object” SE-2811 Dr.Yoder 4

Type Erasure (Section 051) After checking that they are used correctly as much as it can, the compiler… “Replaces all type parameters in generic types with … Object. “Inserts type casts if necessary to preserve type safety. … rics/erasure.html SE-2811 Dr.Yoder 5

The purpose of data-structures is speed The purpose of Big-O is to compare speed Fact: Predicting the actual speed of an algorithm is challenging Big-O allows us to compare speed of algorithms without knowing the actual speed Reminder: An algorithm is more general than the implementation of a program Why Big-O? 6 What is Big-O?

In Big-O analysis, we only care about how runtime changes as the input size grows For example, once we’ve done the Big-O analysis, we can predict… 7 If the runtime is … O(n)O(n 2 )O(n 3 ) Then doubling the input size will multiply runtime by about … 248 Then tripling the input size will multiply runtime by about … 3927

How long do operations really take on my computer? Empty loop:0.51 Empty loop:0.95 Integer addition: 0.0 Integer subtract: 0.0 Multiply:0.0 Comparison:0.0 Remainder:0.34 Division:0.35 Float Add:0.0 Float subtract:1.3 Float Division:1.27 Float Multiply:1.26 Function call:0.0 Math.sin:116.5 Math.atan2:57.6 Math.random:25.7 Integer addition:0.0 SE-2811 Dr.Yoder 8 Nanoseconds per loop iteration (10,000 2 iters)

How long do operations really take on my computer? Empty loop: Empty loop: Integer addition: 0.0 Integer subtract: 0.0 Multiply:0.0 Comparison:0.0 Remainder: Division: Float Add:0.0 Float subtract: Float Division: Float Multiply: Function call:0.0 SE-2811 Dr.Yoder 9 Nanoseconds per loop iteration (100,000 2 iters)

How long do operations really take on my computer? Empty loop:0.36 Empty loop:0.33 Integer addition: 0.0 Integer subtract: 0.0 Multiply:0.0 Comparison:0.0 Remainder: Division: Float Add:0.0 Float subtract: [See TimePrimitives.java in notes, example from Princeton] SE-2811 Dr.Yoder 10 Nanoseconds per loop iteration (1,000,000 2 iters)

Let’s assume… Let’s assume the following costs: 1 ns for each line of code 1 ns for each time header condition is evaluated and we jump to a different place in the code for, while, if If we call a method, we need to figure out how long that method takes to run. For Math calls, we’ll assume 1 ns. (This is lower than real.) We are ignoring many real details that influence run-time. SE-2811 Dr.Yoder 11

Example: Estimate running time of add [See code, take notes…] SE-2811 Dr.Yoder 12

Example Find running time of contains if array = {“first”, “second”, “third”} o = “second” Assume the line with.equals takes 1ns if run. SE-2811 Dr.Yoder 13

Example Find running time of contains if Array contains n elements. o = last element in array [Take notes] SE-2811 Dr.Yoder 14

Example Suppose the run-time for our algorithm is T(n) = 5 + 3n Suppose n=1000 T(n) = = 3005 Does the 5 make a difference? Now suppose n doubles (to 2000) T(n) = = How much does the runtime multiply by? 6005/3005 ≈ 6000/3000 = 2 Does the 3 make a difference? 15

Definition of Big-O [Take notes] SE-2811 Dr.Yoder 16

Symbols T(n) – Actual worst-case run time f(n) – Simplified run-time O(n) – Symbolizes simplification process CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 17

Asymptotic Analysis: Analysis Techniques Assign unknown time to each time step Get polynomial Use Big-O Simplifications to eliminate uneeded terms and scaling factors Jump straight to the conclusion Just use “1” for each simple instruction Use known complexity of called methods Multiply contents of loop by loop count Take max. of branches for if CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 18

When comparing algorithms Pick the one with the lower complexity when You anticipate a significant amount of data at some point in the life of the code You can use a standard library with a low complexity You need to demonstrate you know the difference Pick the higher complexity when Your amount of data will be small throughout the life of the code The hidden cost (n o, c) are high If same – use other properties CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 19

Muddiest Point Wait for the slides, or follow this link to answer both questions at once: SE-2811 Dr.Yoder 20

SE-2811 Dr. Josiah Yoder 21

SE-2811 Dr. Josiah Yoder 22