Write pseudocode from a flowchart

Topic 9.2 – Translating Flowcharts into Pseudocode (and Vice‑versa)

Objective

Develop the ability to:

  • Read a flowchart and produce clear, well‑structured pseudocode (or structured English).
  • Generate a correct flowchart from a given algorithm.
  • Apply the technique across the full Cambridge International AS & A Level Computer Science (9618) syllabus.

Why translate a flowchart?

  • Flowcharts give a visual overview of the control flow.
  • Pseudocode (or structured English) is the language used in exam answers and in the planning stage of real code.
  • Fluently moving between the two representations demonstrates a deep understanding of algorithmic logic – a key assessment objective in 9618.

1. Syllabus Context – Where this fits

The Cambridge 9618 syllabus is divided into eight major sections. The ability to translate between flowcharts and pseudocode is directly assessed in the Algorithms sub‑topic, but it also underpins many other sections (e.g., data representation, networking protocols, hardware design, security checks). The table below shows the linkages.

Syllabus Section Relevant Content for Flowchart ↔ Pseudocode
1 Information Representation Binary, BCD, two’s‑complement – often shown in flowcharts that perform arithmetic or conversion.
2 Communication – Networks Algorithms for IP address validation, subnet calculations, packet‑checksum generation are commonly expressed as flowcharts.
3 Hardware – Logic Gates & Circuits Design of combinational circuits (e.g., adders) can be described with a flowchart that maps inputs to gate operations.
4 Processor Fundamentals – Assembly & Bit Manipulation Bit‑masking and shift‑operations are routinely written in pseudocode before being translated to assembly.
5 System Software – OS & Translators Compilation steps (lexical analysis → code generation) are modelled with flowcharts and then described in pseudocode.
6 Security & Data Integrity Checksum, parity‑bit, and simple encryption algorithms are ideal candidates for flowchart‑to‑pseudocode practice.
7 Ethics & Ownership Decision‑making flowcharts (e.g., “Is the software licence compatible?”) illustrate ethical reasoning.
8 Databases CRUD operations, normalization checks and query optimisation steps are often expressed as flowcharts.

2. Key Flowchart Symbols and Their Pseudocode / Structured English Equivalents

Symbol Meaning Pseudocode Structured English
Oval (Start/End) Marks the beginning or termination of the algorithm. START / END Start / End
Parallelogram (Input/Output) Read data from the user or display results. READ variable
WRITE expression
Input variable
Output expression
Rectangle (Process) Performs a calculation or assignment. variable ← expression Set variable to expression
Diamond (Decision) Tests a condition; branches to “Yes” or “No”. IF condition THEN … ELSE … ENDIF If condition then … otherwise …
Arrows (Flow lines) Indicates the order of execution. Implicit in the order of statements. Implicit in the order of statements.
Loop symbols (rectangle with a curved edge or a diamond with a back‑arrow) Repeats a block of statements. FOR i ← 1 TO n DO … ENDFOR
WHILE condition DO … ENDWHILE
Repeat … for i = 1 to n
Repeat … while condition

3. Identifier Table (Variable Declaration)

Before writing any pseudocode you must list every identifier that will be used. The table records the name, data type, purpose and initial value (if any). This satisfies the syllabus requirement for “identifiers and their scope”.

Identifier Data type Purpose Initial value
n integer Number of terms to sum
sum integer Running total of the series 0
i integer Loop counter 1

4. Step‑wise Refinement – From Idea to Full Pseudocode

Start with a high‑level description (the “algorithm outline”), then progressively add detail until the complete pseudocode is produced. This mirrors the way examiners expect you to develop an answer.

  1. Level 1 – Outline (structured English)
    1. Read n
    2. Initialise sum to 0
    3. Repeat while i ≤ n
        a. Add i to sum
        b. Increment i
    4. Output sum
            
  2. Level 2 – Add loop control
    1. READ n
    2. sum ← 0
    3. i ← 1
    4. WHILE i ≤ n DO
        a. sum ← sum + i
        b. i ← i + 1
    5. ENDWHILE
    6. WRITE sum
            
  3. Level 3 – Full pseudocode with identifier table
    IDENTIFIER TABLE
    -----------------
    n   : integer   – number entered by the user
    sum : integer   – cumulative total, initially 0
    i   : integer   – loop counter, initially 1
    
    PSEUDOCODE
    ----------
    START
        READ n
        sum ← 0
        i ← 1
        WHILE i ≤ n DO
            sum ← sum + i
            i ← i + 1
        ENDWHILE
        WRITE sum
    END
            

5. Full Translation Example (Sequence + Selection + Iteration)

