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)

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

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.
Lec 5 Feb 10 Goals: analysis of algorithms (continued) O notation summation formulas maximum subsequence sum problem (Chapter 2) three algorithms image.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
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.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
David Luebke 1 8/17/2015 CS 332: Algorithms Asymptotic Performance.
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing.
Introduction to Analysing Costs 2015-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
Week 2 CS 361: Advanced Data Structures and Algorithms
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
Data Structures and Algorithms Lecture 5 and 6 Instructor: Quratulain Date: 15 th and 18 th September, 2009 Faculty of Computer Science, IBA.
Mathematics Review and Asymptotic Notation
Week 2 - Monday.  What did we talk about last time?  Exceptions  Threads  OOP  Interfaces.
Chapter 19: Searching and Sorting Algorithms
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.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
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.
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.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
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.
Chapter 7 Analysis of Algorithms © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
David Luebke 1 1/6/2016 CS 332: Algorithms Asymptotic Performance.
Asymptotic Performance. Review: Asymptotic Performance Asymptotic performance: How does algorithm behave as the problem size gets very large? Running.
ANALYSING COSTS COMP 103. RECAP  ArrayList: add(), ensuring capacity, iterator for ArrayList TODAY  Analysing Costs 2 RECAP-TODAY.
CS2910 Week 2, Class 1 Today Return Lab 1 Muddiest Points Quiz Parsing Data in Python SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors:
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.
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.
CS-2852 Data Structures Week 10, Class 2 Announcement re. Final Choosing a Data Structure CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1.
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)
Week 7, Class 1: The Command Pattern (cont.) Get Ready for Poll Everywhere Labs 2 & 3 returned Lab 7 due this evening at 11pm Quiz tomorrow at start of.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington2012 Analysing Costs COMP 103.
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.
CS-2852 Data Structures Week 4, Class 1 - Review Review! Thursday Exam I - Review Implementing ArrayList Big-O Iterators – High-level description Linked.
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.
CS2910 Week 6, Lab Today Dictionaries in Python SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1.
Introduction to Analysing Costs 2013-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
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.
Slide style: Dr. Hornick
GC 211:Data Structures Week 2: Algorithm Analysis Tools
CSC 413/513: Intro to Algorithms
CS 201 Fundamental Structures of Computer Science
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
CS-2852 Data Structures Week 1, Class 1 Data Structures Syllabus
Slide design: Dr. Mark L. Hornick
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder
Estimating Algorithm Performance
Presentation transcript:

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) Connect the Dots Generator Main instructions now posted SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1

The purpose of data-structures is speed The purpose of Big-O is to compare speed Why Big-O? (Review) 2 What is Big-O? In Big-O analysis, we only care about how runtime changes as the input size grows For example, we can predict… 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

Actual Runtimes, in nanosecs, averaged over 100,000 2 iters Nothing:4.737E-7 Empty loop:0.379 Integer addition:3.95E-8 Nothing:0.0 Two integer additions:0.0 Integer subtraction:3.95E-8 Multiply:0.0 Integer addition:0.0 Integer addition (use result): read array[0]: read array[500_000]: read array[999_999]: read array[500_000]: 3.95E-8 Nothing:0.0 One clock: 1/2.6Ghz One clock: 0.26 ns SE-2811 Dr.Yoder 3

Let’s assume… (Review) 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.) 0 ns for the ending }’s and blank lines We are ignoring many real details that influence run-time. SE-2811 Dr.Yoder 4

Big-O Simplification (Review) 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? 5

Big-O Notation & Simplification 6 Symbols T(n) – Actual worst-case run time f(n) – Simplified run-time O(n) – Symbolizes simplification process

Asymptotic Analysis: Analysis Techniques Determining complexity Assign arbitrary time to each line, count number of times line is called Use known complexity of called methods Multiply contents of loop by loop count Take max. of branches for if Result is often a polynomial Keep highest term, drop the rest Drop “weight” (or “scaling factor”) of largest term Higher order term, higher complexity 7

Exercise Consider two programs with running times in milliseconds T(n) = 50n + n 2 Q(n) = 100n Select which program is faster when n = 10 Select which program is faster when n = 1000 SE-2811 Dr.Yoder 8

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 9

Linked Lists array or ArrayList Items are stored next to each other in memory (ditto) Find item location by adding index Inserting takes a while – have to shift everything over LinkedList Items can be stored in any order Items are connected by references Find item by following references Inserting is simple – just change some references. SE-2811 Dr.Yoder 10

Exercise Draw in what the linked list will look like after inserting an element at index 0. (Edit the next slide) SE-2811 Dr. Yoder 11

SE-2811 Dr.Yoder 12

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

SE-2811 Dr. Josiah Yoder 14

SE-2811 Dr. Josiah Yoder 15