Introduction to design and analysis algorithm LECTURE 2 fundamentals of analysis of

advertisement
Introduction to design
and analysis algorithm
1
LECTURE 2
:
f u n d a m e n t a ls o f a n a l y s i s o f
algorithm efficiency
Theoretical analysis of time efficiency(time
complexity)
2
Time efficiency is analyzed by determining the number of
repetitions of the basic operation as a function of input
size
 Basic operation: the operation that contributes most
towards the running time of the algorithm
T(n) ≈ copC(n)




n:input size
C(n):Number of times basic operation is executed
T(n) running time
Cop: constants
T(n) ≈ C(n)
Example 2.1:for the following code
a- what is the basic operation?
b- what is C(n)?
d-what is the running time?
3
Input size and basic operation examples
Problem
Basic operation
Searching for key in a
list of n items
Key comparison
Multiplication of two
matrices
Multiplication of two
numbers
Checking primality of
a given integer n
Division
Typical graph problem
Visiting a vertex or
traversing an edge
application:
Determinate the largest element in a given array
20
40
4
89
125
23
Download