Form 4 · Chapter 1

Algorithms

An algorithm is an ordered set of steps for solving a problem, and it can be represented using pseudocode or a flowchart before being turned into program code.

What Is an Algorithm?

An algorithm is an ordered, clear and finite set of steps for solving a problem or carrying out a task. The steps must be arranged in the correct order, because the wrong order gives the wrong result. A good algorithm has these features: clear (unambiguous) steps, defined input and output, and it must terminate after a finite number of steps.

Key idea

An algorithm is a finite, ordered sequence of steps that solves a problem. It is independent of any programming language.

Pseudocode

Pseudocode is a way of writing an algorithm using simple, structured everyday language rather than a real programming language. It helps a programmer plan the logic without worrying about the grammar of a particular language. Keywords such as START, READ, IF, PRINT and END are commonly used.

Example

Pseudocode to find the area of a rectangle:

START
  READ length, width
  area = length * width
  PRINT area
END

Flowcharts and Their Symbols

A flowchart is a diagram that represents an algorithm using standard symbols joined by arrows:

  • Oval (terminal) — marks Start or End.
  • Parallelogram — represents input/output, such as reading or displaying data.
  • Rectangle — represents a process or calculation.
  • Rhombus (diamond) — represents a decision with a yes/no answer.

Tracing an Algorithm

Tracing means following each step of an algorithm one by one using sample values to check whether the output is correct. It is done by listing the value of each variable at every step. Tracing helps catch logic errors before the code is even written.

Remember

The order of steps in an algorithm matters greatly — changing the order of steps can change the result completely.

Stuck on this topic? A verified JomKelas tutor can walk you through it.

Find a verified tutor