Algorithms · Cambridge syllabus 7.2, 7.9, 8.1 · Lesson 1 of 3
Algorithm Representation
Pseudocode expresses algorithmic logic without requiring one programming language’s exact syntax, and 0478 uses Cambridge's own conventions: upper-case keywords, ← for assignment and Pascal-case identifiers. Flowcharts show the same control flow with six symbols: terminators for start and stop, process rectangles, subroutine boxes, input/output parallelograms, decision diamonds and flow lines. Both must make order and conditions unambiguous.
By the end, you can
- Write algorithms using structured pseudocode.
- Use precise mathematical and logical notation.
- Represent input, processing and output clearly.
- Represent algorithms using the standard flowchart symbols: terminator, process, subroutine, input/output, decision and flow line.
- Use sequence, selection and iteration in flowcharts.
- Trace flowchart execution.
Pseudocode
Pseudocode is a way of writing an algorithm in structured English. It uses the control structures of a programming language so the logic is exact, but it is not tied to any one language and is not run by a computer.
Cambridge sets out exactly how 0478 pseudocode is written. Keywords are in capitals. Identifiers use Pascal case, starting with a capital letter, such as Total or NumberOfPupils. Assignment uses an arrow: Total ← 0 means put zero into Total. Input and output are written INPUT Mark and OUTPUT Average. Arithmetic uses + − * / and ^. Comments start with //.
Selection is written IF condition, then THEN on the next line, the statements, an optional ELSE, and ENDIF, with THEN and ELSE indented two spaces. Counted repetition is FOR Counter ← 1 TO 10, ended by NEXT Counter; conditional repetition is WHILE condition DO with ENDWHILE, or REPEAT with UNTIL condition. The statements inside each block are indented so that its extent is visible.
The average algorithm written out becomes: Total ← 0, then INPUT Count, then FOR Index ← 1 TO Count, INPUT Mark, Total ← Total + Mark, NEXT Index, then Average ← Total / Count, then OUTPUT Average.
Two mistakes lose marks routinely. The first is vagueness: work out the average is not a step, because it does not say how. The second is leaving a loop or an IF unterminated, so that nobody can tell where the block ends.
Comparison uses = and the relational operators; assignment uses the arrow. Precision is required: Mark > 50 is acceptable, but mark is more than fifty is not.
Worth remembering
- Upper-case keywords, Pascal-case identifiers, ← to assign, * and / for arithmetic.
- Total ← 0 assigns; IF, WHILE, FOR and REPEAT are closed by ENDIF, ENDWHILE, NEXT, UNTIL.
- Every step must say how, not merely what.
Flowcharts
A flowchart shows an algorithm as a diagram, with the shape of each box saying what kind of step it is. It makes the flow of control visible at a glance, which pseudocode does not.
The symbols are fixed, and there are six. A rounded rectangle, the terminator, marks the start and the stop, and every flowchart has exactly one start. A parallelogram is input or output. A rectangle is a process, such as a calculation or an assignment. A rectangle with an extra line down each side is a subroutine: a call to a separate flowchart, drawn on its own. A diamond is a decision holding a question with a yes or no answer, and it must have exactly two arrows leaving it, labelled Yes and No. Flow lines, arrows, join the boxes and show the direction of flow.
The three structures have recognisable shapes. Sequence is a straight run of boxes. Selection is a diamond whose two branches separate and then rejoin below. Iteration is a diamond with one branch looping back up to a point above it — which is the only place an arrow ever goes upwards, so a loop is easy to spot.
Tracing one means starting at the terminator and following the arrows with a specific set of values, taking whichever branch the condition gives and writing down each variable as it changes. Doing this with a value that should loop several times and a value that should not loop at all catches most errors.
The common faults are a decision with unlabelled branches, a decision with three arrows out, and a loop whose condition can never become false — which is an infinite loop, and is as visible on the diagram as it is fatal in the program.
Worth remembering
- Terminator, input/output, process, subroutine, decision and flow line.
- A decision has exactly two labelled branches; a loop is an arrow going back up.
- Trace with real values, including one that does not enter the loop at all.
Worked example
IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Retry" ENDIF selects one output according to a condition. THEN and ELSE each go on a line of their own, indented two spaces, and the statements under them four.
Practice
Warm-up · not marked
Check your understanding
Answer in your own words, then compare with the worked answer. Nothing here is saved or scored.
Worked answer
A decision diamond, with clearly labelled outgoing branches.
Check your method, units and explanation against it.
Marked practice
Set 1 of 5 · easiest first · Checked as you go, with the worked answer. Sign in or create a free account to save your progress.