Algorithmics–Science and Art

Algorithmics – The science of algorithms. I feel its not just science, but an art as well; and like any other art it needs special skills. Knowing few basic concepts would take us far enough, but that’s it. If you want to go beyond, it needs a special skill and that I discovered numerous times while developing many solutions over past 8+ years of the developer experience that I have.

To recap and brush up on my algorithmic skills, I decided to document it in a diary and hence this mini series on algorithms starts.

In this post, I would quickly

  • Define Algorithm.
  • Define what is a good algorithm.

Define Algorithm

So what is an algorithm ? From Wikipedia, Algorithm is a self-contained step-by-step set of operations to be performed. Algorithms perform calculationdata processing, and/or automated reasoning tasks. Of course, we use algorithm to solve a problem.

Suppose the problem at hand is to boil 1 litre of water. Then the steps to solve can be:

  1. Take a calibrated container and fill it with water till 1 litre mark.
  2. Transfer the water to a pan and keep it on a gas burner.
  3. Keep the burner on, till the water boils.
  4. Finally we have boiled water.

The above steps to solve the problem (boil 1 litre of water) can be though of an algorithm to boil the water.

What is a good algorithm?

Now, with above algorithm, though the problem is solved. Someone, might want to use microwave to boil the water, rather than using gas burner and then there might be arguments, discussions and debates as to which way is better. The same goes with algorithms as well. A problem can be solved by many approaches and hence there is always a case that one approach may be better and more efficient than other and so on and so forth. So the question arises, what is a good algorithm? Here are the questions we should ask:

  1. Is it fast?
  2. Does it need fewer resources ?
  3. Is it easier to implement ?
  4. Is it easier to maintain?

If answer to above 4 questions are yes, we are in good hands and same questions can be used to compare different algorithms.

Of these 4 questions #1 & #2 are most important and  they determine how good an algorithm is.

In the next post, we would see how we can measure how fast an algorithm is and how much resources it would need and then would go on to define

  • Various ways of measuring the algorithm.
  • Complexity.
  • Best case, worst case and average complexity.

Till then, happy coding and happy learning.