Lesson 2 of 8
Algorithms: Lesson 2

Representing Algorithms

Learn to read and write pseudocode and flowcharts - the two universal tools for representing algorithms before coding. Toggle between pseudocode styles to match what appears on your exam papers.

50 minutes Pseudocode toggle included
Pseudocode style: Saved automatically

Before writing a single line of real code, professional developers design their algorithms in a language-neutral form. Pseudocode lets you think through the logic without worrying about Python syntax rules. Flowcharts turn the same logic into a visual diagram where loops and branches are immediately visible. Both appear heavily in exam questions - you must be able to read them, trace them, write them and correct errors in them.

Think about it: Write down in plain English, as precisely as you can, how to make a cup of tea. Now look at your instructions. Where are the decisions ("if the water is not boiling yet")? Where are the loops ("stir three times")? How could you make your instructions precise enough that a machine with no common sense could follow them? That is exactly the problem pseudocode is designed to solve.
Terms you need to know
Pseudocode
Structured, English-like notation for writing algorithms. Not a real language - cannot be run by a computer.
Flowchart
A visual algorithm representation using standardised shapes connected by arrows to show the flow of execution.
Assignment
Storing a value in a variable. AQA uses ← (left arrow). OCR uses = (equals).
Trace table
A table tracking variable values at each step of an algorithm - used to verify correctness without running the code.
Selection
Choosing which path to follow based on a condition. Represented by IF/ELSE in pseudocode and a diamond in flowcharts.
Iteration
Repeating a block of steps. Count-controlled (FOR loop) or condition-controlled (WHILE loop).
The language of algorithms

Pseudocode sits between natural language and real code. It is precise enough to describe an algorithm unambiguously, but flexible enough that you do not need to worry about compiler rules. Two widely-used styles in UK exams differ mostly in capitalisation and the assignment operator.

ConceptAQA styleOCR style
Assignmentx ← 5x = 5
Inputx ← USERINPUTx = input("Enter:")
OutputOUTPUT xprint(x)
If/ElseIF cond THEN ... ELSE ... ENDIFif cond then ... else ... end if
Count loopFOR i ← 1 TO 10 ... ENDFORfor i = 1 to 10 ... next i
Condition loopWHILE cond ... ENDWHILEwhile cond ... end while
SubroutineSUBROUTINE name() ... ENDSUBROUTINEprocedure name() ... endprocedure
FunctionFUNCTION name() ... ENDFUNCTIONfunction name() ... endfunction
ReturnRETURN valuereturn value
Exam angle

Your exam uses one consistent pseudocode style throughout. Focus on the one matching your specification. The logic is always identical across both styles; only the notation differs. Toggle between styles on this page to see this clearly - every algorithm is logically the same.

Reading and writing pseudocode

Example 1: Find the larger of two numbers

// Find the larger of two numbers (AQA style)
OUTPUT "Enter first number: "
a ← USERINPUT
OUTPUT "Enter second number: "
b ← USERINPUT
IF a > b THEN
    OUTPUT "Larger: " + a
ELSE
    OUTPUT "Larger: " + b
ENDIF
# Find the larger of two numbers (OCR style)
print("Enter first number: ")
a = input()
print("Enter second number: ")
b = input()
if a > b then
    print("Larger: " + a)
else
    print("Larger: " + b)
end if

Example 2: Sum numbers 1 to 10 using a FOR loop

total  0
FOR i  1 TO 10
    total  total + i
ENDFOR
OUTPUT total    // outputs 55
total = 0
for i = 1 to 10
    total = total + i
next i
print(total)    # outputs 55

Example 3: Validation loop - keep asking until the user enters a positive number

number  -1
WHILE number <= 0
    OUTPUT "Enter a positive number: "
    number ← USERINPUT
ENDWHILE
OUTPUT "Valid: " + number
number = -1
while number <= 0
    print("Enter a positive number: ")
    number = input()
end while
print("Valid: " + number)
Why initialise number to -1?

The WHILE condition is checked before the loop body executes. By initialising number to -1 (a value that will definitely fail the condition), we guarantee the loop body runs at least once and actually asks the user for input. Without this initialisation, number would be undefined when the condition is first checked.

Visualising algorithm structure

Flowcharts show the same algorithm as pseudocode but in visual form. Each shape has a precise, standardised meaning and must not be used for anything else. Arrows show the direction of execution. Loops are shown by arrows pointing back up to an earlier shape.

AppearanceShape nameMeaning
TextOvalStart or End (terminal) - every flowchart must have exactly one Start and one End
TextRectangleProcess: any action such as assignment, calculation, updating a variable
Cond?DiamondDecision: a condition with exactly two exits - Yes and No (or True and False)
In/OutParallelogramInput from the user or output to the screen
Flow arrowShows the direction of execution between shapes
Converting between pseudocode and flowcharts

IF statement: becomes a diamond with two branches (Yes/No) that rejoin below the diamond.

WHILE loop: becomes a diamond where the No exit leads downward (out of the loop) and the Yes exit leads into a process box, with an arrow looping back up to the diamond.

FOR loop: initialise counter (process box), check counter (diamond), body (process box), increment counter (process box), arrow back to the diamond.

Exam angle

Common exam tasks: (1) Draw a flowchart for a given algorithm. (2) Convert a flowchart to pseudocode. (3) Trace a flowchart with given inputs and write the output. (4) Identify and correct an error in a flowchart. Always use the correct shapes and label both exits of every diamond.

Verifying algorithms step by step

