20 - 1 Algorithm Analysis PS5 due 11:59pm Wednesday, April 18 Final Project Phase 2 (Program Outline) due 1:30pm Tuesday, April 24 Wellesley College CS230.

Slides:



Advertisements
Similar presentations
Computational Complexity 1. Time Complexity 2. Space Complexity.
Advertisements

Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved10-1 Chapter 10 Algorithm Efficiency and Sorting CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck.
CS 307 Fundamentals of Computer Science 1 Asymptotic Analysis of Algorithms (how to evaluate your programming power tools) based on presentation material.
Not all algorithms are created equally Insertion of words from a dictionary into a sorted list takes a very long time. Insertion of the same words into.
Chapter 2 Fundamentals of the Analysis of Algorithm Efficiency Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 More on Recursion.
Cmpt-225 Algorithm Efficiency.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
1 Algorithm Efficiency, Big O Notation, and Role of Data Structures/ADTs Algorithm Efficiency Big O Notation Role of Data Structures Abstract Data Types.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Algorithm Efficiency and Sorting Bina Ramamurthy CSE116A,B.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithm.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Design and Analysis of Algorithms Chapter Analysis of Algorithms Dr. Ying Lu August 28, 2012
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Abstract Data Types (ADTs) Data Structures The Java Collections API
COMPSCI 102 Introduction to Discrete Mathematics.
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Program Performance & Asymptotic Notations CSE, POSTECH.
Week 2 CS 361: Advanced Data Structures and Algorithms
Lecture 2 Computational Complexity
CSC 201 Analysis and Design of Algorithms Lecture 04: CSC 201 Analysis and Design of Algorithms Lecture 04: Time complexity analysis in form of Big-Oh.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 9: Algorithm Efficiency and Sorting Data Abstraction &
Merge Sort. What Is Sorting? To arrange a collection of items in some specified order. Numerical order Lexicographical order Input: sequence of numbers.
Analysis of Algorithm Efficiency Dr. Yingwu Zhu p5-11, p16-29, p43-53, p93-96.
Algorithm Efficiency Chapter 10 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Chapter 10 A Algorithm Efficiency. © 2004 Pearson Addison-Wesley. All rights reserved 10 A-2 Determining the Efficiency of Algorithms 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.
Growth of Functions. Asymptotic Analysis for Algorithms T(n) = the maximum number of steps taken by an algorithm for any input of size n (worst-case runtime)
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
1 Introduction to Data Structures. 2 Course Name : Data Structure (CSI 221) Course Teacher : Md. Zakir Hossain Lecturer, Dept. of Computer Science Stamford.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Binary Trees PS4 due 1:30pm Tuesday, April 10 Wellesley College CS230 Lecture 17 Thursday, April 5 Handout #28.
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
Algorithm Efficiency and Sorting Data Structure & Algorithm.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Sorting.
SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes.
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 01 / 30 / 2009 Instructor: Michael Eckmann.
Algorithm Analysis (Big O)
CS 150: Analysis of Algorithms. Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of algorithms.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
Lecture 4 Jianjun Hu Department of Computer Science and Engineerintg University of South Carolina CSCE350 Algorithms and Data Structure.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Concepts of Algorithms CSC-244 Unit 3 and 4 Algorithm Growth Rates Shahid Iqbal Lone Computer College Qassim University K.S.A.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
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.
LECTURE 2 : fundamentals of analysis of algorithm efficiency Introduction to design and analysis algorithm 1.
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Analysis of algorithms
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
CS 201 Fundamental Structures of Computer Science
Algorithm Efficiency and Sorting
Chapter 2.
Searching, Sorting, and Asymptotic Complexity
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Introduction to Discrete Mathematics
Analysis of algorithms
Presentation transcript:

Algorithm Analysis PS5 due 11:59pm Wednesday, April 18 Final Project Phase 2 (Program Outline) due 1:30pm Tuesday, April 24 Wellesley College CS230 Lecture 20 Tuesday, April 17 Handout #32

