By the end of this lesson you will be able to:
IF … THEN … [ELSE …]CASE … OF … END CASEWHILE … DO … END WHILE or REPEAT … UNTIL …| Operator | English meaning | Cambridge pseudocode form |
|---|---|---|
| ∧ | AND – both conditions must be true | AND |
| ∨ | OR – at least one condition is true | OR |
| ¬ | NOT – negates a condition | NOT |
| → | IF‑THEN – implication | IF … THEN … |
| ↔ | IF AND ONLY IF – bi‑conditional | IF … THEN … ELSE … (IFF) |
PRE‑CONDITION: n > 0IF … THEN … [ELSE …], CASE … OF … END CASE or loops.AND, OR and NOT as required.POST‑CONDITION: f = n! ∧ f > 0Find the greatest common divisor of two positive integers a and b.Refined steps
1. Check that a > 0 AND b > 0.
2. REPEAT
temp ← b
b ← a MOD b
a ← temp
UNTIL b = 0
3. OUTPUT a
Full pseudocode (Cambridge style)
INPUT a, b
IF NOT (a > 0 AND b > 0) THEN
OUTPUT "Invalid input"
STOP
END IF
WHILE b ≠ 0 DO
temp ← b
b ← a MOD b
a ← temp
END WHILE
OUTPUT a // a now holds GCD
gcd(a, b) = gcd(original_a, original_b) holds before and after each iteration; when the loop ends (b = 0) the invariant gives a = gcd(original_a, original_b).O(log min(a,b)) iterations, each requiring a constant‑time modulo operation. Hence time‑complexity is O(log min(a,b)) and space‑complexity is O(1).
Abstraction is encouraged. The GCD algorithm can be split into two reusable procedures:
PROCEDURE MODULUS(x, y) RETURNS r
r ← x MOD y
RETURN r
END PROCEDURE
PROCEDURE SWAP(x, y) RETURNS (x', y')
x' ← y
y' ← x
RETURN (x', y')
END PROCEDURE
The main algorithm then calls these procedures, which can be shown in a simple structure chart.
INPUT a, b, c
IF a + b ≤ c OR a + c ≤ b OR b + c ≤ a THEN
OUTPUT "Not a triangle"
STOP
END IF
CASE
WHEN a = b AND b = c THEN
OUTPUT "Equilateral"
WHEN a = b OR b = c OR a = c THEN
OUTPUT "Isosceles"
OTHERWISE
OUTPUT "Scalene"
END CASE
INPUT y
IF y ≤ 0 THEN
OUTPUT "Invalid year"
STOP
END IF
/* Leap year rule:
Leap ↔ (y MOD 4 = 0) AND ((y MOD 100 ≠ 0) OR (y MOD 400 = 0))
*/
IF (y MOD 4 = 0) AND ((y MOD 100 ≠ 0) OR (y MOD 400 = 0)) THEN
OUTPUT "Leap year"
ELSE
OUTPUT "Common year"
END IF
| Concept | Key points for exams |
|---|---|
| Number bases | Binary, octal, decimal, hexadecimal; conversion methods; positional weighting. |
| Two’s‑complement | Representing signed integers; range –2n‑1 … 2n‑1‑1; overflow detection. |
| Character encodings | ASCII (7‑bit), Unicode (UTF‑8/16); mapping characters to numeric codes. |
| BCD & other specialised codes | When and why they are used (e.g., digital clocks). |
Mini‑activity: Convert 101101₂ to decimal, then to hexadecimal, and interpret it as a signed two’s‑complement integer.
| Term | Definition / exam relevance |
|---|---|
| Topology | Star, bus, ring, mesh – impact on reliability and performance. |
| Protocol | Set of rules; examples: TCP, UDP, HTTP, SMTP. Emphasise layered model (OSI or TCP/IP). |
| IP addressing | IPv4 dotted‑decimal, subnet masks, CIDR notation; IPv6 basics. |
| DNS | Domain Name System – translating host names to IP addresses. |
| Client‑server vs P2P | Identify which model a given application uses. |
| Cloud services | Key characteristics: on‑demand, scalability, multi‑tenancy. |
| Topic | What you need to know |
|---|---|
| Assembly language basics | Instruction format (opcode, operand), simple examples (LOAD, STORE, ADD, SUB). |
| Addressing modes | Immediate, direct, indirect, indexed, relative – when each is used. |
| Bit manipulation | LEFT SHIFT, RIGHT SHIFT, AND, OR, XOR masks; use in logical conditions. |
| Two‑pass assembler outline | First pass builds symbol table; second pass generates machine code. |
| Component | Key responsibilities (exam focus) |
|---|---|
| Operating System | Memory management, process scheduling, I/O handling, security (user accounts, permissions). |
| Utilities | File manipulation (copy, delete), disk management, backup tools. |
| Language translators | Compilers (source → object), interpreters (line‑by‑line), assemblers, linkers. |
| IDE features | Syntax highlighting, debugging, version control integration – useful for algorithm testing. |
Case‑study prompt (exam style): A school wants to develop a mobile app. Should they use an open‑source library (GPL) or a commercial SDK (proprietary)? Discuss licensing implications, professional codes of conduct and the impact on future maintenance.
| Concept | Exam‑relevant details |
|---|---|
| Relational model | Tables, primary keys, foreign keys, relationships (1‑1, 1‑M, M‑M). |
| ER diagram → relational schema | Identify entities, attributes, cardinalities; translate to CREATE TABLE statements. |
| Normalization | First, second and third normal form – eliminate redundancy. |
| SQL basics | DDL: CREATE TABLE, DROP TABLE; DML: SELECT, INSERT, UPDATE, DELETE. |
FOR i ← 1 TO n DO … END FOR.Student record.OPEN, READ, WRITE, CLOSE.
PROCEDURE MAXIMUM(arr[1..n]) RETURNS max
max ← arr[1]
FOR i ← 2 TO n DO
IF arr[i] > max THEN
max ← arr[i]
END IF
END FOR
RETURN max
END PROCEDURE
Task: Write a complete algorithm that determines whether a given integer n is a perfect square. Use logical statements for the input, processing (including a CASE to report “Yes” or “No”), and output sections. Include a pre‑condition and a post‑condition.
n (integer).n ≥ 0.root ← FLOOR(√n) (you may use a loop that repeatedly increments i until i*i > n).
CASE
WHEN root * root = n THEN OUTPUT "Yes"
OTHERWISE OUTPUT "No"
END CASE
(output = "Yes") ↔ (∃k ∈ ℕ, k² = n).
INPUT n
PRE‑CONDITION: n ≥ 0
/* Find integer square root */
root ← 0
WHILE (root + 1) * (root + 1) ≤ n DO
root ← root + 1
END WHILE
CASE
WHEN root * root = n THEN
OUTPUT "Yes"
OTHERWISE
OUTPUT "No"
END CASE
POST‑CONDITION: (output = "Yes") ↔ (∃k ∈ ℕ, k² = n)
AND, OR, NOT.IF … THEN … [ELSE …] or CASE … OF … END CASE using the correct Cambridge symbols.WHILE … DO … END WHILE or REPEAT … UNTIL … with a clear logical termination condition; state a loop invariant if asked.Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.