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.
So what is an algorithm ? From Wikipedia, Algorithm is a self-contained step-by-step set of operations to be performed. Algorithms performÂ calculation,Â data 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:
- Take a calibrated container and fill it with water till 1 litre mark.
- Transfer the water to a pan and keep it on a gas burner.
- Keep the burner on, till the water boils.
- 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:
- Is it fast?
- Does it need fewer resources ?
- Is it easier to implement ?
- 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.
- Best case, worst case and average complexity.
Till then, happy coding and happy learning.