An algorithm is a set of step-by-step instructions used to solve a problem or complete a task.
Computers follow algorithms to perform different activities. Programmers write algorithms before creating computer programs so that the computer knows exactly what to do.
Algorithms are not only used in computers. People also use algorithms in everyday life when they follow instructions to complete tasks.
For example, making a cup of tea follows an algorithm:
-
Boil water.
-
Put a tea bag in a cup.
-
Pour hot water into the cup.
-
Add sugar or milk if desired.
-
Stir and drink.
Each step must be followed in the correct order. If the steps are not followed correctly, the result may not be successful.
In coding, algorithms help programmers plan how a program will work before writing the code.