Analysis Of Algorithm|| Why It Is Important?

What is the Algorithm?

According to Wikipedia, “In mathematics and computer science, an algorithm is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computation”. We also discuss Analysis in this post

Now, breaking above definition in some parts,

  1. Well defined
  2. Instruction
  3. finite Sequence

When we write any program, let’s take a example

int fun(int a)
int sum = a++;
return sum;

In the above program, we are increasing the value of a by 1 after every time fun() is called, The Above algorithm is written to solve a problem i.e increasing value by 1 which consists of a well-defined sequence. Suppose above function may be written as

int fun(int a)
int sum = 0;
return sum;
 sum = a++;

Hence, the above function is not a well-defined sequence because it returns 0 every time instead of increasing value by 1. This is all about Algorithm, Now come to Analysis of Algorithm

Analysis of Algorithm?

Let’s see the two program written below,

int fun(int n)
return n*(n+1)/2;
int fun(int n)
int sum = 0;
for(int i = 0;i<n;i++)
sum = sum+i;
return sum;

Now, You understand that both of the above programs gives us the sum of the first n natural number, but how you analyze them. You may say we compare both algorithms according to their speed of execution, Yes you are right but on which factor speed of execution depends? So to understand we are going to know on which factor Algorithm execution depends

Algorithm execution speed depend on two factor

  1. Machine Speed
  2. Algorithm Time Complexity

Machine Speed

Suppose there are two Friend’s “A” and “B”, created a algorithm and both of them have their own machine

Speed of “A” machine is 10^5 and number of instruction in algorithm is 10^3;

Speed of “B” machine is 10^9 and number of instruction in algorithm is 10^10;

So, Execution speed of “A” algorithm in his Machine is .01 sec(10^3/10^5)

And, Execution speed of “B” algorithm in his Machine is 10 sec(10^10/10^9)

Here, we need to note some extra point,

  1. Speed of algorithm depends on machine speed
  2. Good Algorithm+Slow machine is better than Bad Algorithm+Fast Machine

Now, Calculate time of “A” algo on”B” speed and “B” algo on “A” speed and you will get a extra point to note

3. Good Algorithm + fast machine is awesome

But As a programmer you control only Algorithm speed you don’t have the power to make the machine faster. So we analyze our algorithm instead of focusing on machine power. Hope You understand why Analysis of Algorithm is important

Design Of Algorithm is not Analysis of Algorithm,

Algorithm Design is a specific instructions for completing a task. They’ve also been called “recipes”. For Completing a task in efficient way, we must analyze what type of design technique suits best.

Advantage of Analysis of Algorithm

  1. Writing an algorithm taking into consideration how much time it will take to run and how much memory it would require
  2. An inefficiently written program consumes a lot of processing power. Hardware stats need to be taken into consideration as well

Sudhanshu is Technology geek and also a pro pubg player. I like to create content in my free time that helps others. Currently pursuing BCA from Noida and operating Geekstocode

Leave a Comment

Your email address will not be published. Required fields are marked *