What is an Algorithm?

posted Oct 20, 2013, 10:51 PM by Anupinder Singh   [ updated Mar 3, 2014, 2:29 AM by Anupinder Singh ]

Definitions

There are various definitions available for term Algorithm as:
  • "A set of rules for solving a problem in a finite number of steps" - Dictionary
  • "A set of steps that are followed in order to solve a mathematical problem or to complete a computer process" - Merriam-Webster
  • "An Algorithm is any well defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values as output"- refer to References
  • "A process or set of rules to be followed in calculations or other problem-solving operations, especially by a computer." - Google

Any of the above mentioned definition will work, and even all definitions provides a similar summary i.e. a set of well defined steps to solve a defined problem corresponding to provided inputs.

Five characteristics of an Algorithm are:

  1. Input: Accept Zero or more inputs externally.
  2. Output: Must produce at least one output as result of procedure.
  3. Definiteness: Each instruction must be clear and unambiguous.
  4. Finiteness: If all the instructions are traced in algorithm, then for all cases the algorithm must terminate after a finite number of steps.
  5. Effectiveness: Every instruction must be very basic so that it can be carried out  and must be feasible to perform on any machine.

One important point about algorithm, it is not a computer program. Instead it is a procedure written as pseudo code or English language type description, providing information about what calculations are to be performed and in which flow.

For Example : To add two numbers we can have an algorithm like:

English language Type

    1. Ask user to enter two integer numbers.
    2. Add both the integer numbers.
    3. Print the final sum value of two numbers

OR

Pseudo Code Type

    Algorithm SUM
        Input: Two Integer Numbers as ONE, TWO
        Output: sum of ONE & TWO as RESULT

        ONE <- User input required
        TWO <- User input required
        RESULT <- ONE + TWO
        return RESULT

OR
Flowchart Representation

In case you want to show it visually it can be represented as:


Even for some cases all the three types of defining the algorithm is used. I depends on what kind of document you are working on.