TK Study

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

  1. 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
  2. Write the test data above the table (which values the Get statements read, or the starting values). From course notes
  3. Start at the first line. Never skip a line; use a pencil finger or the line numbers. General advice
  4. 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.
  5. 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
  6. 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
  7. Write the output when Display runs, in the output column. General advice
  8. 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
Stepxyx > 0 ?Output
Start30
Pass 16TRUE (x = 3)
2
Pass 210TRUE (x = 2)
1
Pass 312TRUE (x = 1)
0
TestFALSE (x = 0): leave the loop
Display12

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)

In a retail business, all product codes must start with an uppercase letter and then be followed by one or more lowercase letters. The algorithm below is designed to validate a product code. It contains errors. Note that Extract(string, start, N) returns N characters from a string, starting from position start. Eg Extract(“Names”, 3, 2) returns “me”. Line numbers have been provided for reference. 10 | BEGIN validate 20 | OK = “F” 30 | Get ProductCode 40 | Len = Number of characters in ProductCode 50 | WHILE OK = “F” AND ProductCode < > “Q” 60 | OK = “T” 70 | IF Extract(ProductCode, 1, 1) is not an uppercase letter THEN 80 | OK = “F” 90 | Display “Not uppercase” 100 | ENDIF 110 | FOR Count = 1 to Len 120 | IF Extract(ProductCode, Count, 1) is not a lowercase letter THEN 130 | OK = “F” 140 | Display “Not all lowercase” 150 | ENDIF 160 | NEXT Count 170 | IF OK = “F” THEN 180 | Display “Invalid code” 190 | Get ProductCode 200 | ENDIF 210 | ENDWHILE 220 | END validate (a) | Perform a desk check of the algorithm using the test data “p3”, “Pad”, “Q”, “X”. | 3 OK | ProductCode | Len | Extracted | Count | Display character (b) | The algorithm contains errors. | 3 Identify TWO errors and suggest how they can be corrected. Refer to line numbers in your answer.

Official marking criteria

[Question 28 (a)] Criteria | Marks • Provides a substantially correct desk check | 3 • Provides a partially correct desk check | 2 • Demonstrates some understanding of the algorithm | 1 Criteria | Marks • Identifies TWO errors and suggests ways to correct them | 3 • Identifies ONE error and suggests a way to correct it OR | 2 • Identifies TWO errors • Identifies an error | 1

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

Old-syllabus question. Diagrams, tables and flowcharts in the paper and MG are images and were lost in text extraction, so some parts are incomplete. Use for practice on the overlapping skill only. The new Software Engineering exam does not use the old SDD terms (e.g. CASE tools, system flowcharts, EBNF, assembly).

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 Largest

Complete a trace table and state the output.

Show the answer
iScores[i]Scores[i] > Largest?Largest
5 (start)
28TRUE8
33FALSE8
49TRUE9
56FALSE9

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 Total

What is displayed?

Show the answer
nn MOD 2 = 0 ?Total
0 (start)
1FALSE0
2TRUE2
3FALSE2
4TRUE6
5FALSE6
6TRUE12

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, n

What is displayed?

Show the answer
nn > 0 ?total
5 (start)0
TRUE5
3TRUE8
1TRUE9
−1FALSE9

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 count

What 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

← How to answer SQL questionsHow to answer drawing questions →