Write pseudocode from a structured English description

Topic 9.2 – Converting Structured English to Pseudocode

1. Why Use Pseudocode?

  • Provides a language‑independent description of an algorithm that can be read by humans.
  • Acts as a bridge between natural language (structured English) and the formal syntax of any programming language.
  • All Cambridge IGCSE/A‑Level examinations require algorithms to be presented in clear pseudocode.

2. Structured English – A Semi‑Formal Description

Structured English combines plain English with a limited set of control‑flow keywords. It is:

  • Unambiguous – each line has one clear meaning.
  • Consistently capitalised – keywords such as IF, FOR EACH, WHILE, REPEAT.
  • Line‑oriented – one step per line, indentation shows nesting.

3. Core Structured‑English Keywords and Their Pseudocode Equivalents

Structured EnglishPseudocode
SET variable TO expressionvariableexpression
IF condition THEN … ELSE … END IFif condition then … else … endif
FOR EACH item IN list DO … END FORfor each item in list do … endfor
FOR i FROM a TO b DO … END FORfor ia to b do … endfor
WHILE condition DO … END WHILEwhile condition do … endwhile
REPEAT … UNTIL conditionrepeat … until condition
OUTPUT valueoutput value
CALL procedure(args)call procedure(args)
RETURN valuereturn value

4. Step‑by‑Step Conversion Process

  1. Identify control‑flow constructs (IF, WHILE, REPEAT, FOR EACH, FOR … TO).
  2. Replace each keyword with the pseudocode symbol from the table.
  3. Remove filler words such as “SET”, “TO”, “DO”, “END …”.
  4. Introduce the assignment arrow (←) for all initialisations and updates.
  5. Apply consistent indentation – two spaces per nesting level.
  6. Check block matching – every if has an endif, every for an endfor, etc.
  7. Add comments (optional) using // on a separate line.

5. Example Conversion

Structured English

SET total TO 0

FOR EACH number IN numbers DO

IF number MOD 2 = 0 THEN

SET total TO total + number

END IF

END FOR

OUTPUT total

Pseudocode

total ← 0

for each number in numbers do

if number mod 2 = 0 then

total ← total + number

endif

endfor

output total

Explanation

  • SET … TO … → assignment arrow .
  • FOR EACH … DO … END FORfor each … do … endfor.
  • IF … THEN … END IFif … then … endif.
  • Mathematical operators (e.g., MOD) are left unchanged.

6. Cambridge Pseudocode Conventions

  • All keywords in lower case (if, while, for, output).
  • Two‑space indentation per nesting level.
  • Use the arrow for assignment; if unavailable, write “=”.
  • Comments start with // and occupy a whole line.
  • Terminate each block with its matching keyword (endif, endfor, endwhile, endrepeat).

Cambridge Syllabus Mapping – Full Coverage

7. Information Representation (1.1‑1.3)

  • Binary & Hexadecimal – base‑2 and base‑16, conversion methods, two’s complement for signed integers.
  • Text Encoding – ASCII (7‑bit) and Unicode (UTF‑8) tables; each character ↔ numeric code.
  • Images – pixels, colour depth (e.g., 24‑bit RGB), bitmap vs. vector, simple lossless compression (run‑length encoding).
  • Sound – sampling rate, bit depth, PCM representation.
  • Simple Compression – lossless (RLE) vs. lossy (JPEG, MP3) concepts.

8. Communication & Networks (2.1)

  • Topologies: star, bus, ring, mesh.
  • OSI model (7 layers) and TCP/IP model (4 layers).
  • IP addressing: IPv4 dotted decimal, subnet masks, brief note on IPv6.
  • DNS role – translating domain names to IP addresses.
  • Client‑server vs. peer‑to‑peer, basic cloud‑computing ideas.

9. Hardware & Processor Fundamentals (3.1‑3.2)

  • Von Neumann architecture – CPU, memory, I/O bus.
  • CPU components: ALU, control unit, registers (PC, ACC, IR, general‑purpose).
  • Fetch‑decode‑execute‑store cycle.
  • Basic logic‑gate symbols (AND, OR, NOT, NAND, XOR) – useful for understanding low‑level operations.

10. Assembly Language (4.1‑4.3)

A simple assembly program that adds the elements of an array, together with its register‑transfer notation (RTN) and equivalent pseudocode.

; --- Assembly (pseudo‑ASM) ---------------------------------

LDI R0,0 ; sum ← 0

LDI R1,0 ; i ← 0

LOOP: CMP R1,N

JGE END

LDA R2,ARRAY(R1)

ADD R0,R2

INC R1

JMP LOOP

END: STA SUM,R0

; ---------------------------------------------------------

Corresponding pseudocode:

sum ← 0

i ← 0

while i < N do

sum ← sum + ARRAY[i]

i ← i + 1

endwhile

11. System Software (5.1‑5.2)

ComponentKey Functions (Cambridge)
Operating SystemMemory management, file system, process scheduling, device control, security services.
CompilersTranslate source → object code; optimisation; produce executables.
InterpretersExecute source line‑by‑line; useful for rapid testing.
AssemblersTranslate symbolic assembly → machine code.
IDE FeaturesSyntax highlighting, debugger, auto‑completion – helpful for testing pseudocode.

