More on Asymptotic Analysis + Performance Measurement

Slides:



Advertisements
Similar presentations
Lecture3: Algorithm Analysis Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Advertisements

CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Simple Sorting Algorithms
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.
Insertion Sort for (i = 1; i < n; i++) {/* insert a[i] into a[0:i-1] */ int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j];
Time Complexity s Sorting –Insertion sorting s Time complexity.
Analysis of Algorithm.
Simple Sorting Algorithms. 2 Bubble sort Compare each element (except the last one) with its neighbor to the right If they are out of order, swap them.
Insertion Sort for (int i = 1; i < a.length; i++) {// insert a[i] into a[0:i-1] int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1]
1 Chapter 2 Program Performance – Part 2. 2 Step Counts Instead of accounting for the time spent on chosen operations, the step-count method accounts.
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.
Program Performance & Asymptotic Notations CSE, POSTECH.
1 ©2008 DEEDS Group Introduction to Computer Science 2 - SS 08 Asymptotic Complexity Introduction in Computer Science 2 Asymptotic Complexity DEEDS Group.
For Wednesday Read Weiss chapter 3, sections 1-5. This should be largely review. If you’re struggling with the C++ aspects, you may refer to Savitch, chapter.
Discrete Structures Lecture 11: Algorithms Miss, Yanyan,Ji United International College Thanks to Professor Michael Hvidsten.
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.
CSE 221/ICT221 Analysis and Design of Algorithms Lecture 05: Analysis of time Complexity of Sorting Algorithms Dr.Surasak Mungsing
CSC 205 Java Programming II Algorithm Efficiency.
CSE 373 Data Structures and Algorithms
Asymptotic Notation (O, Ω, )
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
SNU IDB Lab. Ch4. Performance Measurement © copyright 2006 SNU IDB Lab.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
CSC 201 Analysis and Design of Algorithms Lecture 05: Analysis of time Complexity of Sorting Algorithms Dr.Surasak Mungsing
Program Performance 황승원 Fall 2010 CSE, POSTECH. Publishing Hwang’s Algorithm Hwang’s took only 0.1 sec for DATASET1 in her PC while Dijkstra’s took 0.2.
1 Asymptotes: Why? How to describe an algorithm’s running time? (or space, …) How does the running time depend on the input? T(x) = running time for instance.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
The Growth of Functions: Selected Exercises
Analysis of Non – Recursive Algorithms
Analysis of Non – Recursive Algorithms
CSC 427: Data Structures and Algorithm Analysis
GC 211:Data Structures Week 2: Algorithm Analysis Tools
Introduction to Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Simple Sorting Algorithms
Running Time Performance analysis
Source: wikipedia
Great Theoretical Ideas in Computer Science
Growth of functions CSC317.
DATA STRUCTURES Introduction: Basic Concepts and Notations
CS 3343: Analysis of Algorithms
O-notation (upper bound)
Asymptotic Notations Algorithms Lecture 9.
Insertion Sort for (int i = 1; i < a.length; i++)
Asymptotes: Why? How to describe an algorithm’s running time?
GC 211:Data Structures Algorithm Analysis Tools
CSC 413/513: Intro to Algorithms
CSE 373, Copyright S. Tanimoto, 2002 Performance Analysis -
CSC 205 Java Programming II
Chapter 2.
CS200: Algorithms Analysis
GC 211:Data Structures Algorithm Analysis Tools
Asst. Dr.Surasak Mungsing
CSE 373, Copyright S. Tanimoto, 2002 Asymptotic Analysis -
Algorithms Analysis Algorithm efficiency can be measured in terms of:
Sorting Rearrange a[0], a[1], …, a[n-1] into ascending order.
More on Asymptotic Analysis and Performance Measurement
Simple Sorting Algorithms
Insertion Sort for (int i = 1; i < n; i++)
Analysis of Algorithms
David Kauchak cs161 Summer 2009
CSE 373, Copyright S. Tanimoto, 2001 Asymptotic Analysis -
Simple Sorting Algorithms
Insertion Sort and Shell Sort
Estimating Algorithm Performance
CSE 373 Sorting 2: Selection, Insertion, Shell Sort
Insertion Sort for (int i = 1; i < n; i++)
Algorithms and data structures: basic definitions
Presentation transcript:

More on Asymptotic Analysis + Performance Measurement Review of Asymptotic Analysis Motivation for Performance Measurement Planning and Executing Experiments Example CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement - Review of O , Ω ,Θ f is O(g) : f is bounded above by c0g for n big enough. f is Ω(g) : f is bounded from below by c1g for n big enough. f is Θ(n) : f is bounded from above by c0g and bounded from below by c1g for n big enough. CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement - Big Θ ( more Examples) 5 is O(1) and 5 is Ω(1) so 5 is Θ(1) Take c0 = 10 and n = 0: 5  10  1 for all n > 0 (n actually doesn’t affect the values of the inequality at all in this case). Take c1 = 4 and n = 0: 5  4  1 for all n > 0 CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement - Ordering Growth Rates If f is not O(g) but f is O(h) ,then g is strictly asymptotically dominated by h O(g) < O(h) O(1) < O(log n) < O(log2 n) < O(n) < O(n log n) < O(n2) < O(n3) < O(nk) < O(1.1n) < O(2n) < O(3n) < O(n!) < O(nn) CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement - Motivation Theoretical analysis may miss aspects of performance such as data characteristics that affect running time. Assumptions about the dominance of particular operations may need to be tested. Improvements in implementation are typically not measured by asymptotic methods. CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

Setting Up Experiments Choosing instance sizes Purpose? Fit a model based upon asymptotic analysis Developing test data Data for best-case, worst-case, and average-case behavior. Setting up the experiment CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

Example 1: Selection Sort We might know that f(n) = c1n2 + c2n + c3 We are most interested in determining c1 which best describes the behavior for large n. We might take instance sizes of 10, 50, and 100 and 200. CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement - Selection Sort Demo For a simple demo of a 2-buffer version of Selection Sort using a Java class called VisibleDataStructure, see http://cubist.cs.washington.edu/~tanimoto/DS/SelectionSort/index.html CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

Example 2: Insertion Sort Again, we might know that f(n) = c1n2 + c2n + c3 However, the performance is highly data dependent. For each instance size, we might generate best-case, worst-case, and random data. CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

Insertion Sort: Java Code public static void intInsertionSort (int [] a) { for (int i=1; i < a.length; i++) { int temp = a[i]; int j; for (j = i - 1; j >= 0 && temp < a[j] ; j--) a[j + 1] = a[j]; a[j + 1] = temp; } CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -

CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement - Insertion Sort (Cont.) Data dependent performance... If a is sorted, n - 1 data comparisons are used. In the worst case, n(n-1)/2 are used. Multiple runs with random data would afford a good estimate of the average-case running time. CSE 373, Copyright S. Tanimoto, 2001 Performance Measurement -