Step 1: Initialization: Identify all variables used in the algorithm and create a column for each, including a column for the line number and any output statements.
Step 2: Initial State: Record the starting values of all variables before the first line of code or the first iteration of a loop begins.
Step 3: Line-by-Line Execution: Follow the code exactly as a computer would. When a variable is updated, write the new value in the corresponding column on a new row.
Step 4: Handling Conditions: For 'if' statements or 'while' loops, evaluate the condition (True/False) and record the result in the condition column to track the branching path.
Step 5: Termination: Continue the process until the algorithm reaches an 'End' state or the loop condition becomes false, ensuring the final output matches expectations.
| Feature | Trace Table (Dry Run) | Automated Debugger |
|---|---|---|
| Execution | Manual (Human-led) | Automatic (Computer-led) |
| Speed | Slow, but builds deep understanding | Fast, efficient for large codebases |
| Focus | Logical flow and conceptual errors | Runtime errors and memory states |
| Environment | Paper/Pen or Spreadsheet | Integrated Development Environment (IDE) |
Trace Table vs. Flowchart: A flowchart visualizes the structure and possible paths of an algorithm, whereas a trace table tracks the actual data values during a specific execution instance.
Trace Table vs. Unit Test: A unit test checks if an input produces the correct output; a trace table explains why that output was produced by showing the internal steps.
Check Loop Boundaries: Always pay close attention to the first and last iterations of a loop (e.g., vs or vs ), as these are where 'off-by-one' errors are most common.
Don't Skip Steps: Even if a line seems trivial, record it. Skipping steps often leads to missing the exact moment a variable takes on an unexpected value.
Use Clear Notation: Use a dash (—) or leave a cell blank if a variable's value does not change in a particular step to keep the table readable.
Verify the 'Final' State: Ensure that the last row of your table reflects the final values of all variables and the final output, as exams often ask for these specific values.
Mental Shortcuts: Students often update variables in their heads rather than writing them down, which defeats the purpose of the table and leads to errors in complex logic.
Misinterpreting Boolean Logic: Incorrectly evaluating conditions (e.g., thinking is True) will lead the trace down the wrong execution path.
Ignoring Output: Forgetting to record what is printed or returned can result in losing marks, even if the variable tracking is correct.
Overwriting Values: Writing multiple values in the same cell instead of using a new row makes it impossible to track the sequence of changes.