Write pseudocode that contains input, process and output

Topic 9.2 – Algorithms: Input, Process, Output and Core Pseudocode Constructs

Learning Objectives

  • Write clear, well‑structured pseudocode that explicitly shows the three fundamental stages of an algorithm: Input, Process and Output.
  • Apply the full range of Cambridge AS & A‑Level pseudocode constructs (sequence, selection, iteration, CASE, recursion, procedures and functions).
  • Demonstrate step‑wise refinement, algorithm analysis (correctness & efficiency) and conversion between flow‑charts and pseudocode.
  • Use basic data structures (constants, variables, arrays, records) correctly in algorithms.
  • Distinguish between count‑controlled and condition‑controlled loops (pre‑condition vs post‑condition).
  • Recall the supporting AS/A‑Level topics that underpin algorithm design (binary representation, multimedia, communication, hardware, logic, processor fundamentals, assembly language and system software).

Why Separate Input, Process and Output?

  • Clarity – each part has a single purpose, making the algorithm easier to read, debug and test.
  • Portability – mirrors the structure of any programming language, so the pseudocode can be translated directly.
  • Testing – inputs can be isolated, processes verified step‑by‑step, and outputs compared with expected results.

Standard Pseudocode Conventions (Cambridge 9618)

  1. Keywords in ALL CAPS (e.g. INPUT, OUTPUT, IF, ELSE, FOR, WHILE, CASE, ENDCASE, PROC, FUNC).
  2. Indentation shows block structure (IF…ENDIF, FOR…ENDFOR, WHILE…ENDWHILE, CASE…ENDCASE, PROC…ENDPROC).
  3. Comments start with # or //.
  4. Variable names are meaningful and written in camelCase or snake_case consistently.
  5. Constants are written in UPPER_SNAKE_CASE.

Full Algorithm Structure

SectionPurposeTypical Keywords
InputObtain data from the user, a file or another system.INPUT, READ
ProcessPerform calculations, decisions, loops, recursion, or call procedures/functions.SET, CALCULATE, IF, ELSE, ENDIF, FOR, ENDFOR, WHILE, ENDWHILE, CASE, ENDCASE, CALL, RETURN
OutputPresent the result to the user, a file or another system.OUTPUT, DISPLAY, PRINT, WRITE

Core Pseudocode Constructs (Syllabus 9.1‑9.2)

1. Sequence (straight‑line code)

# Assign a constant
SET TAX_RATE ← 0.20

2. Selection (IF…ELSE)

# Determine pass/fail
IF mark ≥ 40 THEN
    SET result ← "PASS"
ELSE
    SET result ← "FAIL"
ENDIF

3. Iteration

Loop TypePurposeKeywordsTypical Use
Count‑controlled (pre‑condition)Known number of repetitionsFOR i ← 1 TO n DO … ENDFORProcessing an array, summing n numbers
Condition‑controlled (pre‑condition)Repeat while a condition is trueWHILE condition DO … ENDWHILEInput validation, searching
Condition‑controlled (post‑condition)Execute at least onceREPEAT … UNTIL conditionMenu‑driven programs

4. CASE (multi‑way selection)

# Grade from mark
INPUT mark
CASE mark OF
    0..39:   SET grade ← "F"
    40..49:  SET grade ← "D"
    50..59:  SET grade ← "C"
    60..69:  SET grade ← "B"
    70..100: SET grade ← "A"
ENDCASE
OUTPUT grade

5. Recursion

# Factorial (n!)
FUNC factorial(n)
    IF n = 0 THEN
        RETURN 1
    ELSE
        RETURN n * factorial(n-1)
    ENDIF
ENDFUNC

INPUT n
SET result ← factorial(n)
OUTPUT result

6. Procedures & Functions (parameter passing)

# Procedure – calculates net pay
PROC calculateNetPay(grossPay, netPay)
    IF grossPay > 500 THEN
        SET netPay ← grossPay * 0.80   # 20 % tax
    ELSE
        SET netPay ← grossPay
    ENDIF
