Library Computer Science 0478 Algorithms
O Level · Computer Science 0478

Algorithms

Revise Algorithms for Computer Science 0478 (O Level) — revision notes and instant AI marking. Free to start.

📖 Revision notes · preview
Cambridge IGCSE 0478 · Computer Science

Algorithms

An algorithm is just a precise, step-by-step recipe for solving a problem — and you can write that recipe as a diagram, a flowchart, or pseudocode.

Structure Diagrams Flowcharts Pseudocode
Summary — The Whole Chapter in One Glance
  • An algorithm is a precise set of instructions for solving a specific problem or task — precise means unambiguous, every step has exactly one meaning.
  • There are three ways examiners expect you to design/represent an algorithm: structure diagrams (top-down hierarchy), flowcharts (visual shapes + arrows), and pseudocode (structured English-like text).
  • Structure diagrams break a big system down into smaller and smaller sub-problems — like a family tree of tasks.
  • Flowcharts use specific shapes: ovals for start/stop, parallelograms for input/output, rectangles for processes, and diamonds for decisions — connected by arrows showing the flow of control.
  • Pseudocode is more structured than plain English but must never use real programming syntax like print() or semicolons — that loses marks in the exam.
  • To explain an existing algorithm, you look at its inputs, its processing steps, its outputs, and (for complex ones) any comments, its context, or you test it with sample data.
  • If a question just says "write an algorithm" with no format specified, default to pseudocode — it's faster and it's what examiners expect unless told otherwise.
1. What Is an Algorithm?

Think about a recipe for making toast: put bread in toaster → wait 2 minutes → take bread out → spread butter. That's an algorithm — it's a sequence of exact, unambiguous steps that, if followed correctly by anyone (or any computer), always solves the same problem the same way.

The exam definition is short but every word matters: an algorithm is a precise set of rules or instructions to solve a specific problem or task. "Precise" is the key word — vague instructions like "cook it until it's done" aren't an algorithm, because different people would interpret "done" differently. A real algorithm might say "heat for exactly 4 minutes at 200°C."

Algorithms don't have to be written as computer code. Before a programmer ever writes a line of Python or Java, they usually design the algorithm first using one of three tools, because it's much easier to spot logic mistakes in a diagram or in plain-ish English than buried inside code syntax:

The Three Ways to Design an Algorithm
1. Structure Diagrams — visual, hierarchical, top-down breakdown of a system
2. Flowcharts — visual, shape-based, shows the flow of control step-by-step
3. Pseudocode — text-based, structured English-like statements
Quick Analogy
If a structure diagram is like an org chart showing who reports to whom, a flowchart is like a map with directions and decision points ("turn left if raining"), and pseudocode is like writing out the driving directions as a numbered list in plain words.
2. Structure Diagrams

Structure diagrams show a system broken down in a hierarchical, top-down way — like a family tree, but for tasks instead of people. You start with the whole system at the top, and each level below breaks that system into smaller, more manageable sub-problems. This process is sometimes called top-down design or decomposition.

Why bother? Because a big problem (like "build a mobile phone's software") is far too complex to solve or code all at once. But if you break it into "voice calls," "text messages," and "contact data store," and then break each of those down further, each individual box becomes small enough that it could realistically be written as a single subroutine (a mini-program/function).

How the boxes connect

Every box represents a task or sub-system. Lines with arrows connect a "parent" task to its "children" — the smaller tasks that make it up. The further down you go, the more detailed and specific the tasks become, until each box at the bottom is small enough to implement directly.

System
↓ ↓ ↓
Sub-system 1 Sub-system 2 Sub-system 3
↓ ↓ (from Sub-system 2)
Sub-system 2.1 Sub-system 2.2

Notice the naming pattern: Sub-system 2 breaks into 2.1 and 2.2. This numbering shows exactly where each box sits in the hierarchy — very handy for referencing specific parts of a large design.

Worked Example — Mobile Phone

The chapter's mobile phone example shows this in action. At the top is "Mobile phone." It splits into three sub-systems: "Voice calls," "Text messages," and "Contact data store." "Voice calls" then splits further into "Receive voice" and "Receive data," and those split even further — "Receive voice" leads down to things like "Convert to analogue" and eventually "Vibrate" (the phone alerting the user). Each branch keeps getting more specific and more technical the further down you travel.

Practice Question
A school wants to design a "Library System." Suggest three sensible sub-systems it could be broken into at the first level of a structure diagram.
3. Flowcharts

