Draw a flowchart from pseudocode

9.2 Algorithms – Drawing a Flowchart from Pseudocode

Learning Objective

Translate a piece of Cambridge‑approved pseudocode into a correct flowchart using the standard symbols defined in the 9618 syllabus.

Why Use Flowcharts?

  • Provide a language‑independent visual description of an algorithm.
  • Help you spot logical errors or inefficiencies before you start coding.
  • Offer a clear way to communicate algorithms to peers, teachers and examiners.

Cambridge Pseudocode Conventions (9618)

  • Keywords in UPPERCASE (e.g. INPUT, IF, WHILE).
  • Assignment arrow for storing values.
  • Structured English style for loops and conditionals.

Full details are available in the Cambridge Pseudocode Guide.

Standard Flowchart Symbols (Cambridge‑approved)

SymbolNamePurpose
Start / EndMarks the beginning or termination of the algorithm.
Input / OutputReads data from the user or displays results.
ProcessPerforms a calculation, assignment or any non‑decision operation.
DecisionTests a condition; produces two branches (Yes/No or True/False).
ConnectorLinks separate parts of a large flowchart when space constraints require it.

Assessment Alignment (9618)

  • AO2 – Apply knowledge: Apply understanding of algorithm representation.
  • AO3 – Design, program and evaluate: Design a visual representation, then evaluate its correctness against the original pseudocode.

Step‑by‑Step Conversion Process

  1. Read the pseudocode. Highlight initialisation, input, loops, decisions and output.
  2. Map each line to a flowchart symbol.
    • Assignments / calculations → Process (rectangle).
    • Reading or printing data → Input/Output (parallelogram).
    • Conditional statements (IF … THEN … ELSE … END IF) → Decision (diamond).
    • Repeated actions (FOR, WHILE) → Decision combined with a backward arrow to form a loop.
    • When the diagram becomes too wide, insert a Connector to continue on a new line.
  3. Place a Start symbol at the top and an End symbol at the bottom.
  4. Connect the symbols with arrows in execution order. Label loop‑back arrows and decision exits with “Yes/No” or “True/False”.
  5. Handle nested structures. Use vertical indentation or connectors so the hierarchy is obvious.
  6. Mini‑checklist – verify every line of pseudocode is represented.
    • ✔︎ Input → Input/Output symbol
    • ✔︎ Assignment → Process symbol
    • ✔︎ Decision → Decision symbol
    • ✔︎ Loop condition → Decision with back‑arrow
    • ✔︎ Output → Input/Output symbol
  7. Test a boundary case. Example: for a factorial routine, check the behaviour when n = 0 or n < 0.

Worked Example – Factorial of a Positive Integer

INPUT n
IF n < 0 THEN
    OUTPUT "Invalid input"
ELSE
    SET fact ← 1
    SET i   ← 1
    WHILE i ≤ n DO
        SET fact ← fact × i
        SET i    ← i + 1
    END WHILE
    OUTPUT fact
END IF

Conversion into a Flowchart

  1. Start (○)
  2. Input n (▷)
  3. Decision: n < 0 (◇)
    • Yes → Output “Invalid input” (▷) → End.
    • No → Continue.
  4. Process: fact ← 1 (▯)
  5. Process: i ← 1 (▯)
  6. Decision: i ≤ n (◇)
    • Yes → Process: fact ← fact × i (▯)
    • Process: i ← i + 1 (▯) → back to the decision.
    • No → Output fact (▷) → End.
  7. End (○)

Boundary‑Case Note

If n = 0, the loop condition i ≤ n is false on the first test, so the flowchart jumps directly to the final output, correctly returning fact = 1.

Typical Layout (SVG placeholder)

Start → Input → Decision → Process → Loop → Output → End. Use connectors only if the diagram exceeds the page width.
Start

Practice Exercise

Convert the following pseudocode into a flowchart. Use the steps above and the mini‑checklist.

