51 exam-style questions on Algorithm Tracing — topic SK.Algorithm_tracing of Skills in the IB Computer Science syllabus — with answers and explanations. Samples below; the full set is free with an account.
Which set of columns makes a trace table of a loop useful to the person checking the algorithm?
Answer: One column for each variable that changes, plus the condition being tested.
The purpose of the table is to show where a value first becomes wrong, which needs the changing variables side by side and the condition that decides whether the loop runs again. Recording only the input and the output turns the trace back into a guess.
A search over an array of 5 elements, indexed from 0, is traced. The index column of the trace table reads 0, 1, 2, 3, 4, 5, and in the last row index 5 is used to read an element. What has the trace revealed?
Answer: The loop runs one pass too many and reads past the last element.
With indices running from 0 to 4 the only legal reads stop at 4, so a read at 5 shows that the terminating condition is one step too generous. This off-by-one error is exactly what a trace table exposes, because the faulty index appears in a row of its own.
A hand trace of a sorting algorithm gives the expected result for the data [3, 1, 2], yet the algorithm still fails on real data. What is the most likely cause?
Answer: The chosen test data never produces the case in which the fault appears.
A trace proves the algorithm only for the values traced, so data that never reaches the faulty branch, such as duplicates or an already sorted array, hides the defect. Choosing data that touches the boundary cases is what makes tracing a test rather than a demonstration.
While tracing, a candidate finds that the variable holding a running total is never given a value before the loop begins. What should be reported?
Answer: That the total is uninitialised, so the result of the algorithm is undefined.
A running total has to start from a known value, normally zero, or the first addition works on whatever the variable happens to contain. A trace exposes this at once, because the first row of the table has no value to write down.
A candidate wants to check a search algorithm by tracing it. Which choice of data reveals the most faults for the least work?
Answer: One case with the target first, one with it last, one with it absent
Faults in a search cluster at the two ends and in the case where the loop must finish without success, so those three cases between them exercise the boundaries and the exit condition. A middle case is the one situation almost every incorrect version handles correctly, which is why it proves the least.
A trace table is being built for an algorithm containing one loop nested inside another. How many rows of values should it contain?
Answer: One for each pass of the inner loop, plus a starting row
The inner loop is where the values actually change most often, so a row per outer pass would hide everything the inner loop did. Recording a row per statement produces a table far longer than the algorithm and no easier to read.
That was 6 of 51 Algorithm Tracing questions.
Practise all 51 freeTraceAO2 · 2–4 marks
Follow the algorithm step by step in a trace table, one row per pass, showing every variable that changes.
OutlineAO1 · 1–2 marks
A brief account or summary: the main points in two or three sentences, no evaluation.
ExplainAO2 · 2–4 marks
Give reasons or causes: say what happens AND why, linking each step with 'because' or 'so that'.
51 Algorithm Tracing questions — free with an account. Spaced repetition, streaks and full exam simulations included.
Practise them freeThis platform is independently developed and is not endorsed by, affiliated with, or sponsored by the International Baccalaureate Organization. “International Baccalaureate” and “IB” are registered trademarks of the IBO.