A flowchart is a visual tool that uses specific shapes to represent different types of steps in an algorithm, connected by arrows that show the flow of control — meaning the order in which steps actually happen. Unlike a structure diagram (which shows what a system is made of), a flowchart shows how the logic actually runs from start to finish, including decisions and loops.

The Four Shapes You Must Know

Cambridge IGCSE only expects you to recognise and use four shape types. Getting the right shape for the right job is an easy way to pick up marks — examiners really do check this.

START / STOP
Terminator — begins/ends the algorithm
INPUT number
Parallelogram — input / output
number ← 5
Rectangle — a process/calculation
Decision?
Diamond — Yes/No branching point
Shape Meanings — Memorise These
Oval = Start or Stop (Terminator)
Parallelogram = Input or Output
Rectangle = Process (a calculation or assignment)
Diamond = Decision (has exactly two exits: Yes/No or True/False)
Worked Example — Age Checker for a Website

Imagine a casino website that only lets in users aged 18 or over. Here's the logic traced through step by step:

Start
INPUT age
IS age >= 18 ?
Yes ↓            No → "Sorry, 18+ only"
OUTPUT "Welcome to the site"
Stop

Notice both branches of the decision eventually meet back up before "Stop" — that's a key habit in good flowchart design: don't leave a dangling branch that never reconnects to the main flow (unless it genuinely ends the algorithm early).

Refining an Algorithm
The chapter shows this same flowchart later "refined" so it also asks for the user's first name and greets them by name. This is a great example of how real algorithm design works — you rarely get it perfect first try. You build a basic working version, then refine it by adding more inputs, more outputs, or more logic, without breaking what already worked.
Practice Question
Which flowchart shape would you use to represent "Calculate total = price × quantity"? And which shape would you use for "Is stock < 10?"
4. Pseudocode

Pseudocode is a text-based way of writing an algorithm using short, structured, English-like statements. It sits in a sweet spot between plain English (too vague, too wordy) and real programming code (too strict, too fussy about syntax). It's "code-shaped" but doesn't belong to any specific programming language — which is exactly why exam boards love it: it tests your logic, not your memory of Python syntax.

The #1 Pseudocode Rule
Never write real code syntax — no print(), no input(), no semicolons, no curly braces.
Use simple keyword statements instead: INPUT, OUTPUT, IF...THEN...ELSE...ENDIF, REPEAT...UNTIL.
Worked Example — Same Casino Age Checker, in Pseudocode

Here's exactly the same logic as the flowchart above, written instead as pseudocode:

INPUT Age IF Age >= 18 THEN OUTPUT "Welcome to the site" ELSE OUTPUT "Sorry, this site is for users 18 and over" ENDIF

And here's the "refined" version that also asks for and uses the user's first name:

INPUT FName INPUT Age IF Age >= 18 THEN OUTPUT "Welcome to the site", FName ELSE OUTPUT "Sorry, this site is for users 18 and over" ENDIF

Notice how closely this mirrors the flowchart's logic — same inputs, same decision, same two outputs. This is intentional: structure diagrams, flowcharts, and pseudocode are three different notations for representing the exact same underlying algorithm. You should be able to convert between them.

Exam Default
If a question just says "write an algorithm" without specifying the format, default to pseudocode. Only draw a flowchart if the question explicitly asks for one, or if a visual layout would genuinely make the logic clearer.
Practice Question
Rewrite this incorrect pseudocode so it follows proper IGCSE style: input("Enter your name"); print(name);
5. Explaining Algorithms

Half of this chapter is about writing algorithms — the other half is about being able to read and explain one that someone else has written. This is a genuinely different skill: you're given a finished flowchart, pseudocode, or code snippet, and asked "what does this actually do?"

A well-designed algorithm should be understandable to a new reader just by following its instructions — that's the whole point of it being "precise." But when an algorithm gets complex (nested IFs, loops inside loops, arrays), you may need extra strategies to fully understand it:

Three Ways to Understand a Complex Algorithm
1. Look for comments in the code (notes left by the original author)
2. Consider the context — where and why is this algorithm being used?
3. Test the algorithm with different sample inputs and trace what happens
Worked Example — Adding Ten Numbers

Let's trace through this pseudocode line by line, the way you should in an exam:

Count ← 1 Number ← 0 Total ← 0 REPEAT INPUT Number Total ← Total + Number Count ← Count + 1 UNTIL Count > 10 OUTPUT Total

Reading this top to bottom: three variables get set to starting values (this is called initialising the variables). Then the loop begins — it asks the user to input a Number, adds that Number onto a running Total, and increases Count by 1 to keep track of how many numbers have been entered so far. This repeats until Count is greater than 10, meaning it will have looped exactly 10 times. Finally, it outputs the Total.