ENDPROC

# Main algorithm
INPUT name, hoursWorked, hourlyRate
SET grossPay ← hoursWorked * hourlyRate
CALL calculateNetPay(grossPay, netPay)
OUTPUT name, netPay

Step‑wise Refinement (Decomposition)

Complex problems are broken into smaller, manageable sub‑algorithms. Each sub‑algorithm can be written as a separate procedure or function and then CALLed from the main algorithm.

Refinement Example – Payroll (full)

#-------------------------------------------------
# MAIN
#-------------------------------------------------
INPUT name, hoursWorked, hourlyRate
CALL computeGrossPay(hoursWorked, hourlyRate, grossPay)
CALL applyTax(grossPay, netPay)
OUTPUT name, netPay

#-------------------------------------------------
# PROCEDURE: computeGrossPay
#-------------------------------------------------
PROC computeGrossPay(hours, rate, gross)
    SET gross ← hours * rate
ENDPROC

#-------------------------------------------------
# PROCEDURE: applyTax
#-------------------------------------------------
PROC applyTax(gross, net)
    IF gross > 500 THEN
        SET net ← gross * 0.80
    ELSE
        SET net ← gross
    ENDIF
ENDPROC

Data Structures (Syllabus 10.1‑10.4)

Constants & Variables

CONST MAX_STUDENTS ← 30
SET total ← 0

Arrays (1‑dimensional)

# Input marks for a class and calculate the average
INPUT n                     # n ≤ MAX_STUDENTS
FOR i ← 1 TO n DO
    INPUT marks[i]
    SET total ← total + marks[i]
ENDFOR
SET average ← total / n
OUTPUT average

Records (structured data)

# Record for a student
TYPE Student
    name : STRING
    id   : INTEGER
    mark : INTEGER
ENDTYPE

SET student1.name ← "Alice"
SET student1.id   ← 1023
SET student1.mark ← 78
OUTPUT student1.name, student1.mark

Algorithm Analysis (Correctness & Efficiency)

  • Correctness – state pre‑conditions (what must be true before the algorithm runs) and post‑conditions (what is guaranteed after it finishes).
  • Efficiency – discuss time‑complexity in terms of n (e.g. FOR i ← 1 TO n is O(n)). Avoid unnecessary nested loops when a linear solution exists.

Flow‑chart ↔ Pseudocode Conversion

  1. Identify symbols: oval = Start/End, parallelogram = Input/Output, rectangle = Process, diamond = Decision, arrows = flow.
  2. Translate each symbol into the matching pseudocode line using the conventions above.
  3. Maintain the same order: Input → Process (including loops/decisions) → Output.

Example Flow‑chart to Pseudocode

Flow‑chart: Read n → Initialise sum←0 → WHILE i ≤ n → sum←sum+i → i←i+1 → ENDWHILE → Output sum

# Sum of first n natural numbers
INPUT n
SET sum ← 0
SET i   ← 1
WHILE i ≤ n DO
    SET sum ← sum + i
    SET i   ← i + 1
ENDWHILE
OUTPUT sum

Common Pitfalls (AO2)

  • Omitting INPUT or OUTPUT – algorithm is incomplete.
  • Mixing input/output statements inside the process block (e.g. printing inside a loop that should only calculate).
  • Using ambiguous variable names (x, y) instead of descriptive ones (hoursWorked, grossPay).
  • Incorrect loop boundaries (off‑by‑one errors).
  • Forgetting ENDIF, ENDFOR, ENDWHILE – leads to mismatched blocks.
  • Not distinguishing between pre‑condition and post‑condition loops, causing an extra or missing iteration.

