Download More on Asymptotic Notation - Lecture Notes | CSCE 310 and more Study notes Algorithms and Programming in PDF only on Docsity! Mihaela Gheorghiu Spring 2002 CSCE-310 Data Struct. & Alg. More on Asymptotic Notation January 23, 2002 How to use asymptotic notation for algorithm analysis. Asymptotic notation is used to determine rough estimates of relative running time of algo- rithms. In class we saw an example of worst-case analysis of pseudocode that led to a big-O estimate. A worst-case analysis of any algorithm will always yield such an estimate, because it gives an upper bound on the running time of the algorithm, that is , and so . In some cases, an exact analysis of the running time is possible, and then we get , so . Here is an example: a <- 0 1 unit 1 time for i <- 1 to n do 1 unit n times for j <- 1 to i do 1 unit n(n+1)/2 times a <- a+1 1 unit n(n+1)/2 times where the times for the inner loop have been computed as follows: for each from to , the loop is executed times, so the total number of times is "!#$%$&$' () * +-, ./ 0 (see Appendix A.1 in the book for this, and other summation formulas). Hence in this case 1 20 .3 " 45$ If we write 3 6 7 , then , that is 8 9 3 6 7 . We actually write 3 , as recommended by the following rule. Be as simple and as precise as possible in analysis. Although the definitions of asymptotic notation allow one to write, for example, 8 : ! 3 . , in practice we never write something like that; we simplify the function in between the parentheses as much as possible (in terms of rate of growth), and write instead ; 3 . Similarly, we don’t write, for example, 8 <"=5 > ?@ 3 :! , but A"B>C . Also, it is wrong to write, for instance, ED ( * +-, ; write instead 3 , after computing the sum. Also, the analysis should be as precise as possible, in the sense that it should provide the closest asymptotic bounds for functions; for example, while it is true that ! "F 3 , we know that ! is actually constant time, rather than quadratic time, so ! GF or ! is the right analysis. In the spirit of the simplicity rule above, when we are to compare, for instance, two candidate algorithms H and I having running times JK8L 3 ? ! = and M18ONP> .! , rather than writing JK QRMS , we write JK QTB 3 , and M1 UT->V , and then we 1