CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation.

Slides:



Advertisements
Similar presentations
 O: order of magnitude  Look at the loops and to see whether the loops are nested. ◦ One single loop: O(n) ◦ A nested loop: O(n 2 ) ◦ A nested loop.
Advertisements

Algorithm Analysis.
Lecture: Algorithmic complexity
HST 952 Computing for Biomedical Scientists Lecture 10.
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
Chapter 10 Algorithm Efficiency
1 CSE1301 Computer Programming Lecture 31: List Processing (Search)
Runtime Analysis CSC 172 SPRING 2002 LECTURE 9 RUNNING TIME A program or algorithm has running time T(n), where n is the measure of the size of the input.
CISC220 Spring 2010 James Atlas Lecture 06: Linked Lists (2), Big O Notation.
Cmpt-225 Algorithm Efficiency.
The Efficiency of Algorithms
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Data Structures and Algorithms1 Basics -- 2 From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University: Harper.
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.
1 Section 2.3 Complexity of Algorithms. 2 Computational Complexity Measure of algorithm efficiency in terms of: –Time: how long it takes computer to solve.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
COMP s1 Computing 2 Complexity
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
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 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
Algorithm Analysis. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. recipes directions for putting.
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.
Analysis of Algorithms
Mathematical Preliminaries The Factorial Function Permutations Logarithms Summations Recurrence Relations Algorithm Analysis.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
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.
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
CSC 205 Java Programming II Algorithm Efficiency.
Ch 18 – Big-O Notation: Sorting & Searching Efficiencies Our interest in the efficiency of an algorithm is based on solving problems of large size. If.
Asymptotic Analysis-Ch. 3
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Algorithm Efficiency and Sorting Data Structure & Algorithm.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Computer Science and Software Engineering University of Wisconsin - Platteville 8. Comparison of Algorithms Yan Shi CS/SE 2630 Lecture Notes Part of this.
RUNNING TIME 10.4 – 10.5 (P. 551 – 555). RUNNING TIME analysis of algorithms involves analyzing their effectiveness analysis of algorithms involves analyzing.
Algorithmic Analysis Charl du Plessis and Robert Ketteringham.
CISC 235: Topic 1 Complexity of Iterative Algorithms.
Algorithm Analysis (Big O)
CISC220 Fall 2009 James Atlas Dec 07: Final Exam Review.
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.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
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 3COMPSCI.220.S1.T Running Time: Estimation Rules Running time is proportional to the most significant term in T(n) Once a problem size.
Algorithm Analysis 1.
Introduction to Analysis of Algorithms
Thought for the Day “Years wrinkle the skin, but to give up enthusiasm wrinkles the soul.” – Douglas MacArthur.
Introduction to 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 Algorithms
Lecture 06: Linked Lists (2), Big O Notation
Program Efficiency Interested in “order of magnitude”
Building Java Programs
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
DS.A.1 Algorithm Analysis Chapter 2 Overview
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
Asymptotic Notations Algorithms perform f(n) basic operations to accomplish task Identify that function Identify size of problem (n) Count number of operations.
Time Complexity Lecture 15 Mon, Feb 27, 2006.
8. Comparison of Algorithms
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:

CISC220 Spring 2010 James Atlas Lecture 07: Big O Notation

Objectives for Today Big-O notation Reading - K+W Chap , 2.6

Big-O notation Describes the relationship between input size and execution time If we double the number of inputs, n, and the execution time is approximately doubled –Linear growth rate –Growth rate has an order of n –O(n)

Example 2.14/2.16 Analysis 2.14 –execution time proportional to x_length –O(n) 2.16 –execution time proportional to (x_length) 2 –O(n 2 )

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } Simple Statement 1 Simple Statement 2... Simple Statement 25

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } n 2 executions

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } n executions, 5 statements per = 5n

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } Simple Statement 1 Simple Statement 2... Simple Statement 25 1 execution, 25 statements = 25

Let’s count individual instructions for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Simple Statement } for (int k = 0; k < n; k++) { Simple Statement 1 Simple Statement 2 Simple Statement 3 Simple Statement 4 Simple Statement 5 } Simple Statement 1 Simple Statement 2... Simple Statement 25 T(n) = total execution time as a function of n T(n) = n 2 + 5n + 25

Formal Big-O Definition T(n) = n 2 + 5n + 25 T(n) = O(f(n)) means that there exists a function, f(n), that for sufficiently large n and some constant c: cf(n)  T(n)

n n + 25 vs. 3n 2

Common Big-O Runtimes Constant -- O(1) Logarithmic -- O(log n) Fractional -- O(sqrt n) Linear -- O(n) Log-Linear-- O(n log n) Quadratic -- O(n 2 ) Cubic -- O(n 3 ) Exponential -- O(2 n ) Factorial -- O(n!)

Various Runtimes

Powers of n (Order of the polynomial)

Multiplicative Constants

Multiplicative Constants (cont’)

Dominant Terms (1)

Dominant Terms (2)

Dominant Terms (3)

Dominant Terms Comparison

Dominant Terms Comparison (cont’)

Class Exercise Implement last on our Linked List

Group Exercise Implement last in O(1)

The big-O notation can be derived from T(n) using the following steps: 1) Set the coefficient of each term to 1 2) Keep the largest (least efficient) term in the function and discard the others.

Standard Measures of Efficiency To get a feel for how much of a difference an algorithm’s efficiency makes, check out the table on the next slide. The table assumes an instruction speed of 1 microsecond, 10 instructions per loop, and n=10,000

Standard Measures of Efficiency Efficiency Big-O IterationsEstimated Time Logarithmic O(log 2 n)14Microseconds Linear O(n)10, seconds Linear Logarithmic O(nlog 2 n)140,0002 seconds Quadratic O(n 2 )10,000 2 ~17 minutes Polynomial O(n k )10,000 k Hours Exponential O(c n )2 10,000 Intractable Factorial O(n!)10,000!Intractable

Standard Measures of Efficiency

Calculating Big-O 1.T(n) = 6n 4 − 2n T(n) = 9 log n + 5 (log n) 3 + 3n 2 + 2n 3 3.T(n) = 3n 2 + O(log n) + O(n) + O(n log n)

Calculating Big-O 4.Binary Search on an array: T(n) = T(n/2) + O(1) 5.T(1) = 2 T(n) = 2T(n - 1) + O(1) for n>1 6.T(1) = 1 T(n) = 2T(n/2) + O(1) for n>1