Sorting, selecting and complexity

Slides:



Advertisements
Similar presentations
Growth-rate Functions
Advertisements

Efficiency of Algorithms Csci 107 Lecture 6-7. Topics –Data cleanup algorithms Copy-over, shuffle-left, converging pointers –Efficiency of data cleanup.
Sorting and Selection, Part 1 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.
Efficiency of Algorithms
CS 1114: Sorting and selection (part one) Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Algorithms and Efficiency of Algorithms February 4th.
Robustness and speed Prof. Noah Snavely CS1114
Data Structure Algorithm Analysis TA: Abbas Sarraf
Interpolation, extrapolation, etc. Prof. Ramin Zabih
1 Complexity Lecture Ref. Handout p
Week 2 CS 361: Advanced Data Structures and Algorithms
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
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.
10/14/ Algorithms1 Algorithms - Ch2 - Sorting.
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.
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.
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.
Clustering Prof. Ramin Zabih
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
ANALYSING COSTS COMP 103. RECAP  ArrayList: add(), ensuring capacity, iterator for ArrayList TODAY  Analysing Costs 2 RECAP-TODAY.
Searching Topics Sequential Search Binary Search.
1 Algorithms Searching and Sorting Algorithm Efficiency.
Introduction to Analysing Costs 2013-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
Implementing stacks Prof. Ramin Zabih
Algorithm Complexity is concerned about how fast or slow particular algorithm performs.
Sorting and "Big Oh" ASFA AP Computer Science A SortingBigOh.
Lightstick orientation; line fitting
Introduction to Analysis of Algorithms
May 17th – Comparison Sorts
Algorithmic Efficency
Scalability for Search
Introduction to Algorithms
Big-O notation.
Lesson Objectives Aims Understand the following: The big O notation.
Search Lesson Outline Searching Lesson Outline
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Catie Baker Spring 2015.
Introduction to Algorithms
Sorting by Tammy Bailey
David Kauchak CS52 – Spring 2015
Garbage collection; lightstick orientation
Algorithm Analysis CSE 2011 Winter September 2018.
Algorithm Analysis and Modeling
Searching CSCE 121 J. Michael Moore.
Efficiency (Chapter 2).
Sorting Algorithms Written by J.J. Shepherd.
Algorithm design and Analysis
Analysis of Bubble Sort and Loop Invariant
ITEC 2620M Introduction to Data Structures
Introduction to Algorithms Analysis
B- Trees D. Frey with apologies to Tom Anastasio
Big O Notation.
Data Structures Review Session
CS 201 Fundamental Structures of Computer Science
Analysys & Complexity of Algorithms
Quickselect Prof. Noah Snavely CS1114
Prof. Ramin Zabih Beyond binary search Prof. Ramin Zabih
B- Trees D. Frey with apologies to Tom Anastasio
Quicksort.
Data Structures Introduction
Quicksort.
Quicksort and selection
Searching and Sorting Hint at Asymptotic Complexity
Quicksort.
Sorting and selection Prof. Noah Snavely CS1114
Presentation transcript:

Sorting, selecting and complexity Prof. Ramin Zabih http://cs100r.cs.cornell.edu

Administrivia Assignment 1 is due tomorrow 5PM Lots of TA time available (check the web) Robot shortage will end soon…

Consider our algorithm Given an array of n numbers, find the number smaller than exactly m of them Strategy: Remove the biggest number Do this m times The answer is the biggest remaining number

Performance of our algorithm What is the worst case? m = n/2 a.k.a., finding the median! Suppose our input has n points Roughly how much work do we need to do, as a function of n, in the worst case? Examine n elements to find the biggest Examine n-1 elements to find the biggest … Do this n/2 times

How much work is this? No matter what computer we use, we have to do something n/2 times Namely, find the biggest element in an array The array is at least n/2 elements long Usually longer Can we find the biggest element without looking at all of them? The work grows as roughly n2 Suppose we add a new number to the array The extra work is proportional to how many numbers we already have

Classes of algorithm speed Constant time algorithms, O(1) Do not depend on the input Example: find the first element Linear time algorithms, O(n) Constant amount of work for every input item In the worst case, as always Example: find the largest element Quadratic time algorithms, O(n2) Linear amount of work for every input item Example: dumb trimming method

Asymptotic analysis picture If you plot n versus running time you get: A flat line for O(1) A sloped line for O(n) A parabola for O(n2) Different hardware only affects the parameters (i.e., line slope) As n gets big, the “dumber” algorithm by this measure always loses eventually

Limitations of this approach Obviously, the worst case doesn’t always happen in practice But this closely tracks real performance! It’s so good that the exceptions are famous It’s much harder to reason about the average case You need a definition of average that really matches your situation Average case analysis doesn’t track real performance nearly as well