Overview of Today’s Lecture Motivation: determining the efficiency of algorithms Review of functions Best-case, average-case, and worst-case efficiency Asymptotic notation: a mathematical tool for describing algorithm efficiency Examples: sorting algorithms, set implementations Next time = another mathematical tool for analyzing algorithms: recurrence equations This is just an appetizer. For the full meal, take CS231 (Fundamental Algorithms)

Determining the Efficiency of Algorithms What is an efficient algorithm? –Time: Faster is better. How do you measure time? Wall clock? Computer clock? Abstract operations? –Space: Less is better Which space? Input data? Intermediate data? Output data? Where space is can affect time: registers, cache, main memory, remote machnine Algorithm analysis provides tools for determining the efficiency of an algorithm and comparing algorithms. Algorithm analysis should be independent of –specific implementations and coding tricks (PL, control constructs) –specific computers (HW chip, OS, clock speed) –particular set of data But size of data should matter Order of data can also matter

How do Your Functions Grow? function f(n) = namen= constant log 2 nlogarithmic nlinear n · log 2 n x x x 10 8 n2n2 quadratic n3n3 cubic n2n exponential For many problems, n · log2 n and less is considered good and n3 and greater is considered bad, but really depends on the problem. E.g., linear is bad for sorted array search and exponential is the best time for Towers of Hanoi.

Graphical Comparison of Functions

Some Canonical Examples Constant time: adding elt to end of vector, prepending elt to beginning of list, push/pop on efficient stack, enq/deq on efficient queue. Logarithmic time: binary search on sorted array/vector, search/insertion/deletion on balanced binary search tree. Linear time: adding elt to beginning of vector, putting elt at end of immutable list, copying array/vector/list, linear search on array/vector/list, insertion-sort on nearly-sorted array/vector/list n log n time: merge-sort on array/vector/list, heap-sort on array/vector/list quick-sort, tree-sort on unsorted array/vector/list, creating balanced BST with n elements Quadratic time: insertion-sort on unsorted array/vector/list, selection- sort on any array/vector/list, quick-sort and tree-sort on sorted array/vector/list. Cubic time: search on unsorted n x n array Exponential time: Towers of Hanoi, Traveling Salesman problem, most optimization problems

Caution: What is n? n is typically the number of elements in a collection (array, vector, list, tree, matrix, graph, stack, queue, set, bag, table, etc.) Changing the definition of n changes the analysis: Search on an unsorted square matrix is linear in the number of elements but quadratic in the side length. Search on a balanced BST is logarithmic in its number of nodes but linear its height. Search on a unsorted full tree is linear in its number of nodes but exponential in its height.

Asymptotics: Motivation Fine-grained bean-counting exposes too much detail for comparing functions. Want a course-grained way to compare functions that ignores constant factors and focuses. Example: functionn=1n=10 3 n=10 6 p(n) = 100n q(n) = 3n 2 + 2n + 1 r(n) = 0.1n 2

Asymptotics: Summary NotationPronunciationLoosely f   (g) f is way bigger than gf > g f   (g) f is at least as big as g f  g f   (g) f is about the same as gf = g f  O(g) f is at most as big as g f  g f  o(g) f is way smaller than gf < g Each of  (g),  (g), … denotes a set of functions. E.g.,  (g) is the set of all functions way bigger than g, etc. The notation f =  (g) is really shorthand for f   (g), and similarly for the other notations. The phrases “is at least O(g)” and “is at most  (g)” are non-sensical.

Order of growth of some common functions –O (1)  O (log 2 n)  O (n)  O (n * log 2 n)  O (n 2 )  O (n 3 )  O (2 n ) –Intuitively,  (1) <  (log 2 n) <  (n) <  (n * log 2 n) <  (n 2 ) <  (n 3 ) <  (2 n ) Properties of growth-rate functions –You can ignore low-order terms –You can ignore a multiplicative constant in the high-order term –  (f(n)) +  (g(n)) =  (f(n) + g(n)), and similarly for other notations. Asymptotic Analysis