Write pseudocode from a structured English description

Published by Patrick Mutisya · 8 days ago

Topic 9.2 – Algorithms

Objective

Write correct pseudocode from a given structured English description.

1. What is Structured English?

Structured English is a semi‑formal way of describing an algorithm using plain English combined with a limited set of control‑flow keywords. It bridges the gap between natural language and formal pseudocode.

  • Uses simple, unambiguous statements.
  • Keywords are written in capital letters (e.g., IF, ELSE, FOR EACH).
  • Each step is on a separate line and indented to show nesting.

2. Typical Structured English Keywords

Structured EnglishPseudocode Equivalent
IF … THEN … ELSE … END IFif … then … else … endif
FOR EACH item IN list DO … END FORfor each item in list do … endfor
WHILE condition DO … END WHILEwhile condition do … endwhile
REPEAT … UNTIL conditionrepeat … until condition
SET variable TO expressionvariable ← expression
OUTPUT valueoutput value

3. Converting Structured English to Pseudocode – Step‑by‑Step

  1. Identify the control‑flow constructs (IF, WHILE, FOR EACH, REPEAT).
  2. Replace each keyword with its pseudocode counterpart (see the table above).
  3. Remove redundant words such as “SET”, “TO”, “DO”, “END …”.
  4. Introduce assignment symbols (←) for variable initialisation and updates.
  5. Maintain indentation to reflect nesting levels.
  6. Check that every opened block has a matching closing block (ENDIF, ENDFOR, ENDWHILE, ENDREPEAT).

4. Example Conversion

Structured English Description

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 …” becomes the assignment operator “←”.
  • “FOR EACH … DO … END FOR” becomes “for each … do … endfor”.
  • “IF … THEN … END IF” becomes “if … then … endif”.
  • Mathematical operators (e.g., MOD) are kept unchanged.

5. Common Pseudocode Conventions for A‑Level

  • All keywords are written in lower case (e.g., if, while).
  • Indentation is usually two spaces per nesting level.
  • Use the arrow symbol “←” for assignment; if unavailable, write “=”.
  • Comments, if required, are prefixed by // or placed on a separate line.

6. Practice Question

Write pseudocode for the following structured English description:

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 (pseudocode)

max ← numbers[1]

for i ← 2 to length(numbers) do

if numbers[i] > max then

max ← numbers[i]

endif

endfor

output max

7. Complexity Notation (Optional)

When analysing an algorithm, we often express its running time using Big‑O notation. For example, the linear search algorithm above runs in \$O(n)\$ time because it examines each element at most once.

\$\$

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

\$\$

8. Suggested Diagram

Suggested diagram: Flowchart showing the conversion from Structured English to Pseudocode, highlighting each keyword mapping and indentation step.

9. Summary

  • Structured English provides a clear, English‑like description of an algorithm.
  • Conversion to pseudocode involves replacing keywords, removing filler words, and using standard symbols.
  • Consistent indentation and matching block terminators are essential for readability and correctness.
  • Practice by converting several examples to become fluent for the A‑Level exam.