The flowchart described below reads an integer x, decides whether it is even or odd, repeats this process k times, and finally outputs the total number of even inputs.

  1. Start
  2. Input integer k (number of repetitions)
  3. Set countEven ← 0
  4. Set repeat ← 1
  5. Decision: repeat ≤ k ?
    • Yes → Input integer x
    • Decision: x mod 2 = 0 ?
      • Yes → countEven ← countEven + 1
      • No → (no action)
    • Set repeat ← repeat + 1
    • Loop back to step 5
    • No → proceed
  6. Output countEven
  7. End

Identifier Table

Identifier Data type Purpose Initial value
k integer Number of repetitions
x integer Current input value
countEven integer How many of the inputs were even 0
repeat integer Loop counter 1

Pseudocode (final version)

START
    READ k
    countEven ← 0
    repeat ← 1
    WHILE repeat ≤ k DO
        READ x
        IF x MOD 2 = 0 THEN
            countEven ← countEven + 1
        ENDIF
        repeat ← repeat + 1
    ENDWHILE
    WRITE countEven
END

Structured English (exam‑style)

Start
    Input k
    Set countEven to 0
    Set repeat to 1
    Repeat while repeat ≤ k
        Input x
        If x is even then
            Add 1 to countEven
        End if
        Add 1 to repeat
    End repeat
    Output countEven
End

6. Reverse Translation – From Pseudocode to Flowchart

Exam questions may ask you to draw a flowchart from a given algorithm. Follow these steps:

  1. Identify the three basic constructs in the pseudocode (sequence, selection, iteration).
  2. Choose the appropriate flowchart symbol for each construct (rectangle, diamond, loop symbol).
  3. Place the symbols in the order they appear, connecting them with arrows.
  4. Ensure every decision diamond has two outgoing arrows labelled “Yes” and “No”.
  5. Label the start and end ovals.
  6. Cross‑check that the flowchart reproduces the exact logic of the pseudocode.

7. Step‑by‑Step Procedure (Flowchart → Pseudocode)

  1. Locate the Start and End symbols.
  2. Read the flow from top‑to‑bottom (or left‑to‑right) following the arrows.
  3. For each symbol, write the corresponding line of pseudocode using the table in Section 2.
  4. Insert an identifier table before the first START line.
  5. Use indentation (4 spaces) to show nesting of IF statements and loops.
  6. Replace any “magic numbers” with meaningful variable names and initialise them in the identifier table.
  7. Verify that every decision has both a THEN and an ELSE (or an explicit “no action” branch).
  8. Review the final pseudocode to ensure it is a complete, executable description of the algorithm.

8. Common Pitfalls & How to Avoid Them

  • Missing ELSE branch – always write an ELSE clause, even if it does nothing (e.g., ELSE /* no action */ ENDIF).
  • Incorrect indentation – use a consistent indent (usually 4 spaces) to make nesting obvious.
  • Ambiguous variable names – keep the identifier table and choose descriptive names (e.g., totalScore instead of s).
  • Forgotten loop update – every loop must contain a statement that eventually makes the condition false.
  • Mis‑reading arrows – always follow the direction shown; a common exam error is to assume “top‑to‑bottom” when a side‑arrow changes the flow.
  • Omitting the identifier table – examiners award marks for a clear table; leaving it out can lose up to 2‑3 marks.

9. Practice Questions

  1. Prime‑number test
    A flowchart reads an integer n, checks whether it is prime, and outputs “Prime” or “Not prime”. Write the full answer including:
    • Identifier table
    • Step‑wise refinement (outline → detailed pseudocode)
    • Final pseudocode
  2. Even / Odd
    Translate the following flowchart into pseudocode and structured English:
    • Start
    • Input integer x
    • Decision: x mod 2 = 0?
    • Yes → Write “Even”
    • No → Write “Odd”
    • End
  3. Loop‑syntax correction
    Identify and correct the errors in the pseudocode below (derived from a flowchart). Explain why each change is required.
    START
        READ m
        total ← 0
        FOR i ← 1 TO m
            total ← total + i
        END FOR
        WRITE total
    END
            

    Hint: The Cambridge exam expects the loop header and footer on separate lines and the closing keyword to be ENDFOR, not “END FOR”.

  4. Reverse translation
    The following pseudocode is given. Draw a correct flowchart using the symbols from Section 2.
    START
        READ n
        sum ← 0
        i ← 1
        WHILE i ≤ n DO
            sum ← sum + i
            i ← i + 1
        ENDWHILE
        WRITE sum
    END
            

10. Additional Syllabus Topics – Quick Reference

