This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1 Analysis of Algorithm 2 60 [CS1102C AY0708S2 Lecture 5] Lecture Outline ยก What is an algorithm? ยก What is analysis of algorithm? ยก How to analyze an algorithm ยก BigO notation ยก Examples 3 60 [CS1102C AY0708S2 Lecture 5] You are expected to know ยก Operations on logarithm function ยก Arithmetic and geometric progressions ยข Their sums ยก Linear, Quadratic, Cubic, Polynomial ยก Ceiling, Floor, Absolute Value 4 60 [CS1102C AY0708S2 Lecture 5] Algorithm and Analysis ยก Algorithm: ยข A stepbystep procedure for solving a problem ยก Analysis of Algorithm: ยข To evaluate rigorously the resources (time and space) needed by an algorithm and represent the result of the evaluation with a formula ยข We focus more on time requirement in our analysis ยข The time requirement of an algorithm is also called the time complexity of the algorithm 2 5 60 [CS1102C AY0708S2 Lecture 5] Limitation of exact running time ยก We can measure the exact running time of a program ยข Use wall clock time or code inserted into program ยก To compute the exact running time needed by an algorithm, the analysis will depend on : ยข Language in which the algorithm is coded ยข Data set : input to the algorithm ยข Computer that the algorithm is executed on ยก Such analysis will make it difficult to compare 2 algorithms ยก It is useful to know the behavior of the algorithm before it is coded / executed ยข Poorly designed algorithm may take very long to finish execution 6 60 [CS1102C AY0708S2 Lecture 5] How to Analyze an Algorithm? ยก Instead of measure the exact timing ยข Count the number of operations needed ยก Operations: Arithmetic, Assignment, Comparison etc ยข Usually choose the โdominantโ operations ยก Example: for (int i=1; i<=n; i++) { perform 100 operations; // A for (int j=1; j<=n; j++) perform 2 operations; // B } Total Ops = A + B = ฮฃ {i = 1,n}100 + ฮฃ {i = 1,n} ( ฮฃ {j = 1,n} 2) = 100n + ฮฃ {i = 1,n} (2n) = 100n + 2n 2 = 2n 2 + 100n 7 60 [CS1102C AY0708S2 Lecture 5] Time Requirement ยก Knowing the number of operations required for an algorithm A, we can state that: ยข E.g. Algorithm A takes 2n 2 + 100n operations to solve problem of size n ยก If the time t needed for one operation is known, then we can state: ยข E.g. Algorithm A takes (2n 2 + 100n)*t time units ยก However, time t is a directly dependent on the factors mentioned earlier: ยข Computer and Programming Language ยก Instead of typing the analysis to actual time t, we can state: ยข Algorithm A takes time that is proportional to 2n 2 + 100n for solving problem of size n 8 60 [CS1102C AY0708S2 Lecture 5] Approximation of Analysis Results ยก Suppose the complexity of ยข Algorithm A is found to be 3n 2 + 2n + log n + 1/4n ยข Algorithm B is found to be 0.39n 3 + n ยก Intuitively, we know Algorithm A will outperform B ยข when solving larger problem i.e. larger n when solving larger problem i....
View
Full Document
 Spring '11
 dunnowho
 Analysis of algorithms, Analysis of Algorithm, CS1102C AY0708S2 Lecture

Click to edit the document details