Assessment Tips (Paper 2 & Paper 3)

  • Read the question carefully: identify required inputs, processing steps and outputs before you start writing.
  • Plan with a quick sketch (flow‑chart or bullet list) – this helps with step‑wise refinement.
  • Use the exact keywords the syllabus expects (e.g. FOR not LOOP).
  • Check that every variable used is declared/initialised.
  • After writing, walk through the algorithm with a small data set to verify correctness.
  • For efficiency marks, comment on the time‑complexity of any loop you use.

Quick Audit Checklist – Full 9618 Coverage

Syllabus BlockPresent in Notes?Typical OmissionSuggested Add‑On
Information representation (binary, BCD, ASCII/Unicode, two’s‑complement, overflow)NoOnly mentioned in passing.Add a short subsection with binary addition, two’s‑complement example and overflow detection.
Multimedia (bitmap vs. vector, lossy vs. lossless compression)NoGraphics and sound rarely explained.Insert a table comparing formats and a calculation of bitmap file size.
Communication (networks, topologies, IP, DNS, client‑server vs. P2P, cloud, wired vs. wireless)NoTopology diagrams omitted.Include a labelled diagram of the 4‑layer model and a mini‑exercise converting an IPv4 address to binary.
Hardware (CPU, RAM/ROM types, embedded systems, buffers)NoEmbedded systems glossed over.Brief case study of a micro‑controller temperature sensor highlighting SRAM vs. DRAM.
Logic gates & circuitsNoTruth‑tables without circuit construction.Provide a three‑step activity: Boolean expression → truth‑table → circuit diagram.
Processor fundamentals (Von Neumann, registers, ALU, CU, bus, fetch‑decode‑execute cycle, interrupts)NoInterrupts omitted.Insert a flow‑chart of an interrupt‑service routine and bullet points on performance impact.
Assembly language & bit manipulationNoOnly a few instructions listed.Supply a two‑pass assembler example (LOAD, ADD, STORE) and a bit‑mask exercise (set/clear flag).
System software (OS functions, utilities, libraries, translators)NoDifferences between compiler, interpreter and IDE are thin.Add a comparison matrix and a short “read‑the‑code” activity using a tiny Java/Python snippet.

Sample Add‑On: Binary Representation & Overflow

# Convert decimal 13 to 8‑bit two’s‑complement binary
SET decimal ← 13
SET binary ← "00001101"          # direct conversion
OUTPUT "Binary (unsigned):", binary

# Subtract 20 using two’s‑complement
SET a ← 13                      # 00001101
SET b ← 20                      # 00010100
# Two’s‑complement of b
SET bComp ← "11101011"           # invert + 1
SET result ← a + bComp          # binary addition
# Detect overflow (carry out of MSB)
IF carry_out = 1 THEN
    OUTPUT "Overflow occurred"
ENDIF
OUTPUT "Result (two’s‑complement):", result

Sample Add‑On: Bitmap File‑Size Calculation

# 1024 × 768 image, 24‑bit colour
SET width  ← 1024
SET height ← 768
SET bitsPerPixel ← 24
SET totalBits ← width * height * bitsPerPixel
SET totalBytes ← totalBits / 8
SET totalKB ← totalBytes / 1024
OUTPUT "File size ≈", totalKB, "KB"

Summary

  1. Input – acquire all required data (constants, variables, arrays, records).
  2. Process – apply sequence, selection, iteration, CASE, recursion, or call procedures/functions. Use step‑wise refinement for complex problems.
  3. Output – present the final result(s) clearly.
  4. Follow Cambridge‑approved pseudocode conventions and always close block structures.
  5. Incorporate supporting syllabus topics (binary representation, multimedia, networking, hardware, logic, processor cycles, assembly, system software) to demonstrate a holistic understanding.
  6. Analyse correctness (pre‑/post‑conditions) and efficiency (time‑complexity) and be ready to convert between flow‑charts and pseudocode.

Create an account or Login to take a Quiz

94 views
0 improvement suggestions

Log in to suggest improvements to this note.