Big Oh CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University of Wisconsin.

Slides:



Advertisements
Similar presentations
Analysis of algorithms and BIG-O
Advertisements

MATH 224 – Discrete Mathematics
Sorted list matching & Experimental run-Time COP 3502.
1 Chapter 4 Analysis Tools. 2 Which is faster – selection sort or insertion sort? Potential method for evaluation: Implement each as a method and then.
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
Analysis of Algorithms intro.  What is “goodness”?  How to measure efficiency? ◦ Profiling, Big-Oh  Big-Oh: ◦ Motivation ◦ Informal examples ◦ Informal.
© 2004 Goodrich, Tamassia 1 Lecture 01 Algorithm Analysis Topics Basic concepts Theoretical Analysis Concept of big-oh Choose lower order algorithms Relatives.
Introduction to Analysis of Algorithms
Analysis of Algorithms Algorithm Input Output. Analysis of Algorithms2 Outline and Reading Running time (§1.1) Pseudo-code (§1.1) Counting primitive operations.
Analysis of Algorithms1 CS5302 Data Structures and Algorithms Lecturer: Lusheng Wang Office: Y6416 Phone:
Analysis of Algorithms (Chapter 4)
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Analysis of Algorithms
Analysis of Algorithms (pt 2) (Chapter 4) COMP53 Oct 3, 2007.
Fall 2006CSC311: Data Structures1 Chapter 4 Analysis Tools Objectives –Experiment analysis of algorithms and limitations –Theoretical Analysis of algorithms.
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
Analysis of Algorithms1 CS5302 Data Structures and Algorithms Lecturer: Lusheng Wang Office: Y6416 Phone:
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.
COMP s1 Computing 2 Complexity
Analysis of Performance
1 i206: Lecture 6: Math Review, Begin Analysis of Algorithms Marti Hearst Spring 2012.
CS2210 Data Structures and Algorithms Lecture 2:
Analysis of Algorithms Algorithm Input Output © 2014 Goodrich, Tamassia, Goldwasser1Analysis of Algorithms Presentation for use with the textbook Data.
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
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
Analysis Tools Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
Lecture 2 Computational Complexity
Analysis of Algorithms
Analysis of Algorithms1 The Goal of the Course Design “good” data structures and algorithms Data structure is a systematic way of organizing and accessing.
Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time. Chapter 4. Algorithm Analysis (complexity)
Data Structures Lecture 8 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Analysis of Algorithms1 Running Time Pseudo-Code Analysis of Algorithms Asymptotic Notation Asymptotic Analysis Mathematical facts.
Complexity of Algorithms
1 Dr. J. Michael Moore Data Structures and Algorithms CSCE 221 Adapted from slides provided with the textbook, Nancy Amato, and Scott Schaefer.
Searching CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
Analysis of Algorithms Algorithm Input Output An algorithm is a step-by-step procedure for solving a problem in a finite amount of time.
Analysis of Algorithms Algorithm Input Output © 2010 Goodrich, Tamassia1Analysis of Algorithms.
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
Merge Sort Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
Analysis of algorithms. What are we going to learn? Need to say that some algorithms are “better” than others Criteria for evaluation Structure of programs.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
1 Dr. Scott Schaefer Data Structures and Algorithms CSCE 221H.
Announcement We will have a 10 minutes Quiz on Feb. 4 at the end of the lecture. The quiz is about Big O notation. The weight of this quiz is 3% (please.
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.
1 COMP9024: Data Structures and Algorithms Week Two: Analysis of Algorithms Hui Wu Session 2, 2014
Analysis of Algorithms
Definition of Computer Science
COMP9024: Data Structures and Algorithms
COMP9024: Data Structures and Algorithms
Introduction to Algorithms
Big-O notation.
Analysis of Algorithms
COMP9024: Data Structures and Algorithms
Analysis of Algorithms
Analysis of Algorithms
CS 3343: Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
Data Structures and Algorithms CSCE 221H
Analysis of Algorithms
Analysis of Algorithms
Analysis of Algorithms
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
Analysis of Algorithms
Presentation transcript:

Big Oh CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University of Wisconsin – Stout 2014

Things to Note Homework 1 is Due – Before now (8 AM, Sep 18) – If you have not yet turned it in, do so now – Peer Review will be towards end of class Homework 2 is Posted on D2L – Do NOT delay in starting it

Notes on Homework Some comments on Homework 2 follow Offering clarification on interpretation of a couple questions – If these additions are not already in there

Linear Search vs. Binary Search ^ successfully performed

Running Time Comparisons log n here means “log Base 2 of n”

From Last Time – Software Engineering – Introduction to Big-Oh

For Today Algorithms Big-Oh

Marker Slide Any General Questions ? Next up – Algorithms – Big-Oh

Algorithm Introduction An algorithm is a set of instructions used to solve a specific problem. – A sequence of steps to solve the problem – A step by step set of instructions to solve the problem – Synonyms Process Method Procedure Routine Recipe Yeah, let’s cook something.

Properties of Algorithms Algorithm design focusses on – Input – Definition – Correctness – Result Specification – Termination

Pieces So far Algorithm design focusses on – Input – Definition – Correctness – Result Specification – Termination All these can be done in ‘consistent’ fashion for any algorithm Input Definition Correctness Specification Time

Pieces So far Algorithm design focusses on – Input – Definition – Correctness – Result Specification – Termination Input Definition Correctness Specification Time How long does it take the Algorithm to run to completion? Assume we only use/create algorithms that do indeed finish (i.e. no infinite loops) How do we answer this question?

Measuring Execution Time: 2 ways Physically Time the Implementation Wall-clock time Benchmarks Experimental Studies Theoretical Analysis – Asymptotic Analysis Use Math

Experimental Studies Write a program implementing the algorithm Run the program with inputs of varying size and composition Use a method like clock() to get an accurate measure of the actual running time Plot the results

Limitations of Experiments It is necessary to implement the algorithm, which may be difficult Results may not be indicative of the running time on other inputs not included in the experiment. In order to compare two algorithms, the same hardware and software environments must be used

Pieces So far Algorithm design focusses on – Input – Definition – Correctness – Result Specification – Termination Input Definition Correctness Specification Time How long does it take the Algorithm to run to completion? Assume we only use/create algorithms that do indeed finish (i.e. no infinite loops) So physically timing the execution has some issues Try option 2: Math

The Problem to Solve Algorithms take time to run. – We want to measure the time relative to data input size (i.e. n ) – Using a physical timer has lots of complications Does not allow for easy comparison of algorithms – Most interested in “worst case” time for those that may have drifted off

Measuring Running Time Running time of an algorithm grows with the input size Average case time is often difficult to determine We focus on the worst case running time – Crucial to applications such as games, finance and robotics – Easier to analyze Running Time 1ms 2ms 3ms 4ms 5ms Input Instance ABCDEFG worst case best case emphasis point

Bounding Functions Long ago in a galaxy called Calculus – Functions were bounded Not only could they be bound by constants But by other limiting functions It was a dark and mysterious place – Let’s go there =)

