Test algorithms using trace tables and test data
Algorithm Design & Problem‑Solving 📐
In IGCSE Computer Science, you’ll learn how to turn a problem into a clear step‑by‑step plan (an algorithm) and then test it with trace tables and real data. Think of an algorithm like a recipe for a cake – it tells you exactly what ingredients to use and in what order.
What is a Trace Table? 🔍
A trace table records the values of variables at each step of the algorithm. It’s like a diary that shows how the algorithm changes the data.
Example: Find the Largest of Three Numbers
Algorithm (pseudo‑code):
- Input three numbers:
a,b,c. - Set
max=a. - If $b > \text{max}$, set
max=b. - If $c > \text{max}$, set
max=c. - Output
max.
Let’s trace the algorithm with the test data a = 7, b = 12, c = 5:
| Step | a | b | c | max |
|---|---|---|---|---|
| 1 | 7 | 12 | 5 | — |
| 2 | 7 | 12 | 5 | 7 |
| 3 | 7 | 12 | 5 | 12 |
| 4 | 7 | 12 | 5 | 12 |
| 5 | 7 | 12 | 5 | 12 |
Result: max = 12.
Exam Tip Box 📝
Analogy: The Algorithm as a Road Map 🚗
Imagine you’re planning a road trip. The algorithm is the map that tells you which roads to take, when to stop for gas, and how to avoid traffic. A trace table is like a GPS that records every turn you make, so you can see if you followed the map correctly.
Practice Question
Write a simple algorithm that checks whether a number n is even or odd. Then create a trace table for n = 7 and n = 10.
Key Takeaways 🎯
- Algorithms are step‑by‑step instructions that solve a problem.
- Trace tables help you verify that each step behaves as expected.
- Always test your algorithm with multiple data sets.
- Use clear, descriptive variable names.
- In exams, show your trace table neatly and label every column.
Good luck, and remember: practice makes perfect! 🚀
Revision
Log in to practice.