Write pseudocode that contains input, process and output
9.2 Algorithms – Pseudocode Basics
What is Pseudocode?
Pseudocode is a simple, human‑readable way of describing an algorithm. It looks like code but is written in plain English (or a mix of English and symbols). Think of it as a recipe that tells a computer what to do, step by step. 🍰
Three Core Parts of an Algorithm
- Input – What data does the algorithm start with? 🔢
- Process – The steps that transform the input into something new. 🔄
- Output – The final result the algorithm produces. 📤
Writing Pseudocode – A Simple Example
Let’s write pseudocode to find the largest number in a list of integers.
| Step | Pseudocode |
|---|---|
| 1 | INPUT list_of_numbers |
| 2 | max_value ← list_of_numbers[0] |
| 3 | FOR each number IN list_of_numbers DO |
| 4 | IF number > max_value THEN |
| 5 | max_value ← number |
| 6 | END IF |
| 7 | END FOR |
| 8 | OUTPUT max_value |
Notice how each line clearly states an action: INPUT, FOR, IF, OUTPUT. This structure helps both humans and computers understand the flow.
Common Pseudocode Conventions
- Use capitalised keywords (e.g.,
IF,FOR) to highlight control flow. - Indent nested blocks to show hierarchy.
- Keep variable names descriptive (e.g.,
max_valueinstead ofm). - Use mathematical symbols where helpful: $x \leftarrow x + 1$.
Exam Tip Box
Exam Tip:
• Always label the three parts: Input, Process, Output. • Use clear indentation to show loops and conditionals. • When writing pseudocode, avoid programming syntax (like semicolons) – keep it readable. • Practice with different problems (sorting, searching, summing) to build confidence.
Quick Practice Challenge
Write pseudocode to calculate the average of a list of numbers. Remember to include the three core parts and use clear, descriptive names. Try it on paper before typing your answer! 📝
Revision
Log in to practice.