A trace table (or dry run) tracks the values of all variables as an algorithm executes, one statement at a time. It is how you verify an algorithm is correct without running it - and it appears in almost every algorithms exam question.

Rules: one column per variable plus one for output. One row per significant state change. Never skip steps. If a variable does not change in a particular step, leave the cell blank (examiners read the last value written in that column).

Trace this algorithm with a = 14 and b = 4:

a ← USERINPUT   // 14
b ← USERINPUT   // 4
WHILE a > b
    a  a - b
ENDWHILE
OUTPUT a
a = input()   # 14
b = input()   # 4
while a > b
    a = a - b
end while
print(a)
Stepaba > b?Output
Input144--
Check 1144True-
Iteration 1104True-
Iteration 264True-
Iteration 324False - exit-
Output24-2

The algorithm repeatedly subtracts b from a until a is smaller than b. This computes 14 MOD 4 = 2 (the remainder when 14 is divided by 4).

Trace this algorithm yourself
total  0
count  1
WHILE count <= 4
    total  total + count
    count  count + 1
ENDWHILE
OUTPUT total
total = 0
count = 1
while count <= 4
    total = total + count
    count = count + 1
end while
print(total)

What is the final value output by this algorithm?

Test yourself

1. Which flowchart shape represents a decision?

A diamond represents a decision with two exits: Yes and No. A rectangle is a process, a parallelogram is input/output, and an oval is start or end.

2. In AQA pseudocode, how do you store the value 10 in a variable called score?

AQA pseudocode uses ← for assignment. So score ← 10 stores 10 in score. OCR uses = for assignment. Neither uses SET or :=.

3. What is the purpose of a trace table?

A trace table (dry run) manually tracks every variable change step by step to verify the algorithm is correct without running the code. It is how you find logic errors.

4. What happens when execution reaches ENDFOR (AQA) / next i (OCR)?

ENDFOR increments the loop counter and sends control back to the FOR line. If the counter is still within range, the body runs again. If the counter has exceeded the end value, execution continues after ENDFOR.

5. A validation loop must keep asking for input until the user enters a value between 1 and 10. Which loop type is most appropriate?

A WHILE loop is correct. We cannot predict how many invalid inputs the user will enter, so we cannot use a FOR loop (which requires a known number of iterations). The WHILE loop repeats as long as the input is invalid and exits naturally when a valid input is given.
Challenge question

The following pseudocode is intended to sum all odd numbers from 1 to 99. Trace the first three iterations and determine whether it is correct. If not, identify the error and write a corrected version.

total  0
FOR i  1 TO 99
    IF i MOD 2 = 0 THEN
        total  total + i
    ENDIF
ENDFOR
OUTPUT total
Trace - first three iterations:
i=1: 1 MOD 2 = 1 (not 0) - condition FALSE, total stays 0.
i=2: 2 MOD 2 = 0 - condition TRUE, total = 0+2 = 2.
i=3: 3 MOD 2 = 1 - condition FALSE, total stays 2.

Error: The condition i MOD 2 = 0 selects even numbers, not odd. The algorithm sums 2+4+6+...+98 = 2450, not 1+3+5+...+99 = 2500.

Fix: Change the condition to i MOD 2 = 1 (or i MOD 2 <> 0).
Printable Worksheets

Practice what you have learned

Three levelled worksheets. Download, print and complete offline.

Recall
Pseudocode and Flowchart Basics
Shape identification, syntax matching and keyword fill-in activities.
Download
Apply
Trace Tables and Conversion
Complete three trace tables, then convert a flowchart to pseudocode and vice versa.
Download
Exam Style
Exam-Style Questions
Trace a 20-line algorithm, identify two flowchart errors and write pseudocode for a given problem.
Download
Lesson 2 - Algorithms
Representing Algorithms
Starter activity
Write "Make a cup of tea" on the board. Ask students to write every step as precisely as possible. Collect examples and highlight: vague steps ("heat water" - to what temperature?), missing decisions ("if no tea bag is available..."), missing loops ("stir until dissolved"). Use this to motivate why pseudocode needs precise keywords rather than informal language.
Lesson objectives
1
Define pseudocode and explain why it is preferred for algorithm design over real code.
2
Read and write pseudocode using correct notation for assignment, input, output, selection and iteration.
3
Identify all five standard flowchart shapes and state the purpose of each.
4
Complete a trace table for a given algorithm with supplied input values.
5
Convert between pseudocode and flowchart representations of the same algorithm.
Key vocabulary
Pseudocode
Language-independent algorithm notation. More precise than English; not executable. AQA uses left arrow and UPPERCASE keywords; OCR uses equals and lowercase.
Trace table
One column per variable, one row per execution step. Verifies output without running code.
Diamond (flowchart)
Decision shape. Exactly two exits: Yes and No. Corresponds to IF or WHILE in pseudocode.
Discussion questions
Why is pseudocode more useful for designing algorithms than actual code?
When is a flowchart clearer than pseudocode for the same algorithm? When is it worse?
If you trace an algorithm and get the wrong output, where in the trace do you look for the error?
Exit tickets
Write pseudocode to input two numbers and output the smaller one. [3 marks]
A flowchart has two arrows leaving a rectangle. What error does this represent? [1 mark]
Trace: total←0; FOR i←1 TO 3; total←total*i; ENDFOR. Show all steps. [3 marks]
Homework suggestion
Write pseudocode for a program that asks the user to enter 5 numbers, calculates their average and outputs whether the average is above or below 50. Then draw the same algorithm as a flowchart. Compare both representations in a short paragraph.