Cambridge A-Level Computer Science 9618 – Topic 9.2 Algorithms: Writing Pseudocode from a Flowchart
Topic 9.2 – Algorithms
Objective: Write pseudocode from a flowchart
In this section you will learn how to translate a flowchart into clear, structured pseudocode. This skill is essential for the A‑Level exam, where you may be asked to interpret a diagram and express the algorithm in a textual form.
Why translate a flowchart?
Flowcharts provide a visual overview of the control flow.
Pseudocode is the language used in exam answers and in planning actual code.
Being able to move between the two representations demonstrates a deep understanding of algorithmic logic.
Key Flowchart Symbols and Their Pseudocode Equivalents
Flowchart Symbol
Meaning
Pseudocode Equivalent
Oval (Start/End)
Marks the beginning or termination of the algorithm.
START / END
Parallelogram (Input/Output)
Read data from the user or display results.
READ variable or WRITE expression
Rectangle (Process)
Performs a calculation or assignment.
variable ← expression
Diamond (Decision)
Tests a condition; branches to “Yes” or “No”.
IF condition THEN … ELSE … ENDIF
Arrows (Flow lines)
Indicates the order of execution.
Implicit in the order of statements.
Loop symbols (e.g., a rectangle with a curved edge)
Repeats a block of statements.
FOR i ← 1 TO n DO … ENDFOR or WHILE condition DO … ENDWHILE
Step‑by‑Step Procedure
Identify the Start and End symbols.
Read the flow from top to bottom (or left to right) following the arrows.
For each symbol, write the corresponding pseudocode line using the table above as a guide.
Maintain proper indentation to reflect nesting (e.g., inside IF or loops).
Replace any “magic numbers” with meaningful variable names.
Check that every decision has both a THEN and an ELSE branch in the pseudocode.
Review the final pseudocode to ensure it is a complete, executable description of the algorithm.
Example Translation
Suggested diagram: Flowchart that reads an integer \$n\$, calculates the sum of the first \$n\$ natural numbers, and outputs the result.
The flowchart contains the following elements (in order):
Start
Input \$n\$
Set sum ← 0
Set i ← 1
Decision: i ≤ n ?
Yes: sum ← sum + i
Yes: i ← i + 1
Loop back to decision
No: proceed
Output sum
End
The corresponding pseudocode is:
START
READ n
sum ← 0
i ← 1
WHILE i ≤ n DO
sum ← sum + i
i ← i + 1
ENDWHILE
WRITE sum
END
Common Pitfalls
Forgetting the ELSE part of a decision – the pseudocode must handle both outcomes.
Incorrect indentation, which can hide the true nesting of loops and conditionals.
Using ambiguous variable names; always choose descriptive identifiers.
Omitting the update step in a loop (e.g., forgetting i ← i + 1).
Translating arrows incorrectly – always follow the direction indicated in the flowchart.
Practice Questions
Given a flowchart that determines whether a number entered by the user is prime, write the full pseudocode.
Translate the following flowchart (described below) into pseudocode:
Start
Input integer \$x\$
Decision: \$x \bmod 2 = 0\$?
Yes: Write “Even”
No: Write “Odd”
End
Identify and correct the errors in the pseudocode below (which was derived from a flowchart):
START
READ m
total ← 0
FOR i ← 1 TO m
total ← total + i
END FOR
WRITE total
END
Hint: Check the loop syntax against the flowchart conventions used in the exam.
Summary
Being able to convert a flowchart into pseudocode involves recognizing standard symbols, following the logical flow, and expressing each step with clear, indented statements. Mastery of this skill will help you answer a wide range of algorithm questions in the Cambridge A‑Level Computer Science examination.