What is an algorithm?

What is an algorithm?


Merry’s mother asked her to prepare a cup of tea following the steps given below.

Step 1: Put half a cup of water in a pan.

Step 2: Put half a cup of milk in the pan.

Step 3: Add 1 teaspoon sugar and a pinch of dried tea leaves in the pan.

Step 4: Light the burner of the gas stove.

Step 5: Put the pan over the flame.

Step 6: Bring the mixture to boil. Let it boil for 2-3 minutes.

Step 7: Switch off the burner.

Step 8: Filter the tea in a cup using a sieve.

This step-by-step instruction of performing a task to get a work done is called an algorithm. Algorithms are used to define steps for calculations as well as processing of data. But, before writing an algorithm, you need to learn some basic terms.

  • Input or Read: It is used when the computer has to ask for some data.
  • Print or Write: It is used when computer has to give the solution or result.

For example, if you want to calculate a sum of two numbers (20 and 32), you need to follow the steps given below to get the result.

Step 1: Read the number ’20’.

Step 2: Read the number ’32’.

Step 3: Find the sum of the two numbers (20 + 32).

Step 4: Show the result ’52’.