ezoic

Friday, December 23, 2016

Analysis of algorithms

Analysis of algorithms can be divided into two parts, time complexity analysis and space complexity analysis.

time complexity

in computer science , the time complexity of an algorithm quantifies the amount of time taken by an algorithm to run as a function of the length of the string representing the input.



space complexity 

Space complexity is a measure of the amount of working storage an algorithm needs. That means how much memory, in the worst case, is needed at any point in the algorithm. As with time complexity, we're mostly concerned with how the space needs grow, in big-Oh terms, as the size N of the input problem grows.

Here are two examples for space complexity analysis

               int sum (int a[], int n)
              { int r=0;
                for ( int i=0; i<n; ++i)
              { r+=a[i];
              }
               return r;
              }

requires N units for a, plus space for nr and i, so it's O(N).

            int sum( int x, int y, int z)
              { int r=x+y+z;
                 return r;
               }


requires 3 units of space for the parameters and 1 for the local variable, and this never changes, so this is O(1).


And mainly you do the counting when analyzing the algorithms

This video showed it:


Here is a gentle guide



No comments:

Post a Comment

looking for a man

 I am a mid aged woman. I live in southern california.  I was born in 1980. I do not have any kid. no compliacted dating.  I am looking for ...