Published on

Behind The Algorithm #2 - What is an Algorithm?


In mathematics and computer science, an algorithm is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of specific problems or to perform a computation. - Wikipedia.


💁 Informally, Algorithm is...

Just a set of instructions to solve a particular problem or accomplishing some specific task. It could be as simple as step by step of how your grandma cooks your favorite meal.

But, in the context of this article, the algorithm is more like a computational procedure that takes some value as input and produces or doing some actions as output.

For example...

Given some words as an input: [tea, dear, own, eat, read, now], and we need to group those words so the expected output would be like this [[tea, eat], [dear, read], [own, now]]. This pattern is called Anagram, Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

Formally, we could define our problem to be written like this:

  • Input: Set of nn alphabetic words [tea, dear, own, eat, read, now].
  • Output: nn groups of words based on anagram pattern [[tea, eat], [dear, read], [own, now]].

How do we justify the correctness of an Algorithm?

We could say that an algorithm is correct if, for any given input or test case, the algorithm should return or doing some actions correctly.

But, sometimes we're not expecting our algorithm to be 100% correct. That's why there is a term called error rate. We would learn about it later in the next article.

How to write an Algorithm?

The algorithm could be specified in any language or anything that could provide a precise description of the procedure to be followed by human or computer, in the context of this article, a computer.

It's more like writing an instruction to be understood by your computer to solve your problem.

What problems could be solved by an Algorithm?

Any problems depend on the capability of the algorithm and the hardware that support the execution of that Algorithm.

The algorithm is essentials to our life right now. When you searching something on Google when you are watching videos on YouTube, scrolling content on Instagram, TikTok, etc. All of them are powered by an Algorithm.

From the algorithm to draw the UI of those applications on the screen of your smartphone until the algorithm to give you personalized content.

Beside those day-to-day problems...

Scientists, the government, the accountant also heavily using an algorithm to solve their particular problems. Because sometimes, it's just impossible or time-consuming to finish all of their tasks manually.

So, in my opinion...

Learning how to write a good algorithm is still worthwhile. It helps us to think in a very structured and efficient way to solve a particular problem.

And there are still a lot of problems in this world that are waiting to be solved. Maybe you are a software engineer, scientist, mathematician, game developer, believe me, it would help you to solve your problems more efficiently.

And also, Having a solid base of algorithmic knowledge and technique is one characteristic that separates the truly skilled programmers from the novices. - Introduction To Algorithm - Third Edition.

📔 Behind The Algorithm Series

  1. Behind The Algorithm #1 - Why do we need to be "Good" in writing Algorithms?
  2. Behind The Algorithm #2 - What is an Algorithm?
  3. Behind The Algorithm #3 - ⏱ Running Time & Time Complexity
  4. Behind The Algorithm #4 - 👨🏻‍💻 How to design an Algorithm?