CIE AS & A Level Computer Science, section 9.2 (Algorithms)
Three ways to describe an algorithm
- Structured English: short, numbered statements in plain English, using words like IF, ELSE and REPEAT.
- Flowchart: a diagram using standard symbols joined by arrows to show the flow of control.
- Pseudocode: code-like statements (see the previous page).
Flowchart symbols
| Symbol | Shape | Use |
|---|---|---|
| Terminator | rounded rectangle (oval) | START and END |
| Process | rectangle | a calculation or assignment |
| Input/output | parallelogram | reading or displaying data |
| Decision | diamond | a question with two exits (Yes and No) |
| Subroutine | rectangle with double side lines | calling a procedure or function |
| Flow line | arrow | the direction of flow |
One problem in all three forms
Problem: read a number and output whether it is even or odd.
Structured English
- Read the number.
- Divide the number by 2 and find the remainder.
- If the remainder is 0, output "even", otherwise output "odd".
Flowchart (as text)
Pseudocode
INPUT Num
IF Num MOD 2 = 0 THEN
OUTPUT "even"
ELSE
OUTPUT "odd"
ENDIF
Converting between forms
- To write pseudocode from a flowchart, follow the arrows: each decision becomes an
IF(or the condition of a loop), and each box becomes a statement. - To draw a flowchart from pseudocode, draw a symbol for each statement in order, with a diamond for each
IFor loop condition.
Common mistake: giving a decision diamond only one exit, or no labels. Every decision needs two labelled exits (Yes and No). Also, use the correct shapes: a parallelogram for input and output, not a rectangle.
Exam tip: when drawing a flowchart, start at a terminator, label the decision exits, and make sure every path leads to the END. When converting, check the pseudocode follows every path.
Check yourself
Which flowchart symbol is used for a decision?
A diamond.
Which flowchart symbol is used for input and output?
A parallelogram.
How many exits does a decision symbol have?
Two, labelled Yes and No (or True and False).