Algorithm Design and Problem Solving · 4 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 11% of your exam marks.
The most marks-dense topic. Both papers test pseudocode writing and trace tables every sitting.
Cambridge IGCSE uses its own pseudocode style. It is not real Python or any other language. The rules are deliberately simple, so any student can read or write it regardless of which language they have learned. Marks are lost if you write things like print(...) with brackets when the question asks for pseudocode.
Variables hold values. The CIE arrow operator ← is used for assignment (some specifications also accept = or :=).
total ← 0
count ← count + 1
name ← "Alice"
isFinished ← FALSE
Variables are also declared with a data type using DECLARE:
DECLARE Score : INTEGER
DECLARE Name : STRING
DECLARE IsFinished : BOOLEAN
DECLARE Price : REAL
Two clean keywords, with no brackets:
INPUT Age
OUTPUT "Welcome to the site, ", Name
A standard two-branch selection:
IF Age >= 18
THEN
OUTPUT "Welcome to the site"
ELSE
OUTPUT "Sorry, this site is for over-18s only"
ENDIF
Selections can be nested to test more than two cases:
IF Score >= 70 THEN
Grade ← "A"
ELSE
IF Score >= 60 THEN
Grade ← "B"
ELSE
Grade ← "C"
ENDIF
ENDIF
For more than a handful of branches, CASE ... OF ... OTHERWISE ... ENDCASE is cleaner:
CASE Day OF
1 : OUTPUT "Monday"
2 : OUTPUT "Tuesday"
3 : OUTPUT "Wednesday"
4 : OUTPUT "Thursday"
5 : OUTPUT "Friday"
OTHERWISE : OUTPUT "Weekend"
ENDCASE
Three loop constructs are tested by the syllabus; they are compared in section 5.
FOR i ← 1 TO 10
OUTPUT i
NEXT i
WHILE NotFinished = TRUE DO
INPUT Answer
IF Answer = "stop" THEN
NotFinished ← FALSE
ENDIF
ENDWHILE
REPEAT
INPUT Number
UNTIL Number > 0
Arrays hold a list of values of the same type:
DECLARE Scores : ARRAY[1:10] OF INTEGER
Scores[1] ← 75
Scores[2] ← 88
OUTPUT Scores[1]
CIE arrays are usually 1-indexed, with the size given as [1:10]. Some other syntaxes use [10].
| Operator | Meaning |
|---|---|
+ - * / | Plus, minus, multiply, divide |
DIV | Integer division (quotient) |
MOD | Remainder (modulo) |
^ | To the power of |
| Operator | Meaning |
|---|---|
= | Equal to |
<> | Not equal to |
< > | Less than, greater than |
<= >= | Less than or equal, greater than or equal |
| Operator | Meaning |
|---|---|
AND | Both conditions are true |
OR | At least one condition is true |
NOT | The single condition is not true |
| Function | What it does |
|---|---|
LENGTH(s) | Returns the number of characters in s |
SUBSTRING(s, start, length) | Returns part of s starting at position start, for length characters |
UCASE(s) | Returns s with every letter in uppercase |
LCASE(s) | Returns s with every letter in lowercase |
PROCEDURE Greet(Name : STRING)
OUTPUT "Hello, ", Name
ENDPROCEDURE
CALL Greet("Alice")
FUNCTION Square(Value : INTEGER) RETURNS INTEGER
RETURN Value * Value
ENDFUNCTION
Result ← Square(5)
These are covered in detail in topic 24 (Procedures and Functions).
Example — Write a CIE-pseudocode algorithm that asks a user to enter their age and either welcomes them to the site (18 or over) or shows a polite rejection message.
INPUT Age
IF Age >= 18 THEN
OUTPUT "Welcome to the site"
ELSE
OUTPUT "Sorry, this site is for over-18s only"
ENDIF
print(), input(), range(). Stick to OUTPUT, INPUT, FOR ... NEXT.IF needs ENDIF; WHILE needs ENDWHILE; FOR needs NEXT.IF, THEN, WHILE, DO, NEXT).StudentScore, not x).