10.1 Information Representation

  • Binary, Hexadecimal, Octal – conversion tables, arithmetic, overflow detection.
  • BCD (Binary‑Coded Decimal) – each decimal digit stored in 4 bits; example: 57 → 0101 0111.
  • Two’s‑Complement – representation of negative numbers; example: -5 in 8‑bit = 1111 1011.
  • Overflow – occurs when the result exceeds the range of the chosen word size; flagged in flowcharts by a decision diamond.

10.2 Communication – Networks

  • Topologies: star, bus, ring, mesh.
  • LAN vs WAN, client‑server vs P2P, cloud‑computing models (SaaS, PaaS, IaaS).
  • IPv4 (e.g., 192.168.1.10) and IPv6 (e.g., 2001:0db8:85a3::8a2e:0370:7334) address formats.
  • Subnetting – calculate network address, broadcast address and usable hosts. Example: 192.168.12.0/24 → 256 addresses, 254 usable.
  • DNS, URL structure, and basic routing concepts.

10.3 Hardware – Logic Gates & Circuits

  • Basic gates: AND, OR, NOT, NAND, NOR, XOR, XNOR – truth tables provided.
  • Combinational circuits: half‑adder, full‑adder, multiplexer, decoder.
  • Design activity – “Create a 2‑bit binary adder” (use XOR for sum, AND for carry).
  • Sequential circuits – flip‑flops, registers, simple counters (can be modelled with a WHILE loop).

10.4 Processor Fundamentals – Assembly & Bit Manipulation

  • Simple instruction set: LOAD, STORE, ADD, SUB, AND, OR, NOT, SHIFT, JUMP.
  • Addressing modes: immediate, direct, indirect, indexed.
  • Two‑pass assembly – first pass builds symbol table, second pass generates machine code.
  • Bit‑masking examples:
    • Set bit 3: value ← value OR 0b00001000
    • Clear bit 2: value ← value AND 0b11111011
    • Toggle bit 5: value ← value XOR 0b00100000

10.5 System Software – OS & Translators

  • Operating‑system functions: process management, memory management, file handling, I/O control.
  • Utility software – backup, defragmentation, antivirus.
  • Translators: assembler, compiler, interpreter. Flowchart of a simple compiler:
    1. Read source code
    2. Lexical analysis → token list
    3. Syntax analysis → parse tree
    4. Code generation → machine code
  • IDE features useful for exam practice: syntax highlighting, auto‑indent, step‑through debugging.

10.6 Security & Data Integrity

  • Symmetric encryption – Caesar cipher (shift), XOR cipher.
  • Asymmetric encryption – basic idea of public/private key pair (no need to implement in exam).
  • Checksums & parity bits – algorithm can be expressed as a flowchart that iterates over a byte string and accumulates a sum modulo 256.
  • Hash functions – one‑way, fixed‑length output (e.g., SHA‑256). In exams you may be asked to explain why a hash is useful for integrity.

10.7 Ethics & Ownership

  • Intellectual‑property rights: copyright, patents, trademarks.
  • Software licences – distinction between proprietary, free‑software, open‑source (GPL, MIT, Apache).
  • Case study – “A mobile app uses a third‑party library under GPL. Is the app allowed to be sold commercially?” Flowchart decision can illustrate the reasoning.
  • Emerging issues – AI bias, data‑privacy regulations (GDPR), digital‑rights management.

10.8 Databases

  • DBMS concepts – tables, records, fields, primary keys, foreign keys.
  • SQL basics – DDL (CREATE, ALTER, DROP) and DML (SELECT, INSERT, UPDATE, DELETE).
  • Entity‑Relationship (ER) diagrams – entities, relationships, cardinality.
  • Normalization – 1NF, 2NF, 3NF; a flowchart can be used to check whether a table violates 2NF.
  • Simple CRUD flowchart example:
    1. Read user choice (Create, Read, Update, Delete)
    2. Branch to appropriate process rectangle
    3. Perform SQL statement
    4. Write success/failure message

11. Summary

  • Recognise the three basic constructs – sequence, selection, iteration – in both flowcharts and pseudocode.
  • Always begin with an identifier table to declare variables and initialise them.
  • Use step‑wise refinement to develop a clear, indented answer that mirrors the exam marking scheme.
  • When drawing a flowchart, follow the symbol conventions in Section 2 and label every decision branch.
  • Check for completeness: every decision has a Yes/No (or Then/Else) branch, loops contain an update that guarantees termination, and the identifier table is present.
  • Remember that the same translation skills are required across the whole 9618 syllabus – from binary arithmetic to network protocols, from hardware design to security checks.

Mastering flowchart‑to‑pseudocode conversion will give you a solid foundation for every algorithm‑related question in the Cambridge International AS & A Level Computer Science (9618) examination.

Create an account or Login to take a Quiz

92 views
0 improvement suggestions

Log in to suggest improvements to this note.