INPUT a, b
IF a = b THEN
    OUTPUT "Numbers are equal"
ELSE
    IF a > b THEN
        SET max ← a
        SET min ← b
    ELSE
        SET max ← b
        SET min ← a
    END IF
    OUTPUT "Maximum = ", max
    OUTPUT "Minimum = ", min
END IF

Hints

  • Two separate OUTPUT statements can be combined into a single Process block for a more compact diagram.
  • Insert a connector if the nested IF makes the chart too wide.
  • Label decision branches “Yes/No” (or “True/False”).

Key Points to Remember

  • Every line of Cambridge‑style pseudocode must appear in the flowchart as a Process, Decision, or Input/Output symbol.
  • Loops are always a Decision symbol that feeds back to an earlier point (the loop body).
  • Maintain a clear top‑to‑bottom flow; avoid crossing arrows where possible.
  • Label decision exits clearly (“Yes/No” or “True/False”).
  • Use connectors only when necessary and number them for easy reference.
  • Check the flowchart against the mini‑checklist and test at least one boundary case.

Additional Syllabus Areas – Action‑Oriented Review (9618)

1. Information Representation

What the Current Notes Miss

  • Two’s‑complement overflow and wrap‑around examples.
  • Unicode code‑point ranges and UTF‑8/UTF‑16 encoding.
  • Lossy vs. lossless audio codecs (e.g., MP3 vs. FLAC).
  • Practical compression calculations (Run‑Length Encoding, Huffman coding).

Concrete Improvements

Overflow & Wrap‑Around Box
Operation8‑bit Two’s‑Complement Result
120 + 20140 → 10001100 (binary) → Overflow → wraps to –116
−70 − 60−130 → 11111110 (binary) → Overflow → wraps to 126
Unicode & UTF‑8 Encoding Table
Code‑point (hex)PlaneUTF‑8 BytesExample Character
U+0041Basic Latin (Plane 0)1 (0x41)A
U+00E9Latin‑1 Supplement2 (0xC3 0xA9)é
U+20ACCurrency Symbols3 (0xE2 0x82 0xAC)
U+1F600Emoticons (Plane 1)4 (0xF0 0x9F 0x98 0x80)😀

Exercise: Encode the string “Café 😀” in UTF‑8 and calculate the total number of bytes.

Audio Codec Comparison
CodecTypeTypical Bit‑rateCompression RatioTypical Use
MP3Lossy128 kbps (stereo)≈10 : 1Music streaming
FLACLossless~900 kbps (CD‑quality)≈2 : 1Archival audio
AACLossy96 kbps (stereo)≈12 : 1YouTube, mobile
Simple RLE Worksheet

Given the binary string 111100001111, apply Run‑Length Encoding and write the result as (value, count) pairs.

Answer: (1,4) (0,4) (1,4)

Huffman Coding Visualiser

Use the free online tool Huffman Coding Visualiser to build a tree for the character frequencies: {A:5, B:9, C:12, D:13, E:16, F:45}. Record the resulting binary codes.


2. Communication & Networks

What the Current Notes Miss

  • IPv4 vs. IPv6 notation and subnet‑mask calculations.
  • Difference between CSMA/CD (wired) and CSMA/CA (wireless) with hidden‑node problems.
  • Cloud service models (IaaS, PaaS, SaaS) and their security implications.
  • A realistic packet‑tracing example (e.g., ping / traceroute).

Concrete Improvements

IPv4 / IPv6 Subnetting Practice
CIDRSubnet MaskNumber of Hosts
/24255.255.255.02⁸ − 2 = 254
/28255.255.255.2402⁴ − 2 = 14
/64 (IPv6)ffff:ffff:ffff:ffff::2⁶⁴ ≈ 1.84 × 10¹⁹

Exercise: Convert the IPv4 address 192.168.12.0/26 into its binary form and list the first usable host address.

