Skip to content

Computer Science · Ch 4 — Introduction to Problem Solving

Why do we need an Algorithm?

4.3.1

Why do we need an Algorithm?

A programmer writes a program to make the computer perform certain tasks, and the computer then follows the steps written in that program code. But before actually writing the code, the programmer first prepares a roadmap of the program to be written. Without a roadmap, the programmer may not be able to clearly visualise the instructions that need to be written, and can end up producing a program that does not work as expected. That roadmap is precisely the algorithm — the building block of a computer program.

Where the word "algorithm" comes from

The term traces back to the Persian astronomer and mathematician Abu Abdullah Muhammad ibn Musa Al-Khwarizmi (c. 850 AD): the Latin rendering of "Al-Khwarizmi" was "Algorithmi", and from it the modern word derives.

Algorithms are everywhere

Familiar computer-based activities all rest on algorithms:

  • searching with a search engine
  • sending a message
  • finding a word in a document
  • booking a taxi through an app
  • performing online banking
  • playing computer games

From algorithm to program

Writing an algorithm is generally regarded as the first step of programming. Once a correct algorithm exists for a problem, the computer program can be written in a high level language to give the computer its instructions. And if the algorithm is correct, the computer will run the program correctly, every time. The purpose of using an algorithm, then, is to increase the reliability, accuracy and efficiency of obtaining solutions.

(A) Characteristics of a good algorithm

  • Precision — the steps are precisely stated (clearly defined).
  • Uniqueness — the result of each step is uniquely defined, and depends only on the input and on the results of the preceding steps.
  • Finiteness — the algorithm always stops after a finite number of steps.
  • Input — the algorithm receives some input.
  • Output — the algorithm produces some output.

(B) What to identify while writing an algorithm …