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 -