¤ Home » Programming » What is an Algorithm?

What is an Algorithm?

An algorithm can be defined as a finite sequence of instructions for performing a task or solving a problem. The instructions must be unambiguous and have a clear stopping point. Algorithms can be expressed in any language, from natural languages like English or French to programming languages like FORTRAN, C, Pascal, Java, PHP, etc.

We use algorithms every day. For example, a recipe for baking a cake is an algorithm. Most programs, with the exception of some artificial intelligence applications, consist of algorithms. Inventing elegant algorithms i.e. writing algorithms that are simple and require the fewest steps possible, is one of the principal challenges in programming.

The basic instructions used by the algorithm should be elementary so that these can be carried out by a machine, viz. the Computer. These instructions can be - add, subtract, read a character, write a character, compare numbers and find out which is larger, etc. Even though these basic instructions are few, it is possible to carry out a large variety of data processing tasks by a permutation and combination of these elementary tasks or instructions.

At this point it is necessary to understand the essential characteristics of Computers, which are as follows:

A computer can be thought of as a slave which carries out instructions at a very high speed obediently, uncritically and without exhibiting any emotions. It is the task of a programmer to give extensive, detailed and correct instructions for solving a problem.

In order to carry out a task using a computer, the following steps are followed:

  1. The given task is analyzed.
  2. Based on the analysis an algorithm to carry out the task is formulated. The algorithm has to be precise, concise and unambiguous.
  3. The algorithm is eventually used as a reference to write the final computer program. (for more on this, read the beginners guide to writing Programs)
  4. The computer program is fed to the computer for execution. The computer interprets the program, carries out the instructions given in the program and computes the results.

Features of an Algorithm

While writing an algorithm, you must keep in mind the following basic features:

  1. A number of quantities are provided to an algorithm initially before the algorithm begins. These quantities are the inputs which are processed by the algorithm.
  2. An algorithm must result in one or more output(s). The outputs desired must therefore be identified.
  3. The processing rules specified in the algorithm must be precise, unambiguous and lead to a specific action. In other words the instructions must not be vague. It should be possible to carry out the given instruction.
  4. Each instruction must be sufficiently basic such that it can, in principle, be carried out in a finite time by a person with pen and paper.
  5. The total time to carry out all steps in the algorithm must be finite. An algorithm may contain repetitive type of instructions. This requirement implies that the number of repetitions must be finite.
  6. An algorithm must have one or more output.

To develop a better understanding of what we mean by this, let us look at two examples. The first example is not an algorithm, the second one is.

Example 1

This example is of a set of instructions that appear to be an algorithm, though it is not so.

Recipe for Bournvita Cake

Bengal gram flour 2 cups, sugar 2 cups, ghee 3 cups, milk ½ cup, Bournvita 6 tablespoons, Vanilla essence 5 drops, water ½ cup.


Step1: Warm 1 cup ghee. Put gram flour and fry for 2 minutes on low flame.

Step2: Separately dissolve Bournvita in warm milk and add vanilla essence.

Step3: Add 2 cups sugar in ½ cup water in a pan and warm it till sugar dissolves. Boil syrup till it become sticky.

Step4: Pour the prepared Bournvita in syrup and stir continuously.

Step5: Add fried gram flour to the syrup and continue stirring 15 to 20 minutes adding the remaining melted ghee until the mixture does not stick to the pan.

Step6: Pour the mixture on a plate smeared with melted ghee shaking while pouring to ensure uniform spreading.

Step7: After 10 to 15 minutes cut into 40 pieces.

40 pieces of Bournvita cake.


The above -

  1. is a sequence of instructions or procedure to solve the problem of making a Bournvita cake (steps 1 - 7).
  2. requires a set of inputs - the ingredients.
  3. produces an output - 40 pcs of cake.
  4. takes a finite time to execute the instructions & stop.

However, it requires someone to have a common cooking sense to execute these instructions. Instructions such as low flame and warm milk are not precise and require individual's judgment. How much quantity of vanilla essence is to be added is not specified. If you read carefully, you will notice several such instructions that are not precise & basic. Hence it does not qualify as an algorithm.

Example 2

This example is of a set of instructions that is truly an algorithm.

Instructions to knit a sweater

Needles No. 12 = 2
Wool 4 ply = 9 balls


Step1: Cast on 133 stitches

Step2: Repeat steps 3 and 4, 11 times

Step3: Knit 2, Purl 1

Step4: Purl 1, Knit 1

Step5: Knit 1, Purl 2



(Similar steps)

Step15: Cast off 133 stitches

Result: A Sweater


The above instructions are -

  1. Precise (unambiguous)
  2. Very few basic actions like Knit, Purl, Count, Cast on or off needles

By a permutation & combination of above elementary set of actions, an infinite number of patterns can be created. Due to the preciseness of instructions & a few basic tasks to be performed, it may be possible to design a machine to automate knitting.

A French engineer Jacquard designed a machine in 1801 on the above lines, which could perform the task of creating large number of patterns. This machine was similar to the modern day computers.

I believe the above would give you a fair understanding of what we mean by an Algorithm


comments powered by Disqus

Web Service Offers

Accounting System for Small Business
5,999 4,999 (16.67% off)
per Year

Ecommerce on the Cloud

An online store hosted on the Cloud. Sell unlimited products. Integrated business functions. Well-suited for high traffic website.

39,999 29,999 (25% off)

Ecommerce Premium

An e-commerce website well-suited for companies having a large portfolio of products. Sell unlimited products. Manage both offline and online sales from one system.

40,000 25,000 (37.5% off)

Ecommerce Business

Launch your online business. Sell up to 5000 products. Collect payment via multiple online and offline payment methods.

35,000 25,000 (28.57% off)

Ecommerce Pro

Get a Mobile friendly online store front. Sell up to 1000 products.

35,000 25,000 (28.57% off)

Ecommerce Starter


35,000 25,000 (28.57% off)

Website on the Cloud

Custom built, responsive corporate website hosted on the cloud. Mirrored on 3 servers. Includes visitor signup with CRM functions/

19,999 9,999 (50% off)

Website Corporate

Custom built, responsive corporate website with CRM. Our most popular website plan.

19,000 9,000 (52.63% off)

Website Business - 1000 Pages

Affordable website plan for small business. Custom built - quick page download, automatic SEO, mobile & tablet friendly.

18,000 8,000 (55.56% off)

Website Business - 500 Pages


17,500 7,500 (57.14% off)

Website Business - 100 Pages


17,000 7,000 (58.82% off)

Website Business - 50 Pages


16,500 6,500 (60.61% off)

Website Business - 25 Pages


16,000 6,000 (62.5% off)

Website Starter - 5 Pages

Get started with your own website at most affordable cost.

15,000 5,000 (66.67% off)

Looking to build a website?

About the Author

Rajeev Kumar
CEO, Computer Solutions
Jamshedpur, India



Copyright © How2Lab.com. All rights reserved.

Refer a friend | Sitemap | Disclaimer | Privacy Policy