Complexity - CSS342: Algorithm Analysis Professor: Munehiro...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CSS342: Algorithm Analysis 1 CSS342: Algorithm Analysis Professor: Munehiro Fukuda
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSS342: Algorithm Analysis 2 Today’s Topics 1. Mathematical analysis of algorithm complexity 2. Examples of algorithm complexity 3. Algorithm improvement from O(N 3 ) to O(N) 4. Efficiency of search algorithms
Background image of page 2
CSS342: Algorithm Analysis 3 Measuring Algorithm Efficiency Cost of a computer program Human cost: Developing good problem-solving skills and programming style Execution cost: Algorithm efficiency Then, what in efficiency should we focus? Clever trick in coding? Execution time? How should we compare programs? Based on a particular computer? What data should be given? Mathematical Analysis
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSS342: Algorithm Analysis 4 Counting an Algorithm’s operations for ( i = 1; i <= n; i++ ) for ( j = 1; j <= i; j++ ) for ( k = 1; k <= 5; k++ ) task( ); Task: t operations ( or may take t seconds) Loop on k: 5 * t Loop on j: 5 * t (i = 1), 5 * t * 2 (i = 2), … 5 * t * n (i = n) n Loop on i: ∑(5 * t * i) = 5 * t * n * (n + 1) / 2 i=1 Mathematical Analysis
Background image of page 4
CSS342: Algorithm Analysis 5 Algorithm Growth Rates Nested loop i/j/k requires 5n(n+1)/2 time units to process a problem of size n. Units may be seconds, minutes, and even dependent on what machines we use! Nested loop i/j/k requires time proportional to 5n(n+1)/2 Focus on how quickly the algorithm’s time requirement grows as a function of the problem size. Growth rate Mathematical Analysis
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSS342: Algorithm Analysis 6 Order-of-Magnitude Analysis Let Algorithm A require time proportional to f(n). A is of order at most g(n), O(g(n)) if f(n) <= k * g(n), for a positive constant k and n > n 0 A is of order at least g(n), Ω(g(n)) if f(n) >= k * g(n), for a positive constant k and n > n 0 A is of order g(n), Θ(g(n)) if Mathematical Analysis
Background image of page 6
CSS342: Algorithm Analysis 7 Example of O(g(n)), Ω(g(n)) ,andΘ(g(n)) Suppose Algorithm A requires time proportional to f(n) = n 2 – 3n + 10 f(n) < k* n 2 , if k = 3 and n >= 2, and thus f(n) = O(n 2 ) f(n) > k * n 2 , if k = 0.5 n>= 0, and thus f(n) = Ω(n 2 ) Therefore f(n) = Θ(n 2 ) 27 10 4.5 3 12 8 2 2 3 8 0.5 1 0 10 0 0 3n 2 N 2 -3N+10 0.5n 2 n Mathematical Analysis
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSS342: Algorithm Analysis 8 Example of Program Analysis j = n while ( j >= 1 ) { for ( i = 1; i <= j; i++ ) x = x + 1; // How many times is x=x+1 executed? j = j / 2;
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 12/20/2009.

Page1 / 25

Complexity - CSS342: Algorithm Analysis Professor: Munehiro...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online