complexity - Measuring Performance of Algorithms There are...

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

View Full Document Right Arrow Icon
Measuring Performance of Algorithms There are two aspects of algorithmic performance: • Time - Instructions take time. - How fast does the algorithm perform? - What affects its runtime? • Space - Data structures take space - What kind of data structures can be used? - How does choice of data structure affect the runtime? Algorithms can not be compared by running them on computers. Run time is system dependent. Even on same computer would depend on language Real time units like microseconds not to be used. Generally concerned with how the amount of work varies with the data. 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Measuring Time Complexity Counting number of operations involved in the algorithms to handle n items. Meaningful comparison for very large values of n. Complexity of Linear Search Consider the task of searching a list to see if it contains a particular value. • A useful search algorithm should be general. • Work done varies with the size of the list • What can we say about the work done for list of any length? i = 0; i = i + 1; if (i <MAX) printf ( “Yes, target is there \n” ); else printf( “No, target isn’t there \n” ); The work involved : Checking target value with each of the n elements. 2
Background image of page 2
no. of operations: 1 (best case) n (worst case) n/2 (average case) Computer scientists tend to be concerned about the Worst Case complexity . The worst case guarantees that the performance of the algorithm will be at least as good as the analysis indicates. Average Case Complexity: It is the best statistical estimate of actual performance, and tells us how well an algorithm performs if you average the behavior over all possible sets of input data. However, it requires considerable mathematical sophistication to do the average case analysis. 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Algorithm Analysis: Loops Consider an n X n two dimensional array. Write a loop to store the row sums in a one-dimensional array rows and the overall total in grandTotal . LOOP 1: grandTotal = 0; for (k=0; k<n-1; ++k) { rows[k] = 0; for (j = 0; j <n-1; ++j){ rows[k] = rows[k] + matrix[k][j]; grandTotal = grandTotal + matrix[k][j]; } } It takes 2n 2 addition operations LOOP 2: grandTotal =0; for (k=0; k<n-1; ++k)
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 16

complexity - Measuring Performance of Algorithms There are...

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

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