What is Algorithm?

What is Algorithm?

Algorithms

The word algorithm is very familiar to everyone who is into programming.

Algorithm is one of the first things taught at school/college before taking a dive into writing the very first program.

At that time the power of algorithm is not understood as it should be. Algorithms are the foundation to the solution of all the problems.

The power of algorithm is realized when working with huge datasets where we need the task to be done with great speed and accuracy.

If proper algorithms are not written for the problem then even the fastest computer with the highest hardware configurations would fail to work for huge datasets or as the number of input grows significantly.

Let us take a look into the definition of Algorithm just like we do before starting a new topic.

An algorithm is any well-defined computation procedure that takes some value, or set of values, as input and produces some value , or set of values , as output.

An algorithm is thus a sequence of computational steps that transforms the input to output.

For example –

Consider a problem of sorting N numbers a1,a2,a3…aN

Input – a1 ,a2 ,a3 , … , aN

Output – a1’ , a2’ , a3’ , … ,aN’ such that a1’ < a2’ < a3’ … aN’

If we closely look into the output it is nothing but one of the permutations of the sequence of N numbers.

The input sequence is called the instance of the sorting problem. The input satisfies whatever constraints are imposed in the problem statement.

As we just saw that algorithms are sequence of steps that transforms an Input to Output then what is the need to understand algorithm since there are lot of things which transforms an input to an output.

Let us take this example – Say , you want to purchase a laptop so that you can manage your day to job , study , play games etc …

Would you just go to the store and pick up any laptop ?

Obviously not, you would look for certain things like good processor, RAM, Storage etc…

Well any laptop could give you the functionalities you need but still you choose the one with certain attributes depending on the workload or the task you would be performing on your laptop and also thinking about the range of tasks you may perform in the near future.

You can think in a very similar way about algorithms.

When trying to develop an algorithm or choosing an algorithm that you would choose for your problem say the sorting problem we discussed above , your decision would depend upon certain factors like –

  1. The number of Items to be sorted

  2. The extent to which the items are already sorted

  3. Possible restrictions on the item values

  4. The architecture of the computer

  5. The kind of storage devices to be used – main memory , disks

  6. And above all you would choose an algorithm that gives you the correct value for all possible combinations of the input.

However there may be some exceptional scenarios where you would choose and algorithm that may not give correct result for some of the possible inputs and in that case you would want to control the error rate for the small set of inputs with incorrect results and handle those scenarios. And you would only choose this approach if the algorithm performs really great with the inputs for which it gives correct result.

Why are algorithms important ?

Algorithms are present almost everywhere in problem solving.

Taking the example of buying a laptop the hardware design of the systems uses algorithms.

You want the good user interface , the design of the graphical user interfaces relies on algorithm. Algorithms are involved in processing the languages in which the softwares are written by the compiler , assembler or interpretors so that we can run on your computer.

Algorithms can in fact be considered as a technology for problem solving techniques like the technologies involved around almost everything around you.

Choosing the right algorithm for your problem is very important to get the correct result with huge dataset and with great performance. It cannot be ignored and should be well designed while developing software systems.

We would be looking into some of the algorithms in the upcoming posts which would give us a better idea of the power of algorithms and the parameters to measure the algorithms just as well measure the configurations while buying a computer.

Conclusion

We have covered the following in this post -

  1. What is an Algorithm ?

  2. Why do we need Algorithm and What is the importance of Algorithm ?

Book for Reference

Introduction to Algorithm

Please share the post by clicking the social media icons at the beginning of the post.

Thank you for reading and see you in the next post !👋