📚 Trace Tables to Document Dry Runs of Algorithms | 用追踪表记录算法的试运行
A dry run is the process of manually working through an algorithm step by step, acting as the computer, without executing the code on a machine. In Cambridge IGCSE Computer Science, a dry run is normally documented using a trace table, which records the value of every variable and every condition at each stage of the algorithm.
试运行(dry run)是指在纸上扮演计算机的角色,不借助机器执行代码,一步一步手动走查算法的过程。在剑桥 IGCSE 计算机科学中,试运行通常使用追踪表(trace table)来记录。追踪表会记录算法每个阶段中每个变量和每个条件的状态。
1. What is a Dry Run? | 什么是试运行?
A dry run is a mental or on-paper execution of an algorithm. You, the programmer, read each line in order, change variable values as instructed, evaluate conditions, and note any output that would be produced. It is one of the most reliable ways to find logic errors before any code is written or compiled.
试运行是一种在大脑中或纸上执行算法的过程。你作为程序员,按顺序逐行阅读算法,根据指令改变变量的值,计算条件的结果,并记录可能产生的任何输出。它是在编写或编译任何代码之前发现逻辑错误最可靠的方法之一。
Dry runs are particularly useful for:
试运行特别适用于:
-
Checking loops and conditions before coding them in a program.
在将循环和条件编写成程序之前先进行检查。
-
Finding off-by-one errors in FOR loops and WHILE loops.
发现 FOR 循环和 WHILE 循环中的差一错误(off-by-one error)。
-
Verifying that an algorithm produces the expected answer for given test data.
验证算法对给定测试数据是否能产生预期的答案。
-
Building confidence that a solution is correct before submitting it in an exam.
在考试提交答案之前,建立对解决方案正确性的信心。
2. What is a Trace Table? | 什么是追踪表?
A trace table is a table used to record the state of an algorithm during a dry run. It typically contains one column for each variable, plus a column for the line number being executed, a column for any condition being tested, and a column for output.
Published by TutorHao | IGCSE Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply