Robustness and speed Prof. Noah Snavely CS1114

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

The Efficiency of Algorithms
Intro to Analysis of Algorithms. Algorithm “A sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any.
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.
Chapter 3 Growth of Functions
CSC401 – Analysis of Algorithms Lecture Notes 1 Introduction
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.
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
Blobs and Graphs Prof. Noah Snavely CS1114
Polygons and the convex hull Prof. Noah Snavely CS1114
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.
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
Week 2 CS 361: Advanced Data Structures and Algorithms
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Analysis Tools Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
Order Statistics The ith order statistic in a set of n elements is the ith smallest element The minimum is thus the 1st order statistic The maximum is.
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.
Arrays Tonga Institute of Higher Education. Introduction An array is a data structure Definitions  Cell/Element – A box in which you can enter a piece.
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.
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.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Medians and blobs Prof. Ramin Zabih
Robustness and speed Prof. Noah Snavely CS1114
CMSC 341 Asymptotic Analysis. 2 Complexity How many resources will it take to solve a problem of a given size? –time –space Expressed as a function of.
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
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.
CS 232: Computer Architecture II Prof. Laxmikant (Sanjay) Kale.
M180: Data Structures & Algorithms in Java Algorithm Analysis Arab Open University 1.
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
Chapter 7 Analysis of Algorithms © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
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.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Growth of Functions & Algorithms
May 17th – Comparison Sorts
Big-O notation.
CS 1114: Sorting and selection (part three)
Big O Notation.
So where is it anyway? Bounding box, median, centroids, and an introduction to algorithm analysis.
Quickselect Prof. Noah Snavely CS1114
Sorting, selecting and complexity
CS 1114: Sorting and selection (part two)
Analysis of Algorithms
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 sign up for a demo slot –These will be posted to CMS soon

3 Administrivia  Please be careful with the robots –As you can tell, they are easy to break, cause smoke to come out of, etc. –Proper care and feeding manual coming soon…

What’s the difference between = and == ?  Answer: a lot  = : assignment x = 2;  == : test for equality if x == 2 y = 4; end ... very important not to get these mixed up 4

Finding the lightstick center  Last time: two approaches  Both have problems… 5 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 * ) / 11 = 55 lbs Mean: 40lbs

How can we do better? 8  Trade deficit by country

9 How can we avoid this problem?  Consider a simple variant of the mean called the “trimmed mean” –Simply ignore the largest 5% and the smallest 5% of the values –Q: How do we find the largest 5% of the values? D.E. Knuth, The Art of Computer Programming Chapter 5, pages 1 – 391

10 Easy to find the min (or max) A = [ ]; m = -1; for i = 1:length(A) if (A(i) > m) m = A(i); end % Alternatively: m = max(m,A(i)); end % Why -1?

 First, we need to know how many cells we’re dealing with –Let’s say there are 100  remove top 5  How do we remove the biggest 5 numbers from an array? 11 How to get top 5%?

% A is a vector of length 100 for i = 1:5 % Find the maximum element of A % and remove it end 12 Removing the top 5% -- Take 1

13 How good is this algorithm?  Is it correct?  Is it fast?  Is it the fastest way? % A is a vector of length 100 for i = 1:5 % Find the maximum element of A % and remove it end

How do we define fast?  It’s fast when length(A) = 20  We can make it faster by upgrading our machine  So why do we care how fast it is?  What if length(A) = 6,706,993,152 ? 14

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 15

16 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… But do we really know this?

17 How fast is this 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!

18 A more general version of trimmed mean  Given an array of n numbers, find the k th largest number in the array  Strategy: –Remove the biggest number –Do this k times –The answer is the last number you found

19 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

20 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 n / 2 terms

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

22 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: dumb median method

23 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)