Algorithms & Variables
An algorithm is a finite sequence of precise, unambiguous instructions designed to solve a specific problem or perform a particular task. Variables serve as named storage locations that hold values which can change during algorithm execution. Together, they form the foundation of computational thinking and programming logic.
Why it matters
Algorithms govern countless daily activities, from GPS navigation systems calculating the fastest route among 50,000 possible paths to online shopping platforms sorting through millions of products in under 0.2 seconds. Banking systems process over 150 billion transactions annually using algorithmic verification, whilst social media feeds use algorithms to select content from thousands of posts. In education, algorithms appear in KS3 computing curriculum and GCSE Computer Science specifications, building logical reasoning skills essential for problem-solving across disciplines. Modern search engines execute over 8.5 billion queries daily through sophisticated ranking algorithms, demonstrating how algorithmic thinking scales from simple classroom exercises to global infrastructure.
How to solve algorithms & variables
Algorithms
- An algorithm is a step-by-step set of instructions to solve a problem.
- Must be precise, unambiguous, and have a clear end.
- Flowcharts use shapes: oval (start/end), rectangle (process), diamond (decision).
- Trace through algorithms with sample inputs to check correctness.
Example: Find max of a, b: if a > b → max = a, else max = b.
Worked examples
x = 9; x = x + 10. What is x?
Answer: 19
- Set initial value → x = 9 — x starts at 9.
- Add 10 → x = 9 + 10 = 19 — x becomes 19.
score = 14; if score <= 14: score = score - 1. What is score?
Answer: 13
- Check the condition → Is 14 <= 14? Yes — 14 <= 14 is true.
- Execute if true → x = 13 — Subtract 1: 14 - 1 = 13
x = 1; repeat 6 times: x = x * 2. What is x?
Answer: 64
- Trace each iteration → 1 -> 2 -> 4 -> 8 -> 16 -> 32 -> 64 — Double x, 6 times.
- Or use shortcut → 1 x 26 = 64 — Doubling 6 times is the same as 2^6.
Common mistakes
- Confusing assignment with equality: writing x = x + 5 when x = 3 and expecting the answer to be 8 = 3 + 5 instead of recognising that x becomes 8
- Misunderstanding loop iterations: executing x = x * 2 starting from x = 3 for 4 loops and calculating 3 * 2 * 4 = 24 instead of tracing 3 → 6 → 12 → 24 → 48
- Incorrect condition evaluation: with score = 15 and condition 'if score >= 15', concluding the condition is false instead of recognising that 15 >= 15 is true