CS-2852 Data Structures Week 10, Class 1 Lab 8 notes Big-O revisited CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1.

Slides:



Advertisements
Similar presentations
Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Advertisements

Algorithm Analysis.
HST 952 Computing for Biomedical Scientists Lecture 10.
Binary TreesCS-2303, C-Term Binary Trees (and Big “O” notation) CS-2303 System Programming Concepts (Slides include materials from The C Programming.
Review. What to know You are responsible for all material covered in lecture, the readings, or the programming assignments There will also be some questions.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Tyler Robison Summer
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Dan Grossman Spring 2010.
CSE 326 Asymptotic Analysis David Kaplan Dept of Computer Science & Engineering Autumn 2001.
Lists and Trees (continued) CS-2301, B-Term Lists and Trees (continued) CS-2301, System Programming for Non-Majors (Slides include materials from.
CS 307 Fundamentals of Computer Science 1 Asymptotic Analysis of Algorithms (how to evaluate your programming power tools) based on presentation material.
CS 206 Introduction to Computer Science II 10 / 14 / 2009 Instructor: Michael Eckmann.
 Last lesson  Arrays for implementing collection classes  Performance analysis (review)  Today  Performance analysis  Logarithm.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithm.
CS Discrete Mathematical Structures Mehdi Ghayoumi MSB rm 132 Ofc hr: Thur, 9:30-11:30a.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Abstract Data Types (ADTs) Data Structures The Java Collections API
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
Searching – Linear and Binary Searches. Comparing Algorithms Should we use Program 1 or Program 2? Is Program 1 “fast”? “Fast enough”? P1P2.
CSCI 2670 Introduction to Theory of Computing November 10, 2005.
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
CS2852 Week 8, Class 2 Today Tree terminology Non-Binary and Non-Search Trees Tree Traversals (Remaining slides not yet shown) Tomorrow: Quiz Implementing.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
Analysis of Algorithms
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
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.
SortingBigOh ASFA AP Computer Science A. Big-O refers to the order of an algorithm runtime growth in relation to the number of items I. O(l) - constant.
CS-2852 Data Structures Week 5, Class 1 – Testing and Stacks Return Exams & Labs  Package-level access  UML connectors for instance variables Announcement:
CS-2852 Data Structures Week 5, Class 2 – Testing and Stacks Announcement: Lab Demos - 2/3 & 4 on Friday Testing  Definitions, Example  (tentative) Testing.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
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.
CS-2852 Data Structures Week 10, Class 3 Final Announcement re. Final Choosing a Data Structure (Concluded) Poll Everywhere Survey & Results Conclusion.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
CompSci 100E 15.1 What is a Binary Search?  Magic!  Has been used a the basis for “magical” tricks  Find telephone number ( without computer ) in seconds.
ANALYSING COSTS COMP 103. RECAP  ArrayList: add(), ensuring capacity, iterator for ArrayList TODAY  Analysing Costs 2 RECAP-TODAY.
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:
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
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.
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
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.
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)
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.
CPS 100e 5.1 Inheritance and Interfaces l Inheritance models an "is-a" relationship  A dog is a mammal, an ArrayList is a List, a square is a shape, …
Amortized Analysis and Heaps Intro David Kauchak cs302 Spring 2013.
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.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Winter 2015.
Introduction to Analysing Costs 2013-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
Week 15 – Monday.  What did we talk about last time?  Tries.
CS-2852 Data Structures Week 5, Class 3 – Testing and Recursion Queue Implementing finite queues Binary Search Recursion Tomorrow – Quiz, Lab demos, Lab.
Sorting and "Big Oh" ASFA AP Computer Science A SortingBigOh.
Slide style: Dr. Hornick
Searching – Linear and Binary Searches
Midterm Review.
Algorithm Analysis The case of recursion.
Week 15 – Monday CS221.
Data Structures and Database Applications Abstract Data Types
Building Java Programs
Building Java Programs
SE-1021 Software Engineering II
CS-2852 Data Structures Week 1, Class 1 Data Structures Syllabus
Presentation transcript:

CS-2852 Data Structures Week 10, Class 1 Lab 8 notes Big-O revisited CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1

Running time CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick Content: Dr. Hasker 2 f(n)f(50)f(100)f(100)/f(50) 1111 log 2 n n n2n ,0004 n3n3 12,500100,0008 2n2n 1e151e301e15 n!3e649e1573e93

Big-O Motivation Want to ignore minor details Focus on what really makes the difference as n grows Each function on the previous slide is in a class of its own Want to find that class Multiplication by scalar doesn’t matter Addition of lower-order operations doesn’t matter CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 3

Big-O Definition T(n) = O(f(n) if and only if There exist n 0 and c such that T(n) ≤ cf(n) for all n > n 0 CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 4

Simplifying Big-O expressions Addition O(1) < O(log n) < O(n k ) < O(k n ) < O(n!) e.g. O(n k +n!) = O(n!) e.g. O(log n + n 2 ) = O(n 2 ) e.g. O(n log n + n 2 ) = O(n 2 ) e.g. O(n log n + n) = O(n log n CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 5

Simplifying Big-O expresions Multiplication by scalar O(kf(n)) = O(f(n)) for any fixed k e.g. O(5) = O(1) e.g. O(2 log 2 n + 5) = O(log n) CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 6

Strategies for determining Big-O Analysis of Code Intuition based on Structure of data Analysis of Code CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 7

Big-O based on analysis of Code public void f() { if(isG()) { h(); x++; } else { for(int i=0;i<j();i++) { k(); for(A a: list) { m(); } } // end of f max – sequence of simple expressions max – different if clauses prod – number of iterations over loop * contents of loop subs – method calls CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 8

Big-O based analysis of a Recursive algorithm Each recursive call should be O(1) except for method calls No loops So order is number of recursive calls needed Number of recursive calls can be exponential e.g. simple implementation of Fibbonaci Often, number of recursive calls is O(n) or even O(log n) CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 9

Example Suppose binary search of an array is implemented recursively. What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 10

Example Suppose binary search of a Red-Black tree is implement recursively. What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 11

Example Suppose binary search of a simple BinarySearchTree is implemented recursively. What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 12

Example Suppose binary search of a simple BinarySearchTree is implemented iteratively (with a loop). What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 13

Example Suppose we insert n items into an ArrayList using add(E). What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 14

Example Suppose we insert n items into an ArrayList using add(0, E). What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 15

Example Suppose we insert n items into a LinkedList using add(0, E). What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 16

Example Suppose we insert n items into a LinkedList using add(E). What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 17

Example Suppose we insert just 1 item into a LinkedList using add(n/2, e). What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 18

Example Suppose we insert one item into an empty hash-table. What is the Big(O) running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 19

Example Suppose we insert n items into an empty hash-table, and then remove them What is the Big(O) running time? Assume: No collisions occur CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 20

Example Suppose we insert n items into an empty hash-table, and then remove them What is the Big(O) running time? Assume: Collisions always occur CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 21

Example Suppose we insert an item into a properly- implemented stack. What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 22

Example Suppose we remove an item from a properly- implemented circular queue (the wrap-around array implementation) What is the Big-O running time? CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 23

Example What is the Big-O running time of the word search lab? (in terms of the size of the grid) CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 24

CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 25