📚 IB & CIE Computer Science: Common Mistakes in Exam Questions | IB & CIE 计算机科学:易错题精讲
Understanding common pitfalls in IB and CIE Computer Science exams can significantly improve your performance. Many students lose marks not because they lack knowledge, but because they misinterpret questions, overlook key details, or apply concepts incorrectly. This article analyzes frequent errors and provides clear solutions to help you avoid them.
理解 IB 和 CIE 计算机科学考试中的常见陷阱可以显著提高你的成绩。许多学生丢分并非因为知识不足,而是由于误解题意、忽略关键细节或错误应用概念。本文分析常见错误并提供明确的解决方案,帮助你避开这些雷区。
1. Overflow in Two's Complement Arithmetic | 二进制补码运算中的溢出
w. For example, 64 + 64 = 128, which exceeds the maximum representable value of 127 in two' -128. Students often accept this as a correct negative number, ignoring the overflow flag.
一个典型错误是将两个 8 位正整数相加得到负数却不识别溢出。例如 64 + 64 = 128,这超过了二进制补码能表示的最大值 127。运算 0100 0000₂ + 0100 0000₂ 得到 1000 0000₂,会被解释为 -128。学生常常将其当作正确的负数接受,从而忽略了溢出标志。
The hardware overflow rule states that overflow occurs if the carry into the sign bit is different from the carry out of the sign bit. In 64 + 64, there is a carry into the sign bit (from bit 6) but no carry out of the sign bit, so overflow is present. Always check this condition when the operands have the same sign and the result sign differs.
硬件溢出规则指出,如果进入符号位的进位与离开符号位的进位不同,就会发生溢出。在 64 + 64 中,有一个进位进入符号位(来自第 6 位),但没有从符号位产生的进位,因此溢出存在。当操作数符号相同而结果符号不同时,务必检查这一条件。
2. Misapplying De Morgan's Laws in Boolean Simplification | 布尔化简中德摩根定律的误用
Students frequently invert expressions incorrectly, forgetting to change the operator. For instance, the complement of A ∧ B is often mistakenly written as ¬A ∧ ¬B instead of ¬A ∨ ¬B. Similarly, ¬(A ∨ B) should become ¬A ∧ ¬B, not ¬A ∨ ¬B. These errors lead to faulty circuit minimisation and lost marks.
学生经常错误地求反表达式,忘记改变运算符。例如,A ∧ B 的补集常被错写成 ¬A ∧ ¬B,而不是 ¬A ∨ ¬B。同样,¬(A ∨ B) 应变为 ¬A ∧ ¬B,而非 ¬A ∨ ¬B。这些错误会导致错误的电路化简并造成失分。
A safe step-by-step approach: take the complement of the whole expression, change all ∧ to ∨ (and vice versa), and complement each variable. For ¬(X ∧ (Y ∨ ¬Z)), apply De Morgan successively to obtain ¬X ∨ (¬Y ∧ Z). Practise with truth tables to verify equivalence.
一个安全的分步方法是:对整个表达式取反,将所有 ∧ 变为 ∨(反之亦然),并对每个变量取反。对于 ¬(X ∧ (Y ∨ ¬Z)),逐步应用德摩根定律可得到 ¬X ∨ (¬Y ∧ Z)。通过真值表验证等价性进行练习。
Remember that ¬(¬A) simplifies to A, and that these laws also apply in multiple-level combinational circuits. In exam questions, always show intermediate steps to avoid sign errors.
请记住 ¬(¬A) 可化简为 A,而且这些定律同样适用于多层组合电路。在考试题中,一定要展示中间步骤以避免符号错误。
3. Recursion Base Case Blunders | 递归基类错误
ction that does not test for n = 0. Without the stopping condition, the function call stack overflows at runtime.
编写递归函数时,学生常遗漏或错误放置基准情形,导致无限递归。一个经典的例子是阶乘函数未对 n = 0 进行检测。缺少停止条件,运行时函数调用栈将溢出。
Another subtle error is defining a base case that is never reached because the recursive call does not move towards it. For example, a sum-of-digits function that divides by a constant that never reduces the argument to zero. Ensure each recursive call uses a smaller or simpler instance of the original problem.
另一个微妙的错误是定义了永远无法到达的基准情形,因为递归调用没有趋近它。例如,一个求各位数字之和的函数用一个常量做除法,但参数永远不会减小到零。必须确保每次递归调用都使用原问题的一个更小或更简单的实例。
In IB and CIE pseudocode exams, also be careful with return statements: every path must return a value. Trace your recursive function with small inputs manually to check logic and coverage.
在 IB 和 CIE 伪代码考试中,还要注意返回语句:每条路径都必须返回一个值。用手动跟踪的方法用较小的输入测试递归函数,以检查逻辑和覆盖。
4. OOP: Confusing Inheritance with Polymorphism | 面向对象编程:继承与多态的混淆
A common misunderstanding is to treat inheritance and polymorphism as the same concept. Inheritance allows a subclass to reuse code from a superclass, whereas polymorphism permits a subclass object to be treated as an instance of its superclass while executing its own overridden methods.
一个常见的误解是将继承和多态视为同一个概念。继承允许子类重用超类的代码,而多态则允许子类对象被当作其超类的实例,同时执行自身重写的方法。
For example, in a Shape superclass with a method draw(), subclasses Circle and Rectangle override draw(). If an array of Shape references holds both Circle and Rectangle objects, calling draw() on each invokes the correct overridden method—this is dynamic binding. Mistaking the relationship as simple code reuse leads to incorrect answers on relationship diagrams and code output predictions.
例如,在一个 Shape 超类中有方法 draw(),子类 Circle 和 Rectangle 重写了 draw()。若一个 Shape 引用类型的数组同时包含 Circle 和 Rectangle 对象,对每个调用 draw() 会执行正确的重写方法——这是动态绑定。错把这种关系当作简单的代码复用会导致在关系图和代码输出预测题上给出错误答案。
When asked to 'describe how polymorphism is achieved', always mention method overriding, upcasting, and dynamic method dispatch—not just extending a class.
当被要求“描述如何实现多态”时,一定要提到方法重写、向上转型和动态方法分派,而不只是扩展一个类。
5. Normalization: Partial Dependency Pitfalls | 数据库规范化:部分依赖陷阱
When normalizing a database to 2NF, many students overlook partial dependencies—non-key attributes that depend on only a part of a composite primary key. This often occurs when a table with composite key (StudentID, CourseID) contains an attribute like StudentName, which depends solely on StudentID.
在将数据库规范化为第二范式时,许多学生忽略了部分依赖——即非键属性只依赖于复合主键的一部分。当一个带有复合主键 (StudentID, CourseID) 的表包含类似 StudentName 这样只依赖于 StudentID 的属性时,就会出现这种情况。
The fix is to decompose the table: place StudentName together with StudentID in a separate Students table, leaving only attributes fully functionally dependent on the entire composite key in the original table. Confusing partial dependency with transitive dependency is another frequent error; transitive dependency refers to a non-key attribute depending on another non-key attribute.
解决方法是对表进行分解:将 StudentName 与 StudentID 一同放入一个单独的 Students 表,让原表只保留完全函数依赖于整个复合键的属性。将部分依赖与传递依赖混为一谈是另一个常见错误;传递依赖是指一个非键属性依赖于另一个非键属性。
In exam questions, underline the primary key and draw dependency diagrams to clearly identify malformed relations before proposing a decomposition.
在考试题中,应在提出分解方案前,给主键加上下划线,并绘制依赖图,以清晰地识别不满足范式的关系。
6. Misinterpreting Big O for Nested Structures | 嵌套结构的大O记号误判
A frequent error is to guess time complexity without carefully counting loop iterations. For nested loops like for i = 1 to n and for j = 1 to i, many assume O(n²), but the total operations sum to n(n+1)/2, which is still O(n²) in Big O notation. The mistake arises when the inner loop varies with the outer loop and students think the average is n/2, leading them to incorrectly state O(n³) or something else.
一个常见错误是在没有仔细计算循环迭代次数的情况下猜测时间复杂度。对于像 for i = 1 to n 和 for j = 1 to i 这样的嵌套循环,许多人认为是 O(n²),而总操作次数为 n(n+1)/2,在大O记法中确实是 O(n²)。当内层循环随外层循环变化时,学生误以为平均值是 n/2,进而错误地判断为 O(n³) 或其他。
More perilous is mistaking O(log n) for O(√n). A binary search halves the search space each step, giving logarithmic complexity; a loop that increments by √n after each iteration has √n steps. Remember that O(log n) grows much slower than O(√n) for large n.
更危险的是将 O(log n) 误认为 O(√n)。二分查找每一步将搜索空间减半,带来对数复杂度;而每次迭代后增加 √n 的循环则有 √n 步。请记住,对于较大的 n,O(log n) 的增长比 O(√n) 慢得多。
When analysing pseudocode in IB/CIE papers, sum the basic operations and discard constant factors and lower-order terms. Write the dominant term and apply standard limits: O(n) > O(log n) but O(n log n) > O(n).
在分析 IB/CIE 试卷中的伪代码时,累加基本操作,丢掉常数因子和低阶项。写出主导项并应用标准大小关系:O(n) > O(log n),但 O(n log n) > O(n)。
7. Stack and Queue Order Slip-ups | 栈与队列顺序的失误
Students often confuse LIFO (Last In First Out) and FIFO (First In First Out) behaviours. For a stack, push operations add elements, and pop retrieves the most recently added item. For a queue, enqueue adds to the rear, and dequeue removes from the front. Mixing these up results in incorrect output sequences.
学生经常混淆 LIFO(后进先出)和 FIFO(先进先出)的行为。对于栈,push 操作添加元素,pop 取出最近添加的项;对于队列,enqueue 向队尾添加,dequeue 从队头移除。把这些弄混会导致输出序列错误。
, then push 7, pop → output 7. With a queue: enqueue 5, enqueue 3, dequeue → 5, enqueue 7, dequeue → 3. Clearly trace each step using a diagram.
典型的考题:给定一系列 push 和 enqueue 操作,判断最终内容或输出。例如,push 5, push 3, pop → 输出 3,再 push 7, pop → 输出 7。对于队列:enqueue 5, enqueue 3, dequeue → 5,enqueue 7, dequeue → 3。务必用图示逐步跟踪。
Beware of peek/top operations that return the next element without removing it; attribute this to the correct data structure state. Exam boards often ask for the state of the stack after partial pops.
注意 peek/top 操作,它们返回下一个元素而不移除它;要将这一点归因于正确的数据结构状态。考试局经常要求给出部分弹栈后的栈状态。
8. Binary Tree Traversal Ordering Errors | 二叉树遍历顺序错误
Three standard depth-first traversals—preorder, inorder, postorder—are often misapplied. Students confuse postorder (left, right, root) with preorder (root, left, right). When given a tree, they might output the wrong sequence, especially when the tree is unbalanced.
三种标准的深度优先遍历——前序、中序、后序——经常被用错。学生将后序遍历(左、右、根)与前序遍历(根、左、右)搞混。给定一棵树时,他们可能会输出错误的序列,特别是当树不平衡时。
A reliable method: label nodes and recursively visit them according to the traversal type. For postorder: traverse the left subtree completely, then the right subtree, finally visit the root. Many mistakes happen when a node has only one child; the traversal still follows the same recursive rule, treating the missing child as empty.
可靠的方法是:给节点做标记,并按遍历类型递归访问。对于后序遍历:完全遍历左子树,然后是右子树,最后访问根。很多错误发生在一个节点只有一个孩子时;遍历依然遵循相同的递归规则,将缺失的孩子视为空。
Given a sequence of values, reconstructing the tree from inorder and preorder (or inorder and postorder) is a common challenge. If inorder is not strictly used as reference, the constructed tree will be incorrect. Always identify the root from preorder/postorder first, then split inorder left and right subtrees.
给出一组值,从 中序和前序(或中序和后序)重建树是一个常见难题。如果没有严格使用中序作为参考,构建出的树就会出错。总是先从 前序/后序 确定根,然后在中序中分割左子树和右子树。
9. Subnet Mask Miscalculation | 子网掩码计算错误
In networking questions, a common slip is forgetting that the number of usable host addresses is 2ⁿ - 2, not 2ⁿ. The subtraction is for the network address and the broadcast address. For example, with a subnet mask of 255.255.255.240 (prefix /28), the remaining host bits are 4, giving 16 possible combinations, but only 14 assignable IP addresses.
在网络问题中,一个常见疏忽是忘记可用主机地址的数量是 2ⁿ - 2,而不是 2ⁿ。减去的是网络地址和广播地址。例如,子网掩码为 255.255.255.240(前缀 /28)时,剩余主机位为 4,产生 16 种可能组合,但只有 14 个可分配的 IP 地址。
Another error is incorrectly converting between dotted decimal notation and binary. A mask like 255.255.254.0 means 23 network bits: the third octet 254 is 11111110₂, leaving 9 bits for hosts (one zero in the third octet and all eight in the fourth). Misreading it as 255.255.255.0 leads to wrong subnets.
另一个错误是在点分十进制和二进制之间转换错误。像 255.255.254.0 这样的掩码意味着 23 个网络位:第三个八位组 254 即 11111110₂,留给主机 9 位(第三个八位组中一个 0,再加上第四个八位组的全部八位)。误读为 255.255.255.0 会导致错误的子网划分。
ys calculate the required number of host bits from the number of hosts per subnet: solve 2ʰ he new prefix length. Double-check both the network address and broadcast address of each subnet.
在设计子网时,始终根据每个子网所需的主机数计算所需的主机位数:求解 2ʰ - 2 ≥ 所需主机数。然后确定新的前缀长度。对每个子网的网络地址和广播地址再进行双重检查。
10. Pseudocode Loop Variable Scope and Off-by-One Errors | 伪代码循环变量作用域与差一错误
A subtle but costly error is using a loop control variable outside its intended scope or incorrectly assuming its final value. In IB/CIE pseudocode, a FOR loop counter is typically undefined after the loop terminates, yet students often print it as the last value that satisfied the condition, leading to logical errors.
一个微妙但代价高昂的错误是把循环控制变量用在其预期作用域之外,或错误地假定其终值。在 IB/CIE 的伪代码中,FOR 循环计数器在循环终止后通常是未定义的,但学生常把它当作满足条件的最后一个值打印出来,导致逻辑错误。
Off-by-one errors abound when setting loop bounds. Using for i = 0 to n-1 iterates n times; using for i = 1 to n also does n iterations. Confusing the two when accessing array indices (typically 0-based) causes out-of-bounds exceptions. Always verify the initial and final values on paper.
差一错误在设定循环边界时频繁出现。使用 for i = 0 to n-1 迭代 n 次;使用 for i = 1 to n 也是 n 次。当访问数组索引(通常从 0 开始)时混淆两者会引起越界异常。务必在纸上核对初值和终值。
When writing nested loops, keep track of inner and outer counters independently. A common mistake is to update the outer loop variable inside the inner loop or reuse the same variable name. Trace table questions explicitly test this; fill in values row by row without skipping.
写嵌套循环时,要独立跟踪内外计数器。一个常见错误是在内循环内部更新外循环变量或重用相同的变量名。跟踪表题目明确考查这一点;要逐行填入值,不要跳步。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

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