CSMA/CD vs. CSMA/CA Diagram
Key differences between wired (CSMA/CD) and wireless (CSMA/CA) media access control.
CSMA/CD (Ethernet) - Detects collisions - Uses jam signal - Back‑off algorithm CSMA/CA (Wi‑Fi) - Avoids collisions - RTS/CTS handshake - Hidden‑node problem
Cloud Service Model Comparison
ModelWhat the Provider SuppliesWhat the User ManagesTypical Example
IaaSVirtual machines, storage, networkingOS, middleware, runtime, data, applicationsAWS EC2, Azure Virtual Machines
PaaSOS, runtime, middleware, development toolsApplications and dataGoogle App Engine, Heroku
SaaSEverything (application delivered over the web)None (except user data)Office 365, Google Workspace

Security note: As you move up the stack (IaaS → SaaS) the provider assumes more responsibility for patching and hardening, but the user must still manage access control and data protection.

Packet‑Flow Tracing Example (Ping)
  1. Host A sends ICMP Echo Request → Ethernet frame (source MAC A, dest MAC B).
  2. Router receives frame, strips Ethernet header, reads IP header (src = A, dest = B).
  3. Router forwards the packet using its routing table; adds a new Ethernet header (src = router MAC, dest = B MAC).
  4. Host B receives Echo Request, replies with Echo Reply following the reverse path.

Label each header field (MAC, IP, ICMP) on a diagram and indicate where TTL is decremented.


3. Hardware & Processor Fundamentals

What the Current Notes Miss

  • Cache hierarchy (L1, L2, L3) and its impact on performance.
  • Pipelining hazards (data, control, structural) and simple mitigation techniques.

Concrete Improvements

Cache Hierarchy Overview
LevelTypical SizeTypical LatencyLocation
L116 KB – 64 KB≈1 cycleIntegrated into each core
L2256 KB – 1 MB≈3–5 cyclesPer core (often shared by 2 cores)
L32 MB – 32 MB≈10–20 cyclesShared among all cores on the chip

Performance tip: Programs that exhibit good spatial and temporal locality (e.g., iterating through an array sequentially) make better use of the cache and run faster.

Pipelining Hazards
Hazard TypeDescriptionSimple Mitigation
Data (RAW)Instruction needs a result that a previous instruction has not yet produced.Insert a NOP or use forwarding/bypass hardware.
Control (Branch)Pipeline must decide which instruction to fetch after a branch.Branch prediction or delay slots.
StructuralTwo instructions compete for the same hardware resource (e.g., a single memory port).Duplicate the resource or stall the pipeline.

Mini‑exercise: For the following three‑instruction sequence, identify any hazards and suggest a single‑cycle stall if forwarding is not available.

1:  LOAD R1, 0(R2)
2:  ADD  R3, R1, R4
3:  STORE R3, 0(R5)
Fetch‑Execute Cycle Diagram (with Pipeline)
Classic 5‑stage pipeline: IF – ID – EX – MEM – WB.
IF ID EX MEM WB Instruction n Decode n Execute n Memory n Write‑Back n
Quick Checklist for Hardware Topics
  • ✔︎ Cache levels, size, latency, and locality effects.
  • ✔︎ Identify data, control and structural hazards in a pipeline.
  • ✔︎ Explain one mitigation technique for each hazard type.
  • ✔︎ Describe the five stages of the classic RISC pipeline.

Putting It All Together – Integrated Practice Question

Design a flowchart for an algorithm that reads an integer n, checks whether it is a valid IPv4 host address (0 ≤ n ≤ 255), stores the value in a cache‑friendly array, and then outputs the binary representation using two’s‑complement (showing overflow handling). Include at least one decision that illustrates a pipeline hazard (e.g., a load followed by an add).

Use the mini‑checklists from the three sections to verify completeness, correctness, and alignment with the Cambridge 9618 syllabus.

Create an account or Login to take a Quiz

88 views
0 improvement suggestions

Log in to suggest improvements to this note.