Algorithm Analysis

# Algorithm Analysis - Algorithm Analysis An algorithm is a...

This preview shows pages 1–10. Sign up to view the full content.

1 Algorithm Analysis z An algorithm is a clearly specified set of simple instructions to be followed to solve a problem. – How to estimate the running time ; – How to reduce the running time of a program from days to fractions of a second; – What is the storage complexity of the program. – How to deal with the trade-offs.

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

View Full Document
2 Running Time of a Program z There are two contradictory goals: – We would like an algorithm that is easy to understand, code, and debug. – We would like an algorithm that makes efficient use of the computer's resources, especially, one that runs as fast as possible.
3 Function Comparison z Given two functions, f ( N ) and g ( N ), what does it mean when we say that f ( N ) < g ( N )? – Should this hold for all N ? – We need to compare their relative rates of growth.

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

View Full Document
4 Definitions z T ( N ) = O ( f ( N )) if there are positive constants c and n 0 such that T ( N ) c f ( N ) when N n 0 . z T ( N ) = ( g ( N )) if there are positive constants c and n 0 such that T ( N ) c g ( N ) when N n 0 . z T ( N ) = Θ ( h ( N )) if and only if T ( N ) = O ( h ( N )) and T ( N ) = ( h ( N )). z T ( N ) = o( p ( N )) if T ( N ) = O ( p ( N )) and T ( N ) Θ ( p ( N )).
5 Example

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

View Full Document
6 Why? z The idea is to establish a relative order among functions. z We are more concerned about the relative rates of growth of functions. z For example, which function is greater, 1,000 N or N 2 ? z The turning point is n 0 = 1,000 where N 2 will be greater for larger N .
7 First Definition O z It says that there is some point n 0 past which cf ( N ) is always at least as large as T ( N ). z In our case, T ( N ) = 1000 N , f ( N ) = N 2 , n 0 = 1,000, and c = 1. z We could also use n 0 = 10, and c = 100. z So we can say that 1000 N = O ( N 2 ). z It is an upper bound on T ( N ).

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

View Full Document
8 Others z The second definition says that the growth rate of T ( N ) is greater than or equal to that of g ( N ). z The third definition Θ says that the growth rate of T ( N ) equals the growth rate of h ( N ). z The fourth definition o says that the growth rate of T ( N ) is less than the growth rate of p ( N ).
Big-O Notation z If f ( n ) and g ( n ) are functions defined for positive integers, then to write f ( n ) is O ( g ( n )) z read f ( n ) is big Oh of g ( n ) means that there exists a constant c such that | f ( n )| c | g ( n )| for all sufficiently large positive integers n . z

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 38

Algorithm Analysis - Algorithm Analysis An algorithm is a...

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

View Full Document
Ask a homework question - tutors are online