CIE AS & A Level Computer Science, section 9.2 (Algorithms)
What an algorithm is
An algorithm is a solution to a problem expressed as a sequence of defined steps. Each step must be clear and unambiguous, and the algorithm must finish (it must stop after a finite number of steps).
An algorithm can be written as structured English, a flowchart or pseudocode.
Identifiers
An identifier is the name of a variable, constant, array, procedure or function. A good name:
- describes the purpose of the data (
TotalMark, notx), - is consistent in style (such as CamelCase),
- does not use spaces or special characters, and does not clash with a keyword.
Identifier table
An identifier table lists every item of data used in an algorithm, with its data type and a description.
Problem: read three test marks and output the average.
| Identifier | Data type | Description |
|---|---|---|
Mark1, Mark2, Mark3 |
INTEGER | the three test marks input by the user |
Total |
INTEGER | the sum of the marks |
Average |
REAL | the mean mark |
Pseudocode using the table
INPUT Mark1
INPUT Mark2
INPUT Mark3
Total ← Mark1 + Mark2 + Mark3
Average ← Total / 3
OUTPUT Average
mark1, mark2, mark3 = 60, 72, 81
total = mark1 + mark2 + mark3
average = total / 3
print(average) # 71.0
Common mistake: using single letters for identifiers, which makes the algorithm hard to follow, or choosing the wrong data type in the table (for example INTEGER for an average that may have decimals). The mean needs REAL.
Exam tip: in an identifier table, include every variable and constant used. Use meaningful names, and check that each data type fits the values stored.
Check yourself
What is an algorithm?
A solution to a problem expressed as a sequence of defined steps.
Why should identifier names be meaningful?
It makes the algorithm easier to read, understand and maintain.
What does an identifier table contain?
The name, data type and description of each variable or constant used.