ACM/JETT Workshop - August 4-5, 2005 Big-O Performance Analysis Based on a presentation by Dr. Simon Garrett, The University of Wales, Aberystwyth:

Slides:



Advertisements
Similar presentations
Algorithm Complexity Analysis: Big-O Notation (Chapter 10.4)
Advertisements

Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L17 (Chapter 23) Algorithm.
Cmpt-225 Algorithm Efficiency.
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, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithm.
 2006 Pearson Education, Inc. All rights reserved Searching and Sorting.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Abstract Data Types (ADTs) Data Structures The Java Collections API
COMP s1 Computing 2 Complexity
Chapter 5 Algorithm Analysis 1CSCI 3333 Data Structures.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Introduction to complexity Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Algorithm Analysis & Complexity We saw that a linear search used n comparisons in the worst case (for an array of size n) and binary search had logn comparisons.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Introduction to complexity. 2 Analysis of Algorithms Why do we need to analyze algorithms? –To measure the performance –Comparison of different algorithms.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
{ 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)
Reynolds 2006 Complexity1 Complexity Analysis Algorithm: –A sequence of computations that operates on some set of inputs and produces a result in a finite.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Analysis of Algorithms
Chapter 10 A Algorithm Efficiency. © 2004 Pearson Addison-Wesley. All rights reserved 10 A-2 Determining the Efficiency of Algorithms Analysis of algorithms.
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
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.
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data.
SortingBigOh Sorting and "Big Oh" Adapted for ASFA from a presentation by: Barb Ericson Georgia Tech Aug 2007 ASFA AP Computer Science.
ACM/JETT Workshop - August 4-5, 2005 Using Visualization Tools To Teach Data Structures and Algorithms Java applets by Dr. R. Mukundan, University of Canterbury,
1 Lecture 5 Generic Types and Big O. 2 Generic Data Types A generic data type is a type for which the operations are defined but the types of the items.
SortingBigOh ASFA AP Computer Science A. Big-O refers to the order of an algorithm runtime growth in relation to the number of items I. O(l) - constant.
Data Structure Introduction.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
Big-Oh Notation. Agenda  What is Big-Oh Notation?  Example  Guidelines  Theorems.
Complexity Analysis. 2 Complexity The complexity of an algorithm quantifies the resources needed as a function of the amount of input data size. The resource.
Algorithm Analysis. What is an algorithm ? A clearly specifiable set of instructions –to solve a problem Given a problem –decide that the algorithm is.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
C++ How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Searching Topics Sequential Search Binary Search.
CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
1 Algorithms Searching and Sorting Algorithm Efficiency.
Algorithm Complexity Analysis (Chapter 10.4) Dr. Yingwu Zhu.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
LECTURE 9 CS203. Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search) and sorting (selection sort.
19 Searching and Sorting.
Analysis of Algorithms
Analysis of Algorithms
COMP108 Algorithmic Foundations Algorithm efficiency
Introduction to Analysis of Algorithms
Introduction to complexity
Introduction to Analysis of Algorithms
Introduction to Algorithms
Big-Oh and Execution Time: A Review
Building Java Programs
CSE 143 Lecture 5 Binary search; complexity reading:
Algorithm Efficiency Chapter 10.
CSE 1342 Programming Concepts
Analysis of Algorithms
CSE 143 Lecture 8 More Stacks and Queues; Complexity (Big-Oh)
Building Java Programs
CSE 143 Lecture 8 More Stacks and Queues; Complexity (Big-Oh)
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
Algorithmic complexity
Analysis of Algorithms
Algorithms and data structures: basic definitions
Presentation transcript:

ACM/JETT Workshop - August 4-5, 2005 Big-O Performance Analysis Based on a presentation by Dr. Simon Garrett, The University of Wales, Aberystwyth:

ACM/JETT Workshop - August 4-5, Execution Time Factors Computer: –CPU speed, amount of memory, etc. Compiler: –Efficiency of code generation. Data: –Number of items to be processed. –Initial ordering (e.g., random, sorted, reversed) Algorithm: –E.g., linear vs. binary search.

ACM/JETT Workshop - August 4-5, Are Algorithms Important? The fastest algorithm for 100 items may not be the fastest for 10,000 items! Algorithm choice is more important than any other factor! O(log N) O(N) O(N 2 )

ACM/JETT Workshop - August 4-5, What is Big-O? Big-O characterizes algorithm performance. Big-O describes how execution time grows as the number of data items increase. Big-O is a function with parameter N, where N represents the number of items.

ACM/JETT Workshop - August 4-5, Common Growth Rates Big-O CharacterizationExample O(1)constantAdding to the front of a linked list O(log N)logBinary search O(N)linearLinear search O(N log N)n-log-nBinary merge sort O(N 2 )quadraticBubble Sort O(N 3 )cubicSimultaneous linear equations O(2 N )exponentialThe Towers of Hanoi problem

ACM/JETT Workshop - August 4-5, Predicting Execution Time If a program takes 10ms to process one item, how long will it take for 1000 items? (time for 1 item) x (Big- O( ) time complexity of N items) log 10 N3 x 10ms.03 sec N10 3 x 10ms10 sec N log 10 N10 3 x 3 x 10ms30 sec N2N x 10ms16 min N3N x 10ms12 days

ACM/JETT Workshop - August 4-5, How to Determine Big-O? Repetition Sequence Selection Logarithmic

ACM/JETT Workshop - August 4-5, Determining Big-O: Repetition for (i = 1; i <= n; i++) { m = m + 2 ; } constant time executed n times Total time = (a constant c) * n = cn = O(N) Ignore multiplicative constants (e.g., “c”).

ACM/JETT Workshop - August 4-5, Determining Big-O: Repetition for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { k = k+1 ; } constant time outer loop executed n times inner loop executed n times Total time = c * n * n * = cn 2 = O(N 2 )

ACM/JETT Workshop - August 4-5, Determining Big-O: Repetition for (i = 1; i <= n; i++) { for (j = 1; j <= 100; j++) { k = k+1 ; } constant time outer loop executed n times inner loop executed 100 times Total time = c * 100 * n * = 100cn = O(N)

ACM/JETT Workshop - August 4-5, Determining Big-O: Sequence Total time = x = x +1; for (i=1; i<=n; i++) { m = m + 2; } for (i=1; i<=n; i++) { for (j=1; j<=n; j++) { k = k+1; } inner loop executed n times outer loop executed n times constant time (c 2 ) executed n times constant time (c 1 ) constant time (c 0 ) Only dominant term is used Total time = c 0 Total time = c 0 + c 1 nTotal time = c 0 + c 1 n + c 2 n 2 Total time = c 0 + c 1 n + c 2 n 2 = O(N 2 )

ACM/JETT Workshop - August 4-5, Determining Big-O: Selection test + worst-case(then, else) if (depth( ) != otherStack.depth( ) ) { return false; } else { for (int n = 0; n < depth( ); n++) { if (!list[n].equals(otherStack.list[n])) return false; } then part: constant (c 1 ) else part: (c 2 + c 3 ) * n test: constant (c 0 ) another if : test (c 2 ) + then (c 3 ) Total time = c 0 Total time = c 0 + Worst-Case(then, else)Total time = c 0 + Worst-Case(c 1, else)Total time = c 0 + Worst-Case(c 1, (c 2 + c 3 ) * n) = O(N)

ACM/JETT Workshop - August 4-5, Determining Big-O: Logarithmic An algorithm is O(log N) if it takes a constant time to cut the problem size by a fraction (usually by ½) Example: Dictionary (binary) search Look at middle of the dictionary Is word before or after? Repeat with left or right half until found

ACM/JETT Workshop - August 4-5, 2005 Demonstration