Software Engineering › How to answer › trace table and desk checking questions
How to answer trace table and desk checking questions
A trace table records the value of every variable as you follow an algorithm line by line. It is the safest way to answer “what does this algorithm output?” and to find logic errors. From course notes
What it looks like in the real exam
Reasoned The 2025 NESA papers in our bank do not contain a table-completion desk check as a written question. Tracing is examined indirectly: multiple-choice items that ask for the output of a short algorithm (for example the 2022 SDD Q8 loop item, old syllabus, used in the multiple choice page), Python “what is printed” items, and pseudocode debugging. The old (SDD) papers examined it directly, as desk-check tables and debugging: 2023 HSC Software Design and Development, Q28, 2022 HSC Software Design and Development, Q28 and 2024 HSC Software Design and Development, Q23 (desk check and debugging), and 2021 HSC Software Design and Development, Q28 (debugging a binary search). They are old syllabus, so treat them as skills practice.
Reasoned Whether the current exam includes a table-completion item is not published. Learn the method anyway, because it is how you get multiple-choice trace items right under time pressure.
Method
- Read the algorithm once and list every variable (inputs, counters, totals, flags) and the output. Each gets a column. Put them in order of first appearance. From course notes
- Write the test data above the table (which values the Get statements read, or the starting values). From course notes
- Start at the first line. Never skip a line; use a pencil finger or the line numbers. General advice
- Every time a variable changes, write the new value in its column on a new row. Leave the other columns for that row blank if the value did not change. General advice Reasoned Some teachers show every variable on every row; ask which style your school uses. Either is correct if the values are right.
- At every IF or loop test, evaluate it exactly with the current values (use the exact comparison:
>is not>=). Write TRUE or FALSE in a test column if that helps. General advice - At the end of the loop body, jump back to the loop test. A WHILE tests before each pass; a REPEAT…UNTIL tests after, so it always runs once. From course notes
- Write the output when Display runs, in the output column. General advice
- Sanity check: does the final result match what the algorithm is supposed to do? If not, you have found a logic error: say which line. General advice
Worked example: a WHILE loop (original)
Original practice What does this algorithm display?
BEGIN Mystery
x = 3
y = 0
WHILE x > 0
y = y + x * 2
x = x - 1
ENDWHILE
Display y
END Mystery
| Step | x | y | x > 0 ? | Output |
|---|---|---|---|---|
| Start | 3 | 0 | ||
| Pass 1 | 6 | TRUE (x = 3) | ||
| 2 | ||||
| Pass 2 | 10 | TRUE (x = 2) | ||
| 1 | ||||
| Pass 3 | 12 | TRUE (x = 1) | ||
| 0 | ||||
| Test | FALSE (x = 0): leave the loop | |||
| Display | 12 |
Answer: 12. (Verified by running the algorithm in Python: 6 + 4 + 2.) Notice: y = y + x * 2 uses the old x, and x is reduced after.
Reasoned The table above uses one row per change. A one-row-per-pass version is equally valid: Pass 1: y=6, x=2; Pass 2: y=10, x=1; Pass 3: y=12, x=0.
Worked example from an old NESA paper (desk check with the official criteria)
Old syllabus This is a 6-mark old-syllabus question. Part (a) (3 marks) is a desk check of a validation algorithm using the test data “p3”, “Pad”, “Q”, “X”. The algorithm contains errors, and part (b) asks you to find two. The official criteria are below.
2023 HSC Software Design and Development, Q28 · 6 marks Old syllabus (use for the skill only)
Official marking criteria
NESA sample answer (the table layout was lost in text extraction, read the values in order)
Sample answer: OK | ProductCode | Len | Extracted | Count | Display character F | p3 | 2 T | p F | Not uppercase p | 1 F | 3 | 2 | Not all lowercase Invalid code F | Pad | P T | P | 1 | Not all lowercase F | a | 2 Invalid code T | Q Note: X is not considered [Question 28 (b)] Sample answer: At line 110 the FOR/NEXT loop counter should start at 2. The value of Len is not being updated for the next ProductCode. Move line 40 to line 55.
Notes
Open this question page · some of the NESA wording or answer is an image or is unpublished, as noted
Reasoned What to learn from it: the sample answer traces each test value through every line, writes “Display” messages in the output column, and notices that the test data “Q” ends the loop, so “X” is never processed. The two errors it names are (1) the FOR loop at line 110 starts at 1, so it tests the first (uppercase) character as lowercase; it should start at 2; and (2) Len is set at line 40 before the loop and never updated for the next input; it should be moved into the loop.
Common mistakes
- General advice Updating a variable too early or too late (using the new x instead of the old x).
- General advice Not testing the loop condition on the last pass.
- General advice Treating
>as>=. - General advice Forgetting to record the output.
- General advice Skipping a line “because it looks obvious”.
- General advice Re-using the previous row’s old value after it has changed.
Time per mark
Derived 140 minutes ÷ 80 marks = 1.75 minutes per mark, so 3 marks ≈ 5.3 minutes.
General advice A short loop (3 passes) trace takes 2 to 3 minutes. Tracing a multiple-choice item properly is worth it: sketch the columns on your scrap paper, if the exam allows paper (check NESA’s instructions).
Practice (4 items, with answers; verified by running the code)
Item 1 · find the largest
Scores = 5, 8, 3, 9, 6 (positions 1 to 5).
Largest = Scores[1]
FOR i = 2 TO 5
IF Scores[i] > Largest THEN
Largest = Scores[i]
ENDIF
NEXT i
Display LargestComplete a trace table and state the output.
Show the answer
| i | Scores[i] | Scores[i] > Largest? | Largest |
|---|---|---|---|
| 5 (start) | |||
| 2 | 8 | TRUE | 8 |
| 3 | 3 | FALSE | 8 |
| 4 | 9 | TRUE | 9 |
| 5 | 6 | FALSE | 9 |
Output: 9. Original practice
Item 2 · sum of evens
Total = 0
FOR n = 1 TO 6
IF n MOD 2 = 0 THEN
Total = Total + n
ENDIF
NEXT n
Display TotalWhat is displayed?
Show the answer
| n | n MOD 2 = 0 ? | Total |
|---|---|---|
| 0 (start) | ||
| 1 | FALSE | 0 |
| 2 | TRUE | 2 |
| 3 | FALSE | 2 |
| 4 | TRUE | 6 |
| 5 | FALSE | 6 |
| 6 | TRUE | 12 |
Output: 12 (2 + 4 + 6). Original practice
Item 3 · WHILE with a counter
n = 5
total = 0
WHILE n > 0
total = total + n
n = n - 2
ENDWHILE
Display total, nWhat is displayed?
Show the answer
| n | n > 0 ? | total |
|---|---|---|
| 5 (start) | 0 | |
| TRUE | 5 | |
| 3 | TRUE | 8 |
| 1 | TRUE | 9 |
| −1 | FALSE | 9 |
Output: 9 and −1. The loop ends after n becomes −1. Original practice
Item 4 · REPEAT UNTIL
count = 10
REPEAT
count = count - 3
UNTIL count < 0
Display countWhat is displayed, and how many times does the body run?
Show the answer
count: 10 → 7 → 4 → 1 → −2; the test is after the body, so it stops when count is −2. Output −2; the body runs 4 times. Original practice
Terms, flashcards and past questions
Key terms for this page: Desk checking · Boundary values · Test plan · WHILE loop (pre-test) · REPEAT UNTIL loop (post-test) · FOR / NEXT loop (counted)
Flashcards · All key terms · Learn step by step · All past questions · Multiple-choice bank · Mock exam
Past questions used on this page:
← How to answer SQL questionsHow to answer drawing questions →