Before we can design or analyse algorithms we need a clear idea of what an algorithm is. This page gives a precise definition, the five properties every algorithm must have, and the extra qualities that make one algorithm better than another.
The idea
A widely used textbook definition (Cormen et al.) says the same thing in other words: 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.
Three points follow from the definition:
An algorithm is not a program. A program is an algorithm written in a particular programming language. The same algorithm can be written in C, Python or Java, or as pseudocode.
An algorithm solves a problem, and a problem has many instances. “Find the GCD of two numbers” is the problem; “find the GCD of 1071 and 462” is one instance. A correct algorithm must work for every legal instance.
The steps must be mechanical. No step may need intelligence, intuition or luck to carry out.
The five properties of an algorithm
Donald Knuth listed five properties that every algorithm must have. A procedure that fails any one of them is not an algorithm.
Property
Meaning in plain words
Example of failure
Finiteness
It always stops after a finite number of steps.
“Keep adding 1 until the number is negative” (starting from 1).
Definiteness
Every step is precisely defined; there is exactly one way to read it.
“Add a few numbers” — which numbers? how many?
Input
It has zero or more inputs, taken from a stated set.
— (an algorithm may have no input, e.g. “print the first 10 primes”)
Output
It produces at least one output that is related to the input.
A procedure that computes but never reports a result.
Effectiveness
Every step is basic enough to be done exactly, in finite time, by a person with pencil and paper.
“Write down the exact decimal value of 2” (it never ends).
Qualities of a good algorithm
The five properties decide whether something is an algorithm. The following qualities decide whether it is a good one:
Correctness — it gives the right output for every legal input. This is the first requirement; a fast wrong answer is useless.
Efficiency — it uses little time and memory.
Generality — it solves the whole class of problems, not just one case.
Simplicity and clarity — it is easy to understand, implement and check.
Key takeaways
An algorithm is a finite sequence of precise steps that solves every instance of a problem.
The five essential properties: finiteness, definiteness, input (zero or more), output (one or more), effectiveness.
A program is an algorithm written in a programming language; the algorithm is language-independent.
A good algorithm is also correct, efficient, general and clear.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Define an algorithm and list its five properties with one line each.
Show worked answer
An algorithm is a finite sequence of precise, unambiguous instructions that takes zero or more inputs and, after a finite number of steps, produces at least one output that solves a problem. Properties: (1) Finiteness — it stops after a finite number of steps; (2) Definiteness — each step is precisely and unambiguously defined; (3) Input — zero or more inputs from a stated set; (4) Output — one or more outputs related to the input; (5) Effectiveness — each step is basic enough to be carried out exactly in finite time.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-211/basics-of-an-algorithm-and-its-properties/what-is-an-algorithm/ to read this page.