MCS-211 · Block 1 Unit 1

Basics of an Algorithm and its Properties

Section 1 of 9

Block 1 · Unit 1Basics of an Algorithm and its Properties12 min · Section 1 of 9

1.1What Is an Algorithm?

Covers IGNOU MCS-211 §1.0, 1.1

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.

PropertyMeaning in plain wordsExample of failure
FinitenessIt always stops after a finite number of steps.“Keep adding 1 until the number is negative” (starting from 1).
DefinitenessEvery step is precisely defined; there is exactly one way to read it.“Add a few numbers” — which numbers? how many?
InputIt has zero or more inputs, taken from a stated set.— (an algorithm may have no input, e.g. “print the first 10 primes”)
OutputIt produces at least one output that is related to the input.A procedure that computes but never reports a result.
EffectivenessEvery 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\sqrt{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 1 · multiple choice

Which property says that every step of an algorithm must have exactly one meaning?

Show answer

Answer: B. Definiteness

Definiteness means each step is precisely and unambiguously defined. Finiteness is about stopping, not about the meaning of steps.

Question 2 · multiple choice

How many inputs must an algorithm have?

Show answer

Answer: D. Zero or more

Knuth’s input property allows zero inputs (e.g. “print the first 10 primes”). “At least one” is a common but incorrect version.

Question 3 · multiple choice

A procedure says: “Start with x = 1. Repeat: x = x + 2. Stop when x is even.” Which property does it fail?

Show answer

Answer: C. Finiteness

x takes the values 1, 3, 5, 7, … and is always odd, so the procedure never stops. Each step is clear and basic, so definiteness and effectiveness are satisfied.

Question 4 · multiple choice

Which statement about algorithms and programs is correct?

Show answer

Answer: D. A program is an algorithm written in a specific programming language.

The algorithm is the method; the program is one implementation of it. The same algorithm can be written in many languages, so it is not tied to C.

Question 5 · multiple choice

The step “compute the exact decimal expansion of π” fails which property?

Show answer

Answer: A. Effectiveness

The step is clearly defined (definite) but it can never be completed exactly in finite time, so it is not effective.

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.

↑ ↓ move↵ openTab switch type