More on Asymptotic Analysis Performance Measurement Review of

  • Slides: 11
Download presentation
More on Asymptotic Analysis + Performance Measurement • Review of Asymptotic Analysis • Motivation

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 1

Review of O , Ω , Θ f is O(g) : f is bounded

Review of O , Ω , Θ f is O(g) : f is bounded above by c 0 g for n big enough. f is Ω(g) : f is bounded from below by c 1 g for n big enough. f is Θ(n) : f is bounded from above by c 0 g and bounded from below by c 1 g for n big enough. CSE 373, Copyright S. Tanimoto, 2001 2

Big Θ ( more Examples) 5 is O(1) and 5 is Ω(1) Take c

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

Ordering Growth Rates If f is not O(g) but f is O(h) , then

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(log 2 n) < O(n log n) < O(n 2) < O(n 3) < O(nk) < O(1. 1 n) < O(2 n) < O(3 n) < O(n!) < O(nn) CSE 373, Copyright S. Tanimoto, 2001 4

Motivation • Theoretical analysis may miss aspects of performance such as data characteristics that

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 5

Setting Up Experiments • Choosing instance sizes • Purpose? Fit a model based upon

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 6

Example 1: Selection Sort We might know that f(n) = c 1 n 2

Example 1: Selection Sort We might know that f(n) = c 1 n 2 + c 2 n + c 3 We are most interested in determining c 1 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 7

Selection Sort Demo For a simple demo of a 2 -buffer version of Selection

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

Example 2: Insertion Sort Again, we might know that f(n) = c 1 n

Example 2: Insertion Sort Again, we might know that f(n) = c 1 n 2 + c 2 n + c 3 However, the performance is highly data dependent. For each instance size, we might generate bestcase, worst-case, and random data. CSE 373, Copyright S. Tanimoto, 2001 9

Insertion Sort: Java Code public static void int. Insertion. Sort (int [] a) {

Insertion Sort: Java Code public static void int. Insertion. Sort (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 10

Insertion Sort (Cont. ) Data dependent performance. . . If a is sorted, n

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 11