Purpose: the algorithm adds ten user-entered numbers together and outputs the sum.

Worked Example — Grading Marks (Nested IF Statements)

This is the trickier worked example from the chapter — a teacher's grading algorithm that uses arrays and deeply nested IF statements:

Count ← 0 REPEAT INPUT Score[Count] IF Score[Count] >= 70 THEN Grade[Count] ← "A" ELSE IF Score[Count] >= 60 THEN Grade[Count] ← "B" ELSE ... more nested IFs for C, D, E, F ... ENDIF ENDIF Count ← Count + 1 UNTIL Count = 30

Here's the trick to reading nested IFs without getting lost: work from the top condition downward, and remember only ONE branch ever actually runs for a given score. A score of 65 checks "is it ≥70?" → No → drops into the ELSE → checks "is it ≥60?" → Yes → assigns Grade "B" and skips all the rest. The nesting is really just a chain of "if this doesn't apply, check the next possibility" — like a sorting hat trying category after category until one fits.

This algorithm: stores 30 inputted marks in the array Score[], checks each mark against a series of boundaries (70, 60, 50, 40, 30), assigns a matching letter grade, stores that grade in Grade[] at the same index as the mark it came from, and stops once 30 marks have been processed.

Common Trap
Students often think Count[] and Score[] are separate unrelated arrays. They're not — the "same index" link is essential: Grade[5] is specifically the grade for Score[5]. Exam mark schemes explicitly award a point for stating this connection.
Practice Question
In the grading algorithm above, a student scores exactly 60. Which grade do they receive, and why does the nesting only check up to "≥60" before stopping?
What to Memorise
Algorithm
A precise set of rules or instructions to solve a specific problem or task. "Precise" means unambiguous — every step must have exactly one clear meaning.
Structure Diagram
A visual, hierarchical, top-down diagram that breaks a system into sub-systems and further sub-problems, down to a level small enough to code as a single subroutine.
Flowchart
A visual algorithm tool using shapes (oval = start/stop, parallelogram = input/output, rectangle = process, diamond = decision) connected by arrows showing the flow of control.
Pseudocode
A structured, text-based way of writing algorithms using English-like keyword statements (INPUT, OUTPUT, IF...THEN...ELSE...ENDIF, REPEAT...UNTIL) — never real programming syntax.
Flow of Control
The order in which the steps of an algorithm are actually carried out — shown by the arrows/lines in a flowchart.
Decomposition / Top-Down Design
Breaking a large, complex problem down into smaller, more manageable sub-problems — the core idea behind structure diagrams.
Refining an Algorithm
Improving or extending an existing working algorithm — for example, adding a new input or output — without breaking its original logic.
Concepts Checklist
Exam Tips
Don't use real code syntax in pseudocode. Writing print("Welcome") instead of OUTPUT "Welcome" is one of the most common ways students lose marks — even if the logic is completely correct.
Use the right flowchart shape. A decision must always be a diamond with exactly two exits (Yes/No). Using a rectangle for a decision, or a diamond for a process, will cost you marks even if the flow is logically right.
Reconnect your branches. When a flowchart's decision has two paths (Yes/No), make sure both paths eventually rejoin the main flow before Stop, unless one branch is genuinely meant to end the algorithm early.
When explaining an algorithm, describe purpose AND process. Mark schemes usually award separate points for stating what the algorithm achieves overall, and for describing the individual steps (inputs, calculations, storage, outputs) that get it there.
Trace nested IFs one condition at a time, top to bottom. Don't try to read them all at once — follow the logic like a decision tree, and remember only one branch ever actually executes.
Match indices in arrays. If a question uses two related arrays (like Score[] and Grade[]), always mention that they're linked by the same index — this is a specific, separately-marked point in many mark schemes.
Default to pseudocode. Unless the question explicitly says "draw a flowchart" or "draw a structure diagram," write pseudocode — it's quicker to produce and it's the format examiners expect by default.
🔓 Read the full Algorithms note — free You're seeing the preview · free account, no card needed
What's inside
📖 Revision notes 🎯 Learn mode ✦ AI flashcards ✓ Instant AI marking 🧊 3D explorers 🧪 Experiments & simulations 📈 Progress tracking
📄 Practise Algorithms with Computer Science 0478 past papers Every paper with its mark scheme — answer online, marked instantly. Open →

Read the full Algorithms notes free

That's the preview — create a free account to read the rest, plus flashcards and practice questions with instant AI marking. No credit card.

Unlock the full notes free →

More Computer Science topics