AQA GCSE Computer Science (8525), section 3.1.1 (Representing algorithms)
Ways to show an algorithm
An algorithm can be written in different ways. In the exam, the question tells you which form to use: pseudo-code, program code or a flowchart.
Pseudo-code
Pseudo-code is a way of writing an algorithm using short, clear statements that look like a program but do not follow the rules of any one programming language. AQA exam questions use the AQA pseudo-code. Where a question asks you for pseudo-code, you may answer in any suitable format.
total ← 0
FOR i ← 1 TO 3
OUTPUT "Enter a mark"
mark ← USERINPUT
total ← total + mark
ENDFOR
OUTPUT total
Things to notice:
←means assign (store the value on the right in the variable on the left).- Keywords such as
FOR,ENDFOR,IFandENDIFare in capitals. - Statements inside a structure are indented.
Program code
The same algorithm written in Python:
total = 0
for i in range(3):
mark = int(input("Enter a mark: "))
total = total + mark
print(total)
Flowcharts
A flowchart shows an algorithm as a diagram using standard symbols joined by arrows that show the order.
| Symbol | Shape | Use |
|---|---|---|
| Start or stop | rounded box (terminator) | marks the start and end |
| Process | rectangle | an action, such as total ← total + mark |
| Input or output | parallelogram | reading or displaying data |
| Decision | diamond | a yes/no question, with an arrow out for each answer |
| Subroutine | rectangle with extra side lines | calls a subroutine |
| Flow line | arrow | shows the direction |
Example flowchart in words
An algorithm that checks whether a number is positive:
The diamond has two arrows out, labelled Yes and No. The two routes join up again before the end.
Choosing a method
- Flowcharts show the flow clearly, but take space for large algorithms.
- Pseudo-code is quick to write and close to real code.
- Program code can be run and tested.
Designing an algorithm systematically
- Understand the problem: what are the inputs and the outputs?
- Decompose it into steps.
- Write the steps in pseudo-code or as a flowchart.
- Trace it with test data to check it works.
- Write it as program code, then test and refine it.
Common mistake: drawing a decision diamond with only one arrow out. A decision always needs at least two (Yes and No). Also, on a flowchart, remember to put arrowheads on every line, and to start and end with the terminator symbol.
Exam tip: the exam tells you what form of answer is expected. If it asks for a flowchart, use the correct symbols; if pseudo-code, you do not need the exact AQA wording, but your logic must be clear and indented.
Check yourself
Which flowchart symbol is used for a decision?
A diamond.
What does the symbol ← mean in pseudo-code?
Assignment: the value on the right is stored in the variable on the left.
Name two ways, other than program code, that an algorithm can be shown.
Pseudo-code and a flowchart.