📚 How to Record Trace Tables in Algorithm Dry Runs | 算法干运行中的追踪表记录方法
In Computer Science examinations, especially those from CIE, you are often asked to perform a dry run of an algorithm and record the results in a trace table. A dry run means manually executing each instruction of the algorithm step by step, without using a computer, in order to understand exactly what the algorithm does. The trace table is the structured way to record this process.
在计算机科学考试中,尤其是 CIE 的考试,你经常被要求对算法进行干运行,并用追踪表记录结果。干运行是指不使用计算机,逐条手动执行算法中的每一条指令,以准确理解算法的行为。追踪表则是记录这一过程的结构化工具。
1. What Is a Dry Run? | 什么是干运行?
A dry run is the process of tracing through an algorithm by hand, simulating the execution of each line in order. You keep track of the current values of all variables and the output as the algorithm progresses. You do this on paper, using a trace table, to predict the result or to debug the algorithm.
干运行是手工逐步模拟算法执行的过程,按照顺序模拟每一行指令的执行。你需要记录算法执行过程中所有变量的当前值以及产生的输出。这一过程在纸上借助追踪表完成,目的是预测结果或调试算法。
Trace tables are particularly common in CIE papers because they test whether you truly understand the logic of control structures such as loops, conditions, and sequences.
追踪表在 CIE 试卷中非常常见,因为它能检测你是否真正理解循环、条件判断和顺序等控制结构的逻辑。
2. The Purpose of Trace Tables | 追踪表的目的
A trace table helps you record the exact state of every variable after each instruction is executed. It provides a clear, line-by-line account of the algorithm’s behaviour, making it easy to detect errors such as incorrect initialisation, wrong loop boundaries, or misplaced assignments.
追踪表帮助你记录每一条指令执行后所有变量的精确状态。它提供了算法行为的逐行清晰记录,便于发现初始化错误、循环边界错误或赋值位置错误等问题。
In an exam, presenting a well-structured trace table can earn you full marks even if your final answer is incomplete, because the examiner can see your reasoning and the point at which you went wrong.
在考试中,呈现一份结构清晰的追踪表,即使最终答案不完整,也可能获得满分,因为考官能够看到你的推理过程以及出错的位置。
3. Setting Up a Trace Table | 建立追踪表
Begin by identifying all the variables used in the algorithm. These include counters, totals, temporary storage, and any flag variables. Create one column for each variable. Also add a column for OUTPUT if the algorithm produces any output. Some trace tables include a column for the line number or instruction being executed, which is useful for complex algorithms.
首先,识别算法中使用的所有变量,包括计数器、累加器、临时存储变量以及任何标志变量。为每个变量创建一列。如果算法会产生输出,还要添加一个 OUTPUT(输出)列。有些追踪表还会添加一个“行号”或“当前执行指令”列,这在处理复杂算法时非常有用。
The columns are typically arranged from left to right in the order the variables are first encountered or in the order they are written in the algorithm. Each new row in the table represents a change in one or more variable values after a particular instruction has been executed.
各列通常按照变量首次出现的顺序或算法中出现的顺序从左到右排列。表格中的每一行表示某条特定指令执行后,一个或多个变量值的更新。
| x | y | z | OUTPUT |
| 5 | 3 | 8 | 8 |
The table above shows an example where x is assigned 5, y is assigned 3, then z is computed as x + y, and finally z is output. Each column records the latest value of the corresponding variable after each step.
上面的表格展示了一个例子:x 被赋值为 5,y 被赋值为 3,然后 z 被计算为 x + y,最后输出 z。每一列记录对应变量在每一步之后的最新值。
4. Recording Variables During Execution | 在执行过程中记录变量
When you trace an algorithm, you must update the trace table after every assignment statement. If the algorithm has a line such as x ← x + 1, you do not create a new column for the “old” x; instead, you record the new value of x in the same column, on a new row.
在追踪算法时,你必须在每一条赋值语句之后更新追踪表。例如,对于 x ← x + 1 这条指令,不需要为“旧的”x 创建新列,而是在同一列中记录 x 的新值,并另起一行。
Each row in a trace table represents the state of all variables after the currently executed instruction. If a variable is not changed by that instruction, you often leave the cell blank or repeat the previous value. In CIE mark schemes, leaving blank cells is usually acceptable as long as the changed variables are correctly recorded.
追踪表中的每一行表示当前指令执行后所有变量的状态。如果某个变量没有被当前指令修改,通常可以留空或重复前一个值。在 CIE 的评分标准中,留空通常是可以接受的,只要被修改的变量被正确记录即可。
- Initialisation: record the initial value of a variable when it is first assigned.
- 更新:记录变量首次被赋值时的初始值。
- Reassignment: record the new value in the same column, not a new column.
- 重新赋值:在同一列中记录新值,而不是创建新列。
- Unchanged variables: leave blank or carry forward the same value.
- 未变的变量:留空或沿用原值。
5. Handling Conditions in Trace Tables | 在追踪表中处理条件判断
When the algorithm contains an IF statement such as IF score ≥ 50 THEN, you must evaluate the condition using the current variable values. Record any variables that are changed inside the chosen branch. You do not usually write “TRUE” or “FALSE” in the trace table unless the examiner asks for it, but you may find it helpful to note the decision in your working.
当算法包含 IF score ≥ 50 THEN 这类条件语句时,你必须使用当前变量值来评估条件。记录所选分支内被修改的任何变量。除非题目特别要求,否则通常不需要在追踪表中写出“TRUE”或“FALSE”,但在草稿中记录判断结果有助于你保持清晰。
For nested conditions, evaluate the innermost condition first when necessary, and follow the corresponding branch. Ensure that the values you record are consistent with the branch you have chosen.
对于嵌套条件,必要时先评估最内层的条件,然后执行对应的分支。确保你记录的值与你选择的分支一致。
6. Recording Loop Execution | 记录循环执行
Loops are the most frequent source of errors in trace tables. For a FOR loop, you must record the loop counter each time it is incremented. For a WHILE loop or REPEAT loop, you must record the condition result and update the relevant variables inside the loop body each iteration.
循环是追踪表中错误最多的部分。对于 FOR 循环,你必须每次递增时记录循环计数器。对于 WHILE 循环或 REPEAT 循环,每次迭代都必须记录条件结果,并更新循环体中的相关变量。
A common technique is to draw one row per iteration of the loop. This makes the table longer but much easier to follow. If the loop never terminates, you will notice that the table grows indefinitely, which is a sign that the algorithm has an error.
一个常用技巧是:循环每迭代一次就画一行。这会使表格变长,但更容易阅读。如果循环永远不会终止,你会注意到表格无限增长,这是算法存在错误的信号。
7. Worked Example 1: Simple Sequence | 示例 1:简单顺序结构
Consider the following pseudocode:
考虑以下伪代码:
total → 0
number → 7
total → total + number
OUTPUT total
Here, the arrow → means assignment. The variable total is initialised to 0, number to 7, then total becomes 0 + 7 = 7, and the output is 7.
这里的箭头 → 表示赋值。变量 total 初始化为 0,number 为 7,然后 total 变为 0 + 7 = 7,输出为 7。
| total | number | OUTPUT |
| 0 | 7 | |
| 7 | 7 | 7 |
Notice that in the first row, total and number are recorded after their initial assignments. In the second row, total is updated and OUTPUT is written.
注意:在第一行中,total 和 number 在初始赋值后记录。在第二行中,total 被更新,同时记录 OUTPUT。
8. Worked Example 2: A FOR Loop | 示例 2:FOR 循环
Now consider a loop that accumulates the sum of numbers from 1 to 3:
现在考虑一个计算从 1 到 3 累加和的循环:
sum → 0
FOR i → 1 TO 3
sum → sum + i
NEXT i
OUTPUT sum
We need columns for i, sum, and OUTPUT. When the loop starts, i is set to 1. The variable sum is 0 before the loop body executes.
我们需要为 i、sum 和 OUTPUT 建立列。循环开始时,i 被设为 1。sum 在循环体执行前为 0。
| i | sum | OUTPUT |
| 1 | 1 | |
| 2 | 3 | |
| 3 | 6 | 6 |
After the loop finishes, i has the value 4 in many languages (because it has been incremented past 3). However, in CIE pseudocode, you only need to record i for the values it takes inside the loop: 1, 2, 3. The final output is 6.
循环结束后,在许多编程语言中 i 的值是 4(因为它已经被递增到超过 3)。但在 CIE 伪代码中,你只需要记录 i 在循环内取到的值:1、2、3。最终输出是 6。
9. Worked Example 3: Conditional with Selection | 示例 3:带选择结构的条件判断
Consider the following algorithm that checks whether a number is even or odd:
考虑以下判断一个数是偶数还是奇数的算法:
num → 9
IF num MOD 2 = 0 THEN
result → “even”
ELSE
result → “odd”
ENDIF
OUTPUT result
The MOD operation gives the remainder of a division. Since 9 MOD 2 = 1, the condition is FALSE, so the ELSE branch is executed.
MOD 运算给出除法余数。因为 9 MOD 2 = 1,条件为 FALSE,因此执行 ELSE 分支。
| num | result | OUTPUT |
| 9 | “odd” | “odd” |
When writing strings in a trace table, use quotation marks exactly as they appear in the algorithm. If the algorithm outputs without quotation marks, you may write the string without them.
在追踪表中书写字符串时,请严格使用算法中的引号。如果算法输出时不带引号,你可以在表中不写引号。
10. Common Mistakes in Trace Tables | 追踪表常见的错误
Many students lose marks unnecessarily when completing trace tables. The most common mistakes include recording values in the wrong order, forgetting to update a variable that is not used until later, and confusing the loop counter with the accumulated total.
许多学生在完成追踪表时白白丢分。最常见的错误包括:记录值的顺序出错、忘记更新某个稍后才使用的变量,以及混淆循环计数器与累加器。
- Not recording initial values: always record the first assigned value of every variable.
- 未记录初始值:始终记录每个变量的第一个赋值。
- Writing values in the wrong column: keep a neat structure and check the variable name above each column.
- 把值写错列:保持整洁的结构,并检查每列上方的变量名。
- Forgetting the OUTPUT column: if an algorithm prints or displays a value, you must record it.
- 忘记 OUTPUT 列:如果算法打印或显示某个值,你必须记录它。
- Ignoring condition results: always evaluate IF and loop conditions using the latest recorded values.
- 忽略条件结果:始终使用最新记录的值来评估 IF 和循环条件。
11. Exam Tips for CIE Computer Science | CIE 计算机科学考试技巧
In CIE theory papers, trace tables may appear in both Paper 1 and Paper 2. You should always use a ruler for table lines if you are drawing the table by hand, and write values clearly so that the examiner can read them.
在 CIE 理论试卷中,追踪表可能出现在 Paper 1 和 Paper 2 中。如果你用手画表,请务必使用尺子,并清晰书写数值,以便考官阅读。
If the question gives you a pre-drawn trace table, you must fill only the cells that correspond to the exact points indicated. If no table is provided, create your own with columns for every variable and OUTPUT. Practising with past papers is the most effective way to improve your speed and accuracy.
如果题目提供了预先画好的追踪表,你只需填写指定位置对应的单元格。如果没有提供表格,请自行创建包含每个变量和 OUTPUT 的列。练习往年真题是提高速度和准确率的最有效方法。
Remember that trace tables are not only for exams — they are also a powerful debugging tool used by professional programmers to understand and fix algorithms.
请记住,追踪表不仅用于考试,它也是专业程序员用来理解和修复算法的强大调试工具。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导