An algorithm is a finite, unambiguous sequence of steps for solving a problem or performing a task. A computer program is an implementation of one or more algorithms written in a programming language so that a computer can execute them.
This distinction is part of IB Digital Society subtopic 3.2 Algorithms, which is shared by SL and HL students.
An algorithm describes the logical method independently of a particular programming language. For example, an algorithm for finding the largest number in a list could state:
- Treat the first number as the largest.
- Compare it with each remaining number.
- Replace the stored number whenever a larger one is found.
- Output the stored number after all comparisons.
A programmer could implement these steps in Python, Java, or another language. Each implementation would be a different program, even though all could use the same underlying algorithm. The program must also follow the language's syntax and may include input handling, error checking, storage, and a user interface.
| Feature | Algorithm | Computer program |
|---|---|---|
| Purpose | Defines steps for solving a problem | Instructs a computer to perform tasks |
| Form | Natural language, pseudocode, or flow chart | Source code in a programming language |
| Execution | May be followed by a person or machine | Must be translated or interpreted for execution by a computer |
| Language dependence | Usually language-independent | Written for a specific programming language |
| Relationship | Provides the logical method | Implements one or more algorithms |
A common misconception is that an algorithm must be computer code. This is incorrect: code is only one possible representation or implementation of an algorithm.
In an IB exam, distinguish requires you to make the differences clear by referring to both terms. Define each precisely, then explain that the algorithm supplies the logical steps while the program expresses executable instructions in a specific programming language.