An algorithm is a step-by-step execution to perform a task. The task can be anything either to use in programming languages or our daily life.
If we say in Programming languages, we can say the Algorithm is the heart of it. Without an Algorithm, no program or coding can be done.
The algorithm gives the programmer a decision at any step where to go according to requirement.
Importance of Algorithm in our daily life
If we see the importance of Algorithm in our daily lives, we will see that there is an algorithm at every step. Like if we have to switch ON the light then the algorithm will be
Step 1: If there is light coming from the powerhouse to our home.
Step 2: if the light is there, then we will switch ON the light button.
Step 3: if the Light bulb is in working condition, then the bulb will be ON otherwise not.
See, in the very small example, there is a proper algorithm. So in every aspect of life, if we see there is an algorithm to execute any task.
What is an Algorithm in programming?
To solve any task in programming task, the algorithm provides a vital role, without an algorithm, no one can write any piece of programming.
When we have to solve any type of requirement in programming languages, we first create some algorithm that how it will be solved.
Algorithm Example in Programming
Let’s see a simple Algorithm example in a Programming language, take a very simple example of adding two numbers.
Algorithm to add two numbers
Step 1: Take two variables say A and B.
Step 2: assign values to these variables say A=10, B=15
Step 3: add these two variables and save them in a new variable say Sum like
Sum=A+B
To solve a simple program of addition we need an algorithm. It is a very simple example if we take more complex programming requirements we need a more complex algorithm.