Algorithms & Variables
Year 8 pupils often struggle when tracing through algorithmic steps, especially when variables change value multiple times. Understanding algorithms and variables forms the foundation of computational thinking in the KS3 computing curriculum and builds essential problem-solving skills for GCSE Computer Science.
Try it right now
Click βGenerate a problemβ to see a fresh example of this technique.
Why it matters
Algorithms and variables appear throughout real-world computing applications that pupils encounter daily. When Harry opens Spotify, an algorithm analyses his listening history across 500+ songs to recommend new tracks, updating preference variables continuously. Banking apps use algorithms to calculate Charlotte's account balance after 12 transactions, where each deposit or withdrawal updates her balance variable step-by-step. Traffic light systems follow algorithmic sequences, timing red lights for precisely 45 seconds before switching. Online shopping websites trace through pricing algorithms when Amelia adds 3 items to her basket, applying discount codes and updating the total cost variable from Β£67.50 to Β£52.20. Understanding these step-by-step processes helps pupils grasp how technology works and prepares them for programming challenges in GCSE Computer Science, where algorithm design and variable manipulation are core assessment objectives worth 40% of marks.
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
score = 1; score = score + 10. What is score?
Answer: 11
- Set initial value β x = 1 β x starts at 1.
- Add 10 to score β x = 1 + 10 = 11 β Score becomes 11.
x = 7; if x > 4: x = x - 5. What is x?
Answer: 2
- Check the condition β Is 7 > 4? Yes β 7 > 4 is true.
- Execute if true β x = 2 β Subtract 5: 7 - 5 = 2
x = 1; repeat 4 times: x = x * 2. What is x?
Answer: 16
- Trace each iteration β 1 -> 2 -> 4 -> 8 -> 16 β Double x, 4 times.
- Or use shortcut β 1 x 2^4 = 16 β Doubling 4 times is the same as 2^4.
Common mistakes
- Pupils forget that variables store new values, not accumulate them. When tracing x = 5; x = x + 3, they often write x = 5 + 3 = 8 instead of recognising x now equals 8.
- Students skip intermediate steps in loops, jumping from x = 2 to x = 16 without showing x = 4, x = 8 for each iteration of x = x Γ 2.
- Many pupils confuse assignment with equality. They read x = x + 1 as 'x equals x plus 1' (mathematically impossible) rather than 'x becomes x plus 1'.
- Students misread conditional statements, executing both branches. For 'if x > 10: x = x - 5', they subtract 5 regardless of x's value.