ALGORITHM ANALYSIS ------------------ Analyze code to determine how much TIME is required to execute an algorithm. Comparative measure. Given multiple algorithms to solve a problem, which one is better??? Order Notation -------------- Algorithm A is O(f(n)) or "order f(n)" if constants k and n0 exist such that A requires no more than k * f(n) operations to solve a problem of size n >= n0 What is the "order" of these algorithm runtimes? (a) 3n + 2 ==> 3n ==> O(n) LINEAR (b) 5n - 5 ==> 5n ==> O(n) 17n (c) 14 + ----- ==> 0.1n ==> O(n) 170 2 n 2 2 (d) ---- + 15n - 6 ==> 0.1n ==> O(n ) 10 QUADRATIC 2 2 (e) 10000 + 36n - 4n ==> O(n ) ----------------------- O(1) Constant O(log n) Logarithmic O(n) Linear O(n log n) 2 O(n ) Quadratic 3 O(n ) n O(2 ) Exponential e.g. int count = 0; for ( int i = 0 ; i < n ; i++ ) { for ( int j = i ; j < n ; j++ ) { count++; } }