CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.

Slides:



Advertisements
Similar presentations
HST 952 Computing for Biomedical Scientists Lecture 10.
Advertisements

Fundamentals of Python: From First Programs Through Data Structures
Complexity Theory  Complexity theory is a problem can be solved? Given: ◦ Limited resources: processor time and memory space.
Computational Complexity 1. Time Complexity 2. Space Complexity.
CS 206 Introduction to Computer Science II 04 / 28 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 09 / 14 / 2009 Instructor: Michael Eckmann.
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 102 Computers In Context (Multimedia)‏ 04 / 20 / 2009 Instructor: Michael Eckmann.
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.
Introduction to Analysis of Algorithms
CS 206 Introduction to Computer Science II 09 / 12 / 2008 Instructor: Michael Eckmann.
CS107 Introduction to Computer Science
CISC220 Spring 2010 James Atlas Lecture 06: Linked Lists (2), Big O Notation.
Cmpt-225 Algorithm Efficiency.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
The Efficiency of Algorithms
Concept of Basic Time Complexity Problem size (Input size) Time complexity analysis.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithm.
CS2336: Computer Science II
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.
Algorithm Analysis (Big O)
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Aaron Bauer Winter 2014.
COMPSCI 102 Introduction to Discrete Mathematics.
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Lecture 2 Computational Complexity
Algorithm Efficiency CS 110: Data Structures and Algorithms First Semester,
Mathematics Review and Asymptotic Notation
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.
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.
Algorithm Analysis PS5 due 11:59pm Wednesday, April 18 Final Project Phase 2 (Program Outline) due 1:30pm Tuesday, April 24 Wellesley College CS230.
Big Oh Algorithms are compared to each other by expressing their efficiency in big-oh notation Big O notation is used in Computer Science to describe the.
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.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Analysis of Algorithms [ Section 4.1 ] Examples of functions important in CS: the constant function:f(n) =
MS 101: Algorithms Instructor Neelima Gupta
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
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.
Asymptotic Analysis (based on slides used at UMBC)
Copyright © 2014 Curt Hill Growth of Functions Analysis of Algorithms and its Notation.
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.
CS 206 Introduction to Computer Science II 02 / 02 / 2009 Instructor: Michael Eckmann.
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.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
DS.A.1 Algorithm Analysis Chapter 2 Overview Definitions of Big-Oh and Other Notations Common Functions and Growth Rates Simple Model of Computation Worst.
Big O David Kauchak cs302 Spring Administrative Assignment 1: how’d it go? Assignment 2: out soon… Lab code.
0 Introduction to asymptotic complexity Search algorithms You are responsible for: Weiss, chapter 5, as follows: 5.1 What is algorithmic analysis? 5.2.
John Levine, Computer and Information Sciences, Strathclyde University 1 Algorithms and Complexity 2: Complexity Notation.
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.
Introduction to Data Structures
Introduction to 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.
Introduction to Algorithms
Building Java Programs
Introduction to Algorithms Analysis
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
Introduction to Data Structures
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Presentation transcript:

CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann

Michael Eckmann - Skidmore College - CS Spring 2009 Today’s Topics Questions/comments sorting write code to sort an ArrayList start algorithm analysis

Michael Eckmann - Skidmore College - CS Spring 2009 Programming Examples Let's write a simple insertion sort method to sort the Cards in the ArrayList. To remind ourselves of how insertion sort works, let's look at:

Michael Eckmann - Skidmore College - CS Spring 2009 HW Read handout on Algorithm Analysis and Chapter 5.

Michael Eckmann - Skidmore College - CS Spring 2009 Algorithm Analysis An algorithm is a specific set of instructions for solving a problem. The amount of time an algorithm takes to finish is often proportional to the amount of input –sorting 1 million items vs. sorting 10 items –searching a list of 2 billion items vs. searching a list of 3 items Problem vs. algorithm --- a problem is not the same as an algorithm. Example: Sorting is a problem. An algorithm is a specific recipe for solving a problem. –bubbleSort, insertionSort, etc. are different algorithms for sorting. So, when we're analyzing the running time --- we're analyzing the running time of an algorithm, not a problem.

Michael Eckmann - Skidmore College - CS Spring 2009 Algorithm Analysis Algorithms are often analyzed for –the amount of time they take to run and/or –the amount of space used while running

Michael Eckmann - Skidmore College - CS Spring 2009 Algorithm Analysis Some common functions (in increasing order) used in analysis are –constant functions (e.g. f(n) = 10 )‏ –logarithmic functions (e.g. f(n) = log(20n) )‏ –log squared (e.g. f(n) = log 2 (7n) )‏ –linear functions (e.g. f(n) = 3n – 9 )‏ –N log N (e.g. f(n) = 2n log n )‏ –quadratic functions (e.g. f(n) = 5n 2 + 3n )‏ –cubic functions (e.g. f(n) = 3n n 2 + (4/7)n )‏ –exponential functions (e.g. f(n) = 5 n )‏ –factorial functions (e.g. f(n) = n! )‏

Michael Eckmann - Skidmore College - CS Spring 2009 Algorithm Analysis The dominant term is what gives a function it's name among –cubic, quadratic, logarithmic, etc. It's more complex than this, but the dominant term can generally be picked out like: –if you determine a function for the running time of an algorithm to be say f(n) = log 2 n + 4n 3 it's dominant term is 4n 3 so ignoring constant multiplier, we have n 3 –we say that f(n) is O (n 3 ) (pronounced big-Oh en cubed)‏ An example of when it's a bit harder to determine –f(n) = 3n log(n!) + (n 2 + 3)log n is O(n 2 logn)‏

Michael Eckmann - Skidmore College - CS Spring 2009 Algorithm Analysis Graphs of functions to get a more intuitive feel for the growth of functions, take a look at the handout with graphs.

Michael Eckmann - Skidmore College - CS Spring 2009 Algorithm Analysis Let's look at the tables with examples of actual times for certain running times given large inputs shows that the time complexity of an algorithm is much more important than processor speed (for large enough inputs) even though processor speeds are getting faster exponentially

Michael Eckmann - Skidmore College - CS Spring 2009 Algorithm Analysis Growth rates of functions are different than being able to say one function is less than another –e.g. x is greater than x 3 for many initial values but as x increases above some value, x 3 will always be bigger The constant being multiplied by the dominant term is generally ignored (except for small amounts of input)‏ Big O notation ignores the constant multipliers of the dominant term and we say a phrase like: –linear search is big Oh en –when we mean that the linear search algorithm's time complexity grows linearly (based on n, the number of items in the search space).

Michael Eckmann - Skidmore College - CS Spring 2009 Algorithm Analysis When examining an algorithm, we usually count how many times a certain operation (or group of operations) is performed. See handout for reasonable choices of what operations we would count in different problems. This will lead us to determining the time complexity of the algorithm. We can consider best-case, worst-case and average-case scenarios.