OCR GCSE Computer Science J277
Systems Architecture
Memory and Storage
Computer Networks, Connections and Protocols
Network Security
Systems Software
Ethical, Legal, Cultural and Environmental Impacts of Digital Technology
Algorithms
Programming Fundamentals
Producing Robust Programs
Programming Languages and Integrated Development Environments
Algorithms
Trace tables and correcting algorithms
- 3 things to know
- J277/02
Overview
Trace tables and why they are used, the output of short algorithms in Exam Reference Language, and finding and fixing errors in given code.
What you need to know
Answer each one before you reveal it.
Explain why trace tables are used.
What is output by the algorithm n = 1, do, n = n * 3, until n > 20, print(n)?
Questions from this subtopic
Each one with the model answer underneath.
- 1
What is a trace table?
Model answer
A trace table records how the values of variables change as an algorithm runs. Each row shows the values after a step, and outputs have their own column.
- 2
Explain why trace tables are used.
Model answer
A trace table shows exactly what an algorithm does with a given set of data. A trace can reveal a logic error or the purpose of an unfamiliar algorithm.
- 3
What is output by the algorithm total = 0, for i = 1 to 6, if i MOD 2 == 1 then total = total + i endif, next i, print(total)?
Model answer
The algorithm prints 9. The nested if statement adds only the odd values of i, so total becomes 1, then 4, then 9.
- 4
What is output by the algorithm x = 50, count = 0, while x > 5, x = x DIV 2, count = count + 1, endwhile, print(count)?
Model answer
The algorithm prints 4. The variable x falls to 25, 12, 6 and then 3, and count rises by 1 each time. The loop stops because 3 is not greater than 5.
- 5
What is output by the algorithm n = 1, do, n = n * 3, until n > 20, print(n)?
Model answer
The algorithm prints 27. The variable n becomes 3, then 9, then 27, and the loop stops once n is greater than 20.
- 6
Which values appear in the total column of a trace table for total = 0, for i = 1 to 3, total = total + i * i, next i?
Model answer
The total column shows 0, then 1, 5 and 14. Each pass adds the square of i, so the final value of total is 14.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Algorithms, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.