Designing and refining algorithms
OCR J277 Paper 2 always includes algorithm-design questions. You need to be fluent in both pseudocode and flowcharts, and able to use a trace table to follow what an algorithm does step-by-step.
Pseudocode (OCR Reference Language)
Pseudocode is a structured English-like notation. OCR provides a Reference Language guide; the key conventions are:
- Assignment uses ← (or = in the exam where ← is unavailable). Example: total ← 0
- Selection uses IF … THEN … ELSE … END IF.
- Iteration uses FOR i ← 1 TO n … NEXT i, or WHILE … END WHILE, or DO … UNTIL.
- Input/output: INPUT and OUTPUT (or PRINT).
- Subroutines: FUNCTION name(parameters) … RETURN value … END FUNCTION; PROCEDURE name(parameters) … END PROCEDURE.
Flowcharts
| Symbol | Meaning |
|---|---|
| Oval (terminator) | START / END |
| Parallelogram | INPUT / OUTPUT |
| Rectangle | Process (assignment / calculation) |
| Diamond | Decision (yes / no, true / false) |
| Arrow | Flow of control |
A flowchart must have exactly one START and at least one END. Decision diamonds always have two outgoing arrows labelled with the conditions.
Trace tables
A trace table records the value of each variable after each step of an algorithm. Columns = variables (and any output); rows = steps.
Example — pseudocode (single-line form): total ← 0; FOR i ← 1 TO 3 do total ← total + i; NEXT i; OUTPUT total
| Step | i | total | OUTPUT |
|---|---|---|---|
| Start | — | 0 | |
| Loop i = 1 | 1 | 1 | |
| Loop i = 2 | 2 | 3 | |
| Loop i = 3 | 3 | 6 | |
| OUTPUT total | 6 |
Refining algorithms
After a first version, look for:
- Correctness — does it produce the right output for normal, boundary and invalid inputs?
- Efficiency — fewer steps, fewer variables, better data structure.
- Readability — meaningful identifiers, comments, broken into subroutines.
- Reusability — can a block be lifted into a function called from elsewhere?
Common OCR exam mistakes
- Using the wrong flowchart shape (rectangle for a decision, etc.).
- Forgetting to fill the trace table row when a variable changes mid-loop.
- Using "IF" without a matching "END IF", or "WHILE" without "END WHILE".
- Designing an algorithm with no terminating condition — the loop never ends.
AI-generated · claude-opus-4-7 · v3-ocr-computer-science-leaves