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.
רמת קושי 3/5 · 200 מטבעות + בונוס קטן בהשלמה הראשונה היום
Best starts at 8. Process values 5, 7, 2, replacing Best only when a value is smaller. Give Best after each value.
רמת קושי 3/5 · 200 מטבעות + בונוס קטן בהשלמה הראשונה היום
The starter finds the largest of NumberOfValues values but wrongly outputs zero for all-negative data. Correct it. NumberOfValues is 1 to 5.
לחץ על הרץ כדי לראות את התוצא כאן.
רמת קושי 3/5 · 200 מטבעות + בונוס קטן בהשלמה הראשונה היום
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.
נשמר להצעה זו בדפדפן זה. עיין בעצמך או עם המורה; הסברים אלו אינם מסומנים אוטומטית.
עיין בהסבר שלך לפי הקריטריונים הבאים
- 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.