12. Security, Privacy & Data Integrity (6.1‑6.2)

  • Common threats: viruses, worms, trojans, ransomware, phishing, DDoS.
  • Counter‑measures: firewalls, anti‑virus, strong passwords, two‑factor authentication, encryption (symmetric & asymmetric).
  • Data integrity techniques: parity bits, checksums, hash functions (MD5, SHA‑1/2), digital signatures.
  • Validation: input sanitisation, range checking, use of try‑catch blocks.

13. Ethics & Ownership (7.1)

Case study – Software licences

  • GNU GPL: users may run, study, modify, and redistribute; derived works must retain the same licence.
  • MIT Licence: permissive, only requires attribution.
  • Proprietary licence: restricts copying, modification, and redistribution.

Discussion prompt for exams: “Explain how open‑source licences balance the creator’s rights with public benefit.”

14. Databases (8.1‑8.3)

  • Relational concepts: tables, rows, columns, primary key, foreign key.
  • ER diagram symbols: entity (rectangle), relationship (diamond), attribute (oval).
  • Normalisation: 1NF, 2NF, 3NF – eliminate redundancy.
  • Simple SQL queries (compatible with A‑Level):

    SELECT name, score

    FROM Students

    WHERE score > 80

    ORDER BY score DESC;

15. Data Types & Data Structures (10.1‑10.4)

CategoryExamples
Primitive typesINTEGER, REAL, BOOLEAN, CHARACTER, STRING
Composite typesRECORD (struct), ARRAY (1‑D, 2‑D), LIST
Abstract Data TypesSTACK, QUEUE, LINKED LIST (brief description)
File handling (pseudocode)

open file "data.txt" for reading as f

while not eof(f) do

read line from f into record

// process record

endwhile

close f

16. Algorithm Design – Searching, Sorting & Recursion

Linear Search (O(n))

found ← false

i ← 0

while i < length(list) and not found do

if list[i] = target then

found ← true

endif

i ← i + 1

endwhile

output found

Binary Search (O(log n)) – requires a sorted list

low ← 0

high ← length(list) - 1

found ← false

while low <= high and not found do

mid ← (low + high) div 2

if list[mid] = target then

found ← true

elseif list[mid] < target then

low ← mid + 1

else

high ← mid - 1

endif

endwhile

output found

Bubble Sort (O(n²))

for i ← 0 to length(arr) - 2 do

for j ← 0 to length(arr) - i - 2 do

if arr[j] > arr[j+1] then

temp ← arr[j]

arr[j] ← arr[j+1]

arr[j+1] ← temp

endif

endfor

endfor

output arr

Insertion Sort (O(n²))

for i ← 1 to length(arr) - 1 do

key ← arr[i]

j ← i - 1

while j >= 0 and arr[j] > key do

arr[j+1] ← arr[j]

j ← j - 1

endwhile

arr[j+1] ← key

endfor

output arr

Recursive Factorial (illustrates recursion)

function factorial(n)

if n = 0 then

return 1

else

return n * factorial(n-1)

endif

endfunction

output factorial(5) // 120

Complexity Notation (Big‑O)

For any algorithm we express the dominant term of its running time as a function of the input size n. Example for linear search:

\[

T(n) = c1 + c2 n \;\;\Longrightarrow\;\; T(n) \in O(n)

\]

17. Programming Paradigms & Exception Handling (20.1‑20.2)

  • Procedural: sequence of commands, use of functions/sub‑routines (e.g., C, Python).
  • Object‑Oriented: classes, objects, inheritance, encapsulation – brief note as it appears in A‑Level.
  • Exception handling (pseudo‑style):

    try

    result ← divide(a, b)

    catch DivisionByZeroError

    output "Cannot divide by zero"

    endtry

18. Emerging Topics – Awareness Box

  • Artificial Intelligence: rule‑based systems, search algorithms (A*), very basic machine‑learning ideas.
  • Virtual Machines: abstraction layer (e.g., JVM) that executes byte‑code, providing platform independence.
  • Parallel Processing: multi‑core CPUs, dividing work into threads, simple speed‑up concept.

19. Practice Conversion Question

Convert the following structured English into correct pseudocode.

SET max TO numbers[1]

FOR i FROM 2 TO LENGTH(numbers) DO

IF numbers[i] > max THEN

SET max TO numbers[i]

END IF

END FOR

OUTPUT max

Answer

max ← numbers[1]

for i ← 2 to length(numbers) do

if numbers[i] > max then

max ← numbers[i]

endif

endfor

output max

20. Summary

  • Structured English gives a clear, English‑like description of an algorithm.
  • Conversion to pseudocode is systematic: replace keywords, drop filler words, use the assignment arrow, and apply consistent indentation.
  • Follow Cambridge conventions (lower‑case keywords, matching block terminators, two‑space indentation).
  • The notes now cover every required syllabus block – from information representation to exception handling – ensuring full alignment with the Cambridge IGCSE/A‑Level Computer Science (9618) objectives.