Robustness and speed Prof. Noah Snavely CS1114

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

Order Statistics Sorted
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Sorting and Selection, Part 1 Prof. Noah Snavely CS1114
Polygons and the convex hull Prof. Noah Snavely CS1114
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Interpolation Prof. Noah Snavely CS1114
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.
CS107 Introduction to Computer Science
Analysis of Algorithms1 Estimate the running time Estimate the memory space required. Time and space depend on the input size.
Quicksort.
CS 1114: Sorting and selection (part one) Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
Complexity (Running Time)
Robustness and speed Prof. Noah Snavely CS1114
Blobs and Graphs Prof. Noah Snavely CS1114
Polygons and the convex hull Prof. Noah Snavely CS1114
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Data Structure Algorithm Analysis TA: Abbas Sarraf
Analysis of Algorithm.
Elementary Data Structures and Algorithms
Search Lesson CS1313 Spring Search Lesson Outline 1.Searching Lesson Outline 2.How to Find a Value in an Array? 3.Linear Search 4.Linear Search.
Robust fitting Prof. Noah Snavely CS1114
Analysis of Performance
1 Complexity Lecture Ref. Handout p
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Week 2 CS 361: Advanced Data Structures and Algorithms
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 2: Orders of Growth
1 Time Analysis Analyzing an algorithm = estimating the resources it requires. Time How long will it take to execute? Impossible to find exact value Depends.
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
Ch 18 – Big-O Notation: Sorting & Searching Efficiencies Our interest in the efficiency of an algorithm is based on solving problems of large size. If.
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.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
Week 12 - Wednesday.  What did we talk about last time?  Asymptotic notation.
Image segmentation Prof. Noah Snavely CS1114
Algorithm Analysis (Algorithm Complexity). Correctness is Not Enough It isn’t sufficient that our algorithms perform the required tasks. We want them.
Interpolation Prof. Noah Snavely CS1114
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
CSC 211 Data Structures Lecture 13
Medians and blobs Prof. Ramin Zabih
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
CS 2601 Runtime Analysis Big O, Θ, some simple sums. (see section 1.2 for motivation) Notes, examples and code adapted from Data Structures and Other Objects.
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
27-Jan-16 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
CS321 Data Structures Jan Lecture 2 Introduction.
Searching Topics Sequential Search Binary Search.
A Introduction to Computing II Lecture 5: Complexity of Algorithms Fall Session 2000.
CS 1114: Finding things Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Introduction to Algorithms. Algorithms Algorithms are ways of solving problems. There is a technical definition that basically says an algorithm is a.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Introduction to Analysis of Algorithms
Big-O notation.
Search Lesson Outline Searching Lesson Outline
Algorithm design and Analysis
CS 1114: Sorting and selection (part three)
So where is it anyway? Bounding box, median, centroids, and an introduction to algorithm analysis.
Quickselect Prof. Noah Snavely CS1114
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Sorting, selecting and complexity
CS 1114: Sorting and selection (part two)
Quicksort and selection
Sorting and selection Prof. Noah Snavely CS1114
Presentation transcript:

Robustness and speed Prof. Noah Snavely CS1114

2 Administrivia  Assignment 1 is due next Friday by 5pm –Lots of TA time available (check the web)  For grading, please get checked off by a TA, or sign up for a demo slot –These will be posted to CMS soon

Finding the lightstick center  Last time: two approaches  Both have problems… 3 Bounding boxCentroid

How can we do better?  What is the average weight of the people in this kindergarten class photo? kids, avg. weight= 40 lbs 1 Arnold, weight = 236 lbs Mean: (12 x ) / 13 = 55 lbs

How can we do better?  Idea: remove maximum value, compute average of the rest kids, avg. weight= 40 lbs 1 Arnold, weight = 236 lbs Mean: (12 x ) / 13 = 55 lbs Mean: 40lbs

6 5% Trimmed mean  Is it correct?  Is it fast?  Is it the fastest way? % A is a vector of length 100 for i = 1:5 % 1. Find the maximum element of A % 2. Remove it end

How do we define fast?  We want to think about this issue in a way that doesn’t depend on either: A. Getting really lucky input B. Happening to have really fast hardware 7

8 How fast is our algorithm?  An elegant answer exists  You will learn it in later CS courses –But I’m going to steal their thunder and explain the basic idea to you here –It’s called “big-O notation”  Two basic principles: –Think about the average / worst case Don’t depend on luck –Think in a hardware-independent way Don’t depend on Intel!

Simple example: finding the max function m = find_max(A) % Find the maximum element of an array A m = A(1); n = length(A); for i = 2:n if (A(i) > m) m = A(i); end  How much work is this? 9 how many times will this comparison be done?

Big-O Notation  Let’s call the length of the array n  The amount of work grows in proportion to n  We say that this algorithm runs in time O(n)  (Or that it is a linear-time algorithm) 10 function m = find_max(A) % Find the maximum element of an array A m = -1; for i = 1:length(A) if (A(i) > m) m = A(i); end

11 Another version of the trimmed mean  Given an array of n numbers, find the k th largest number in the array  Strategy: 1.Find the biggest number in the array 2.Remove it –Repeat k times –The answer is the last number you found

Performance of our algorithm  How many operations do we need to do, in terms of k and n? 12  Given an array of n numbers, find the k th largest number in the array  Strategy: 1.Find the biggest number in the array 2.Remove it –Repeat k times –The answer is the last number you found  Given an array of n numbers, find the k th largest number in the array  Strategy: 1.Find the biggest number in the array 2.Remove it –Repeat k times –The answer is the last number you found

13 Performance of our algorithm  How much work will we do? 1. Examine n elements to find the biggest 2. Examine n -1 elements to find the biggest … keep going … k. Examine n-(k-1) elements to find the biggest

14 Performance of our algorithm  What value of k is the worst case? –k = n –k = n/2  How much work will we do in the worst case? 1. Examine n elements to find the biggest 2. Examine n -1 elements to find the biggest … keep going … n/2. Examine n/2 elements to find the biggest we can easily fix this

15 How much work is this?  How many elements will we examine in total? n + (n – 1) + (n – 2) + … + n/2 = ?  We don’t really care about the exact answer –It’s bigger than (n / 2) 2 and smaller than n 2 n / 2 terms

 The amount of work grows in proportion to n 2  We say that this algorithm is O(n 2 ) 16 How much work in the worst case?

 The amount of work grows in proportion to n 2  We say that this algorithm is O(n 2 )  If it takes 10 seconds when n = 1,000, how long will it take when n = 2,000? A: 20 seconds B: 40 seconds 17 How much work is this?

18 Classes of algorithm speed  Constant time algorithms, O(1) –Do not depend on the input size –Example: find the first element  Linear time algorithms, O( n ) –Constant amount of work for every input item –Example: find the largest element  Quadratic time algorithms, O( n 2 ) –Linear amount of work for every input item –Example: slow median method

19 Asymptotic analysis picture  Different hardware only affects the parameters (i.e., line slope)  As n gets big, the “dumber” algorithm by this measure always loses eventually O(1) O(n)O(n) O(n2)O(n2)

20 Where we are so far  Finding the lightstick –Attempt 1: Bounding box (not so great) –Attempt 2: Centroid isn’t much better –Attempt 3: Trimmed mean Seems promising But how do we compute it quickly? The obvious way doesn’t seem so great…

Questions? 21