What We Want Assume: our algorithm can be characterized to run in f(n) time – where n = input size We want a function g(n) – that at some value of n = n0 – becomes greater than f(n) and stays greater – and it is okay if we have to multiply g(n) by some constant c to get this

O( mathFunction ) if we can find such a g(n) then we will say – our algorithm runs in – O( g(n) ) time More Formally: a function f(n) is O(g(n)) if f(n) is bounded above by some constant multiple of g(n) for all large n. So, f(n) ≤ cg(n) for all n > n o.

What do we get? Math: Asymptotic Analysis – Uses a high-level description of the algorithm instead of an implementation – Characterizes running time as a function of the input size, n. – Takes into account all possible inputs – Allows us to evaluate the speed of an algorithm independent of the hardware/software environment

Marker Slide Any Questions On: – Algorithms General Execution Time: Physically Timing Execution Time: Asymptotic Analysis: Big-Oh Next up – Big-Oh: Motivation Linear Search Binary Search

Motivation: Linear Search Say you have 1,000 action figures – You keep them in an unorganized (but very cool) looking pile on your otherwise unused bed A friend comes over and wants to see the super rare and totally awesome Boba Fett In the worst case how many action figures will you have to look at before you are guaranteed to have found the specified Boba Fett?

Motivation: Linear Search (cont) Worst case: 1000 If there were 10,000 action figures? – Worst case is 10,000 If there were 100,000? – Worst case is 100,000 So the input size (1000, 10000, ) is directly proportional to the worst case search time – This is described as O(n) for k = 1 to 1000 look at action figure number k stop if it is Boba Fett for k = 1 to 10,000 look at action figure number k stop if it is Boba Fett for k = 1 to 100,000 look at action figure number k stop if it is Boba Fett for k = 1 to n look at action figure number k stop if it is Boba Fett

Marker Slide Any Questions On: – Algorithms General Execution Time: Physically Timing Execution Time: Asymptotic Analysis: Big-Oh – Big-Oh: Motivation Linear Search Next up – Big-Oh: Motivation Binary Search

More Examples – More Motivation Why do we care how long an algorithm will take to run? – So we can Generalize Re-apply Improve Compare Determine if we are using the RIGHT TOOL for the job Consider Dictionaries…

Dictionaries – Motivation Why are dictionaries alphabetized? – [ pause for student participation ]

Dictionaries – Motivation Why are dictionaries alphabetized? – To speed up looking for things.

Dictionaries – Motivation Why are dictionaries alphabetized? – To speed up looking for things. Why does alphabetizing them help? – [ Yet Another Pause ] YAP…. YAP…. YAP

Dictionaries – Motivation Why are dictionaries alphabetized? – To speed up looking for things. Why does alphabetizing them help? – We can find things faster. – Using an Ordered List.

Dictionaries – Find Things Faster Using an ordered list helps us find things faster – How does that work? – [ YAP ] Describe processes of using dictionary

How to Use a Dictionary Keep cutting the search area in half Open dictionary to the middle – Then to ¼ or ¾ mark Then (1/8 or 3/8 mark) or (5/8 or 7/8) – Then … Find H appiness

Discovered: Binary Search By investigating dictionaries – We discovered an ordering allows us to perform a binary search more on that search method later For now we will claim a Binary Search is – O(log n) to be shown later

More Examples – More Motivation Why do we care how long an algorithm will take to run? Compare – Linear: O(n) – Binary: O(lg n) – Which is faster? Consider the graphs of each lg(n) 0 Binary Search is thus faster

Marker Slide Any Questions on: – Algorithms General Execution Time: Physically Timing Execution Time: Asymptotic Analysis: Big-Oh – Big-Oh: Motivation Linear Search Binary Search Next up – Peer Review of hw01

Graded: Peer Review Perform Peer Review on HW #1 Form into groups of 4 to 6 people – Give copy of your solution to person on your right Rightmost person circle around: give to leftmost person Locate PeerReviewSheet on D2L – Fill it out based on your evaluation of the code you have been given When done – Submit PeerReviewSheet to D2L Repeat once (so you do a total of 2 reviews)

The End Or is it?