Library Computer Science 0478 Standard Methods of a Solution
O Level · Computer Science 0478

Standard Methods of a Solution

Revise Standard Methods of a Solution for Computer Science 0478 (O Level) — revision notes and instant AI marking. Free to start.

📖 Revision notes · preview
  Cambridge (CIE) IGCSE — Computer Science

Standard Methods of a Solution

Big idea: most exam algorithms are just a handful of repeatable patterns — search, sort, total, count, and find the max/min/average — and once you know the pattern, you can write it for any dataset.

Quick Summary
Skim this first. Every bullet gets its own full section below.
Linear SearchCheck every value, one at a time, from the start, until you find the target or run out of values.
Bubble SortCompare neighbouring pairs and swap them if they're in the wrong order. Repeat passes until a whole pass makes zero swaps.
TotallingKeep a running sum by adding each new value to a variable that starts at 0.
CountingIncrease (or decrease) a counter by a fixed amount, usually 1, each time something happens.
Max / Min / AverageFind the biggest, smallest, and mean value in a list — average = total ÷ count.
Why it mattersThese five patterns appear, combined and recombined, in almost every algorithm question on the paper.
1. Linear Search
Finding a value the "brute force" way

1What is a searching algorithm?

A searching algorithm is a precise, step-by-step set of instructions a computer follows to find a specific piece of data inside a (possibly huge) dataset — like finding one name in a phone book with a million entries, but doing it in a way a computer can follow exactly, with no "just eyeballing it."

2What is a linear search?

Imagine you're looking for your friend's name in an unsorted stack of index cards. You don't know where it is, and the cards aren't in any order — so your only honest option is to pick up the first card, check it, then the second, then the third, and so on, until you either find the name or run out of cards. That's exactly what a linear search does.

  • It starts at the first value in the dataset.
  • It checks values one at a time, in order.
  • It can be used even if the data is completely unsorted — that's actually its one big advantage over faster searches like binary search, which require sorted data.
The Rule
1. Check the first value.
2. IF it matches → STOP, found it.
3. ELSE move to the next value.
4. REPEAT until you've checked everything (or found it).

Here's the pseudocode from the textbook, worked through step by step. We're searching for target = 11 in data = [5, 2, 8, 1, 9]:

DECLARE data : ARRAY[1:5] OF INTEGER
DECLARE target : INTEGER
DECLARE found : BOOLEAN

data ← [5, 2, 8, 1, 9]
target ← 11
found ← FALSE  // assume not found until proven otherwise

FOR index ← 1 TO 5
   IF data[index] = target THEN
      found ← TRUE
      OUTPUT "Target found"
   ENDIF
NEXT index

IF found = FALSE THEN
   OUTPUT "Target not found"
ENDIF

Notice the shape of this: a flag variable (found) starts as FALSE, and only flips to TRUE if a match is discovered. After the loop finishes, you check the flag to decide what to output. This "flag pattern" shows up constantly in IGCSE pseudocode — get comfortable with it.

Why Python's version is smarter In the Python version, once a match is found the code uses break to exit the loop immediately — there's no point checking the rest of the list once you've already found what you're looking for. Pseudocode doesn't always show this optimisation, but it's good practice to mention it if you're writing your own search in an exam.
Practice Question 1

A linear search is being performed on the list [12, 45, 3, 67, 9] looking for the value 67. How many comparisons does the algorithm make before it finds the target, and why can a linear search be used here even though the list isn't sorted?

Practice Question 2

What would the algorithm output if it searched the same list [12, 45, 3, 67, 9] for the value 100? Explain why, referring to the found flag.

2. Bubble Sort
Sorting by repeatedly comparing neighbours

1What is a sorting algorithm?

A sorting algorithm is a set of step-by-step instructions that rearranges data into a specific order — usually numerical (smallest to largest) or alphabetical (A to Z).

2What is a bubble sort?

Think of a bubble sort like a line of people standing in a random order of height, and you (the "algorithm") walk down the line comparing each pair of neighbours. If the person on the left is taller than the person on the right, you swap them. You keep walking to the end of the line — that's one full pass. Then you walk the whole line again, and again, until you make a full pass with zero swaps — meaning everyone is finally in order.

The name "bubble sort" comes from the fact that on each pass, the largest unsorted value "bubbles up" to its correct position at the end — a bit like an air bubble rising to the top of water.

The Rule
1. Compare the first pair.
2. IF out of order → swap them.
3. Move to the next pair, repeat until the end (this is one pass).
4. IF any swap happened in that pass → do another pass.
5. ELSE (no swaps at all) → STOP, it's sorted.

