📚 Trace Tables to Document Dry Runs of Algorithms | 追踪表:记录算法干运行
In both computer science and experimental science, algorithms are used to model, simulate, and analyse data. A dry run is a manual step-by-step execution of an algorithm, and a trace table is the structured tool used to document that process. Whether you are calculating reaction rates or simulating projectile motion, trace tables help you verify logic, catch errors, and understand how variables change over time. This article explains how to construct and interpret trace tables, with examples drawn from scientific calculations relevant to the Cambridge IGCSE Science curriculum.
无论是在计算机科学还是实验科学中,算法都被用来建模、模拟和分析数据。干运行是手动逐步执行算法的过程,而追踪表则是用来记录这一过程的结构化工具。无论是计算反应速率还是模拟抛体运动,追踪表都能帮助你验证逻辑、发现错误,并理解变量随时间的变化。本文将结合剑桥 IGCSE 科学课程中相关的科学计算示例,解释如何构建和解读追踪表。
1. What Is a Dry Run? | 什么是干运行?
A dry run is the process of manually working through an algorithm’s instructions, line by line, using pencil and paper. Instead of running the code on a computer, you simulate the execution in your mind or on paper, updating each variable’s value as you go. This technique is especially useful in science when developing formulas to process experimental data, because it lets you test whether the logic produces expected numerical results before any real coding is done.
干运行是使用纸笔手动逐行执行算法指令的过程。与在计算机上运行代码不同,你是在头脑中或纸上模拟执行过程,随时更新每个变量的值。在科学研究中,当需要开发处理实验数据的公式时,这一技术尤为有用,因为它可以在实际编写代码之前,检验逻辑是否能产生预期的数值结果。
2. Why Use Trace Tables in Science? | 为什么在科学中使用追踪表?
In science experiments, you often design algorithms to calculate quantities such as concentration, velocity, or energy. A trace table provides a transparent record of how each variable’s value evolves during the calculation. This is essential for debugging errors in your logic and for justifying your results to a teacher or examiner. Moreover, the Cambridge IGCSE Science syllabus encourages computational thinking, and trace tables are a clear way to demonstrate your understanding of algorithmic processes.
在科学实验中,你经常需要设计算法来计算浓度、速度或能量等物理量。追踪表可以清晰地记录每个变量的值在计算过程中的变化。这对于调试逻辑错误以及向老师或考官证明结果的合理性至关重要。此外,剑桥 IGCSE 科学课程鼓励计算思维,而追踪表正是展示你对算法过程理解程度的清晰方式。
3. The Basic Structure of a Trace Table | 追踪表的基本结构
A trace table typically consists of columns for each variable, condition, and output. The first column usually records the line number or step being executed. Additional columns are added for any expression that is evaluated, such as a loop condition or an if-statement test. Each row represents a complete snapshot of the algorithm’s state after executing that line. In a scientific algorithm, you might track variables like temperature, time, pH, or a counter for iterations.
追踪表通常由代表每个变量、条件和输出的列组成。第一列一般记录正在执行的行号或步骤。对于任何需要求值的表达式,例如循环条件或 if 语句测试,都会添加额外的列。每一行代表了在执行该行指令后算法状态的完整快照。在一个科学算法中,你可能需要追踪温度、时间、pH 值或用于记录迭代次数的计数器等变量。
| Line # | time (s) | distance (m) | time ≤ 3? | Output |
|---|---|---|---|---|
| 1 | 0 | 0 | True | |
| 2 | 0 | 0 | 0, 0 |
4. Example Algorithm: Free Fall Distance Calculator | 示例算法:自由落体距离计算器
ysics student predict the position of a falling object and can be verified using a trace table. The pseudocode is as follows:
考虑一个简单的科学算法,它计算物体在重力作用下(g = 9.8 m/s²)每 0.5 秒时间间隔内下落的距离,直到 3 秒为止。所使用的公式为 d = ½ × g × t²。该算法可帮助物理学生预测下落物体的位置,并且可以通过追踪表进行验证。伪代码如下:
t ← 0
d ← 0
while t ≤ 3
d ← 0.5 × 9.8 × t × t
output t, d
t ← t + 0.5
endwhile
ermines whether the loop continues, and the output column records the displayed pairs of values. This mimics how sensors might record position data in a lab experiment.
需要追踪的变量是 t(时间)和 d(距离)。条件 t ≤ 3 决定循环是否继续,输出列记录显示的数值对。这模拟了实验室实验中传感器记录位置数据的方式。
5. Step-by-Step Trace Table Construction | 逐步构建追踪表
art by initialising the table with columns for the line number, t, d, the condition (t ≤ 3? .5. This process repeats until t becomes 3.5, at which point the condition fails and the loop terminates.
我们首先初始化表格,包含行号、t、d、条件 (t ≤ 3?) 和输出列。逐行执行伪代码,随时更新数值。第 1 行后,t = 0;第 2 行后,d = 0。检查 while 条件:0 ≤ 3 为真,因此进入循环。第 4 行,d 变为 0.5 × 9.8 × 0 × 0 = 0。然后输出 (0, 0),并将 t 增加至 0 + 0.5 = 0.5。重复此过程,直到 t 变为 3.5,此时条件不成立,循环终止。
| Line # | t | d | t ≤ 3? | Output |
|---|---|---|---|---|
| 1 | 0 | – | ||
| 2 | 0 | 0 | ||
| 3 | 0 | 0 | True | |
| 4 | 0 | 0 | ||
| 5 | 0 | 0 | 0, 0 | |
| 6 | 0.5 | 0 | ||
| 3 | 0.5 | 0 | True | |
| 4 | 0.5 | 1.225 | ||
| 5 | 0.5 | 1.225 | 0.5, 1.225 | |
| 6 | 1.0 | 1.225 | ||
| 3 | 1.0 | 1.225 | True | |
| 4 | 1.0 | 4.9 | ||
| 5 | 1.0 | 4.9 | 1.0, 4.9 | |
| 6 | 1.5 | 4.9 | ||
| ... | ... | ... | ... | ... |
0 seconds. This matches the theoretical values and confirms the algorithm is correct for a science simulation.
完整的追踪表验证了该公式在 t = 0、0.5、1.0、1.5、2.0、2.5、3.0 秒时产生的 d 值分别为 0、1.225、4.9、11.025、19.6、30.625、44.1 米。这符合理论值,证实该算法适用于科学模拟。
6. Handling Conditional Statements in Scientific Contexts | 处理科学情境中的条件语句
ecords True or False in that column. When the condition is false, the algorithm may skip certain calculations, and the trace table makes it easy to see which path was taken. This mirrors how you might record observations when a chemical indicator changes colour.
许多科学算法包含条件逻辑。例如,一个程序可能会检查反应是否达到平衡。追踪表必须包含一个用于评估条件的列。如果测试变量 pH(pH == 7),追踪表会在该列记录 True 或 False。当条件为假时,算法可能会跳过某些计算,追踪表可以轻松显示采取了哪条路径。这类似于在化学指示剂颜色变化时记录观察结果的方式。
if temperature > 100
state ← 'gas'
else
state ← 'liquid'
endif
A trace table for this snippet would show the temperature, the condition temperature > 100, and the resulting state. For a temperature of 98, the condition is False, so state becomes 'liquid'. This systematic method helps scientists ensure their decision-making algorithms are implemented correctly.
该代码片段的追踪表将显示温度、条件 temperature > 100 以及最终的状态。当温度为 98 时,条件为 False,因此状态变为 'liquid'。这种系统化的方法有助于科学家确保决策算法得到正确实施。
7. Tracing Loops: Accumulating Scientific Data | 追踪循环:累积科学数据
e loop iterates, showing a timeline of variable changes. For a FOR loop that runs from i = 1 to 10, the trace table helps you verify that the final total is correct by summing incremental changes.
循环对于处理重复测量至关重要,例如每小时每分钟记录一次温度。在追踪表中,你必须小心更新循环计数器以及任何累积变量,例如总热能或成功试验次数。追踪表的行数会随着循环迭代而增加,显示出变量变化的时间线。对于一个从 i = 1 到 10 运行的 FOR 循环,追踪表可以帮助你通过逐步求和来验证最终的总和是否正确。
An example from a biology experiment: calculating the average growth of plants over 7 days. The algorithm might sum the daily heights and then divide by 7. The trace table clearly logs each daily height and the running total, so any mistake in data entry or formula becomes immediately obvious.
以一个生物学实验为例:计算一周内植物的平均生长量。算法可能会先累加每天的高度,然后除以 7。追踪表会清晰地记录每天的植株高度和累计值,因此任何数据录入或公式的错误都会立即显现出来。
8. Trace Tables for Error Detection in Science Simulations | 利用追踪表进行科学模拟的错误检测
When coding a simulation for radioactive decay or population growth, small logical errors can lead to completely wrong predictions. A trace table acts as a debugging tool by showing the state of the program after each instruction. If the expected number of undecayed nuclei after one half-life is not exactly half, the trace table will reveal where the calculation went wrong—perhaps the exponent was applied incorrectly or the loop terminated one iteration too early. For IGCSE Science students, this practice mirrors the careful recording of experimental data to detect anomalies.
在为放射性衰变或种群增长编写模拟程序时,微小的逻辑错误都可能导致完全错误的预测。追踪表作为一种调试工具,可以显示每条指令执行后程序的状态。如果一个半衰期后预期的未衰变核数目不是精确的一半,追踪表将揭示计算的具体错误之处——可能是指数应用不正确,或者循环过早地终止了一次迭代。对于 IGCSE 科学学生而言,这种做法与仔细记录实验数据以检测异常值的过程是一致的。
9. Common Pitfalls When Using Trace Tables | 使用追踪表时的常见陷阱
Students often forget to update a variable’s value after a calculation or omit the condition column altogether, making it hard to follow the logic. Another mistake is not resetting variables when re-running a dry run, leading to residual values from a previous attempt. In science contexts, confusing units (e.g., mixing metres with centimetres) can also corrupt the trace table. Always label your columns with the correct scientific units and double-check each line against the original algorithm.
学生通常会忘记在计算后更新变量的值,或者完全省略条件列,从而导致难以理解逻辑。另一个错误是在重新进行干运行时未重置变量,从而保留了前一次尝试的残留值。在科学情境中,混淆单位(例如将米与厘米混用)也可能使追踪表出错。务必使用正确的科学单位标记列,并逐行对照原始算法进行检查。
ment. A trace table with a separate column for the expression can help you verify intermediate results and avoid precedence errors.
此外,还要注意运算顺序。在自由落体算法中,乘法 0.5 × 9.8 × t × t 必须要在赋值之前完成。为表达式单独设置一列的追踪表可以帮助你验证中间结果,避免优先级错误。
10. Trace Tables in the Cambridge IGCSE Science Curriculum | 剑桥 IGCSE 科学课程中的追踪表
Cambridge IGCSE Sciences—whether Coordinated Science, Combined Science, or the separate Biology, Chemistry, and Physics courses—increasingly incorporate computational thinking tasks. You may be asked to interpret an algorithm that processes experimental data, such as calculating the efficiency of a machine or the concentration of a solution. The exam question might require you to complete a trace table for the first few iterations of a loop. Demonstrating your ability to systematically trace variable changes earns marks for logical reasoning and data handling.
剑桥 IGCSE 科学课程——无论是协调科学、综合科学,还是独立的生物学、化学和物理学课程——都越来越多地融入计算思维任务。你可能会被要求解释一个处理实验数据的算法,例如计算机器的效率或溶液的浓度。考试题目可能会要求你完成一个循环前几次迭代的追踪表。展示出系统追踪变量变化的能力,可以为你赢得逻辑推理和数据处理方面的分数。
Even if a dedicated computer science paper is not part of your science assessment, the skill of dry running an algorithm with a trace table strengthens your ability to think sequentially, which is vital when planning multi-step laboratory procedures or solving numerical problems in physics and chemistry.
即使你的科学考试中没有专门的计算机科学试卷,使用追踪表进行算法干运行的技能也能增强你的顺序思维能力,这在设计多步骤实验程序或解决物理、化学中的数值问题时至关重要。
11. Benefits of Documenting Dry Runs | 记录干运行的好处
Documenting a dry run with a trace table promotes clarity, reduces errors, and provides a permanent record that you can review later. In group science projects, a trace table can serve as a communication tool, allowing peers to understand your algorithm’s logic without running the code. It also prepares you for real-world scientific computing, where code verification is mandatory before publishing results. The discipline of filling in a trace table fosters meticulousness, a trait highly valued in both academic and professional science settings.
使用追踪表记录干运行可以提升清晰度、减少错误,并提供一份可供日后查阅的永久记录。在团队科学项目中,追踪表可以作为一种沟通工具,让同伴无需运行代码就能理解你的算法逻辑。它还为现实世界中的科学计算做好准备,因为在发表结果之前,代码验证是必不可少的。填写追踪表这一训练能培养一丝不苟的精神,这在学术和专业科学领域都备受推崇。
12. Conclusion: Mastering Trace Tables for Scientific Algorithms | 结论:掌握科学算法的追踪表
Trace tables are an indispensable tool for any IGCSE Science student who wants to understand and debug algorithms. By methodically recording the value of each variable, condition, and output as you step through a dry run, you gain deep insight into how an algorithm works and can quickly spot logical flaws. Whether you are simulating free fall, modelling reaction rates, or processing biological data, a well-constructed trace table is your key to accurate and reliable results. Practice with simple scientific formulas first, then apply the technique to more complex algorithms as your confidence grows.
对于任何想要理解和调试算法的 IGCSE 科学学生来说,追踪表都是不可或缺的工具。通过在干运行过程中有条不紊地记录每个变量、条件和输出的值,你可以深入了解算法的运作方式,并快速发现逻辑缺陷。无论你是在模拟自由落体、建模反应速率,还是处理生物学数据,一个构建良好的追踪表都是获得准确、可靠结果的关键。先使用简单的科学公式进行练习,随着信心的增强,再将这一技术应用于更复杂的算法。
Published by TutorHao | Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图