Trace, diagnose and repair algorithms
Trace in execution order
Record values after the statement or iteration named in the question. Carry unchanged values forward. Do not jump directly to the final answer: a trace table records the route taken.

Use a counterexample to find the fault
A greatest-value algorithm initialised with zero appears to work for positive data. The smallest counterexample is a single negative value. Known: the answer must be a member of the data. Therefore initialise from the first item, then compare remaining items.
DECLARE Best, Value : INTEGER
Best ← -8
Value ← -2
IF Value > Best THEN
Best ← Value
ENDIF
OUTPUT Best

Common mistakes
- Filling in only the final values. The table must show each change in the order it happens.
- Updating a variable in the wrong row: a value changes on the line that assigns it, not at the next
OUTPUT. - Fixing the line but not giving the cause. "Changed 0 to Data[1]" earns less than "0 is larger than every negative value, so it was never replaced".
- Testing only the counterexample after a fix. Rerun a normal case as well, so the fix has not broken it.
Distinguish error types
A syntax error breaks the language's structure; a runtime error occurs during execution, such as an out-of-bounds index; a logic error produces the wrong result despite running. After repairing a fault, test the counterexample and a normal case. Explain the cause, not just the changed line.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
Best starts at 8. Process values 5, 7, 2, replacing Best only when a value is smaller. Give Best after each value.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
The starter finds the largest of NumberOfValues values but wrongly outputs zero for all-negative data. Correct it. NumberOfValues is 1 to 5.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
The program executes without crashing but skips the last array item because its loop ends at NumberOfValues - 1. Is this a syntax, runtime or logic error? Enter one word.
Explain your choice of data structure and loop. Identify one boundary case and predict its result. For a subroutine, explain what is returned or changed in the caller.
Enregistré pour cette session sur ce navigateur. Revoyez-le vous-même ou avec votre enseignant ; ces explications ne sont pas automatiquement corrigées.
Revoyez votre explication selon ces critères
- My types and data structure match the data and the question.
- I justified the loop and checked its first and last iterations.
- Initial values and rejected operations preserve the intended state.
- My test includes input, purpose and expected result.
- I distinguished returning a value from printing and changing caller state.