Let's trace Pass 1 on the dataset [9, 2, 4, 7, 10, 3, 1] from the textbook, comparing neighbours left to right:

ComparisonResultList after step
9 vs 2✓ SWAP2, 9, 4, 7, 10, 3, 1
9 vs 4✓ SWAP2, 4, 9, 7, 10, 3, 1
9 vs 7✓ SWAP2, 4, 7, 9, 10, 3, 1
9 vs 10✗ no swap2, 4, 7, 9, 10, 3, 1
10 vs 3✓ SWAP2, 4, 7, 9, 3, 10, 1
10 vs 1✓ SWAP2, 4, 7, 9, 3, 1, 10

See how 10, the largest number, "bubbled" all the way to the end of the list in just one pass? That always happens — the biggest unsorted value reaches its final position by the end of every pass. That's why, on the next pass, you technically don't even need to re-check the last element again (though you don't have to worry about that detail for the exam).

Examiner Tip You do NOT need to write out every single comparison in an exam answer. Showing the state of the list at the end of each pass is enough to get full marks, as long as the end result is correctly sorted through legitimate passes.

Here's the full pseudocode, using a swaps flag exactly like the found flag in linear search:

DECLARE nums : ARRAY[1:11] OF INTEGER
nums ← [66, 7, 69, 50, 42, 80, 71, 321, 67, 8, 39]
DECLARE numlength : INTEGER
numlength ← 11
DECLARE swaps : BOOLEAN
swaps ← TRUE

WHILE swaps = TRUE
   swaps ← FALSE
   FOR y ← 1 TO numlength - 1
      IF nums[y] > nums[y + 1] THEN
         DECLARE temp : INTEGER
         temp ← nums[y]
         nums[y] ← nums[y + 1]
         nums[y + 1] ← temp
         swaps ← TRUE  // a swap was made
      ENDIF
   NEXT y
   numlength ← numlength - 1  // last value now sorted, shrink range
ENDWHILE
Why the temp variable? To swap two values in most languages you can't just say nums[y] ← nums[y+1] — that would overwrite nums[y] before you've saved its original value anywhere. So you store it in a temporary variable first: save the original left value into temp, overwrite the left value with the right value, then put temp into the right-hand slot. (Python can skip this using a, b = b, a, but pseudocode and most other languages need the temp variable.)
Practice Question 3

Perform a bubble sort on the list [8, 3, 5, 1]. Show the state of the list at the end of each pass.

Practice Question 4

A student says: "A bubble sort always needs exactly as many passes as there are items in the list." Is this true? Explain your reasoning using the algorithm's actual stopping condition.

3. Totalling & Counting
The two simplest — and most-used — building blocks in any algorithm

1What is totalling?

Totalling means keeping a running sum of values as they're entered or read — exactly like a supermarket till adding up the price of items as they're scanned. You start a variable at 0, and every time a new value comes in, you add it on.

The Rule
Total ← 0, then on each iteration: Total ← Total + NewValue
Total ← 0
FOR Count ← 1 TO ReceiptLength
   INPUT ItemValue
   Total ← Total + ItemValue
NEXT Count
OUTPUT Total

Notice: Total must start at 0 before the loop. If you forgot to initialise it, the first "add" would be adding onto an undefined value — a classic bug (and a classic mark lost in the exam).

2What is counting?

Counting is when a variable is incremented (or decremented) by a fixed step — usually 1 — every time a loop iterates, to track how many times something has happened. It's different from totalling: totalling adds up the actual values, counting just tallies the number of occurrences.

The Rule
Count ← 0 (or a starting number), then each loop: Count ← Count + 1 (increment) or Count ← Count - 1 (decrement)

Incrementing example — counting up to 50:

Count ← 0
DO
   OUTPUT "Pass number", Count
   Count ← Count + 1
UNTIL Count >= 50

Decrementing example — counting down from 50 to 0:

Count ← 50
DO
   OUTPUT "Pass number", Count
   Count ← Count - 1
UNTIL Count <= 0
Common Mistake Mixing up the loop condition direction. If you're decrementing (Count - 1) but write UNTIL Count >= 50, the loop will either never end or never run — always double-check the UNTIL/WHILE condition matches whether the counter is going up or down.
Practice Question 5

A shop till reads five item prices: 2.50, 4.00, 1.25, 6.75, 3.00. Write pseudocode using totalling to calculate and output the receipt total (you can adapt the textbook's example).

Practice Question 6

Explain, in your own words, the difference between totalling and counting, using an example of each from a real-world scenario (not from the textbook).

4. Maximum, Minimum & Average
Squeezing three useful stats out of one list

1Why these three together?

Finding the largest (max), smallest (min), and average (mean) of a list are extremely common tasks — think leaderboard high scores, coldest/hottest temperature of the week, or a class's average test grade. They're grouped together here because in practice you often calculate all three from the same dataset in one go.

The Rule
Max = the largest value in the list. Min = the smallest value in the list. Average = Total of all values ÷ Number of values (count).

Here's the textbook's pseudocode, finding all three from a list of test scores:

Total ← 0
Scores ← [25, 11, 84, 91, 27]

Highest ← max(Scores)
Lowest ← min(Scores)

FOR Count ← 0 TO LENGTH(Scores) - 1
   Total ← Total + Scores[Count]
NEXT Count

Average ← Total / LENGTH(Scores)

OUTPUT "The highest score is:", Highest
OUTPUT "The lowest score is:", Lowest
OUTPUT "The average score is:", Average

For this dataset: Highest = 91, Lowest = 11, and Total = 25+11+84+91+27 = 238, so Average = 238 ÷ 5 = 47.6.

Watch out This example uses built-in max() and min() functions, which many exam boards allow — but you should also know how to find max/min manually with a loop, in case a question asks you not to use built-in functions. The pattern: set Highest to the first item, then loop through the rest, and whenever you find something bigger, update Highest.
// Manual method — no built-in max() function
Highest ← Scores[0]
FOR Count ← 1 TO LENGTH(Scores) - 1
   IF Scores[Count] > Highest THEN
      Highest ← Scores[Count]
   ENDIF
NEXT Count
Practice Question 7

A list of temperatures recorded over a week is [18, 22, 15, 30, 19, 21, 17]. Calculate the highest, lowest, and average temperature by hand, showing your working for the average.

Practice Question 8

Write pseudocode to manually find the lowest value in a list (without using a built-in min() function), following the same pattern shown above for finding the highest value manually.

What to Memorise
Your last-minute-before-the-exam cheat sheet
Linear Search
Checks every value from the start, one at a time, until the target is found or the list ends. Works on unsorted data. Uses a boolean found flag, starting FALSE.
Bubble Sort
Compares adjacent pairs and swaps them if out of order. One full left-to-right run = one pass. Stops when a pass makes zero swaps. Uses a boolean swaps flag, starting TRUE to enter the loop.
Totalling
A running sum. Initialise Total ← 0 before the loop, then Total ← Total + value inside it.
Counting
A tally, not a sum. Increment/decrement by a fixed step (usually 1) each iteration: Count ← Count + 1.
Maximum / Minimum
Manually: set the "best so far" to the first item, then loop through the rest, updating whenever a better value appears (> for max, < for min).
Average (Mean)
Average = Total ÷ Count (i.e. the total of all values divided by how many values there are).
Temp Variable (Swap)
Needed to swap two values in pseudocode: save one value into temp, overwrite it with the other, then assign temp into the freed-up slot.
Concepts Checklist
Tick off each idea once you can explain it without looking back
Exam Tips
What examiners actually reward — and the traps that lose easy marks
Tip 1 — You don't need every micro-step For linear search, you don't need to show a full trace on the exam. For bubble sort, examiners are happy if you show the list at the end of each pass — you don't have to write out every single individual comparison, as long as the passes are correct and lead to a fully sorted final list.
Tip 2 — Always initialise before the loop Total ← 0 and found/swaps flags must be set before the loop starts, not inside it (or the value resets every iteration, breaking the logic). This is one of the most common mark-losing mistakes.
Tip 3 — Match your loop condition to your counter's direction If a counter increments, your exit condition should use >=. If it decrements, use <=. Mixing these up creates an infinite loop or a loop that never runs — a classic trap in "identify the error" style questions.
Tip 4 — Don't forget the swap needs a temp variable In pseudocode and most exam-board languages, swapping two array elements needs a third, temporary variable to hold one value while you overwrite it. Forgetting this (or writing nums[y] ← nums[y+1] and then nums[y+1] ← nums[y] without a temp) is a very common error that loses marks.
Tip 5 — Average always means Total ÷ Count Every "average" or "mean" question ultimately boils down to this one formula. If a question asks you to code it, you need both a totalling loop and a count of how many items there are — don't forget to divide by the length of the list at the end.
Standard Methods of a Solution — Revision Guide · Built for offline study
🔓 Read the full Standard Methods of a Solution 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 Standard Methods of a Solution with Computer Science 0478 past papers Every paper with its mark scheme — answer online, marked instantly. Open →

Read the full Standard Methods of a Solution 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