An algorithm is a set of well-defined instructions to solve a particular problem.
Recipe Analogy
Let's suppose u have to make a dish so u have a set of ingredients, then u follow the recipe by following step by step in the sequence, and the final result is the tasty dish.
Now let's suppose u have to make noodles, so in the first diagram u can see u have some set of instructions, and n the second step, u have step by step process to make noodles and the final output is in the form of tasty noodles.
Programming Algorithms
Let's suppose we have a problem with ''add two numbers''.
Here, in the above example. We have two numbers 'a' and 'b' as a set of instructions, then we have to create an algorithm by following step by step process in sequence first adding numbers using the plus operator, and then the last step is the return of the value and our output is the total value by adding a with b.
Characteristics of Algorithms
Well-defined inputs and outputs. (So in the above example u can see that we have to add two numbers a and b which are inputs and our output is the sum of these two numbers. So, here is our first step lies correct).
Each step should be clear and unambiguous. (U can see in the above example that in our algorithms sequence our first step is to add numbers using the + operator and the second step is to return the value of those sums. So, here our second characteristic lies true and clear).
Language Independent. (That means we have to create an algorithm that should execute on every programming language, in simple words that means if you are writing an algorithm in JavaScript language then the same algorithm logic should work on any other programming language as well).
Why Algorithms?
So, why should we learn algorithms? The answer is simple
As a developer, you will come across a problem that needs to be solved.
Learning algorithms means u will get insight into how to efficiently solve those problems.
One problem can be solved in many ways using algorithms, which means if u stuck on one road u can take the second road to reach your destination ๐.
Every algorithm comes with its own tradeoffs when it comes to algorithms, but HOW? Which I will discuss in the next article.