IB Computer Science: Common Pitfall Questions Explained | IB 计算机科学:易错题精讲

📚 IB Computer Science: Common Pitfall Questions Explained | IB 计算机科学:易错题精讲

In IB Computer Science, students often lose marks not because of a lack of understanding, but due to subtle misconceptions and careless mistakes in exam questions. This article compiles the most frequent error-prone topics—from binary arithmetic to object-oriented design—and explains the correct reasoning behind each typical pitfall. By reviewing these examples, you will strengthen your conceptual clarity and avoid common traps.

在 IB 计算机科学中,学生失分往往不是因为不理解,而是由于细微的误解和考试中的粗心错误。本文汇总了最常出错的题型——从二进制运算到面向对象设计——并解释每个典型陷阱背后的正确推理。通过复习这些例子,你将增强概念清晰度,避免常见陷阱。


1. Binary Addition and Overflow | 二进制加法与溢出

When adding two binary numbers, many students forget to handle the carry correctly when the sum exceeds 1. Another frequent mistake is ignoring overflow when the result exceeds the given bit width, or misinterpreting the result as always negative in two’s complement representation.

在进行二进制加法时,许多学生忘记在相加结果超过 1 时正确处理进位。另一个常见错误是在结果超过给定位宽时忽略溢出,或者在二进制补码表示中误以为结果总是负数。

Example Question: Perform the binary addition of 1011 and 0111 using 4-bit two’s complement representation. Identify if overflow occurs.

典型问题: 使用 4 位二进制补码表示法,计算 1011₂ 与 0111₂ 的和,并判断是否溢出。

A common wrong approach is to simply add bit by bit without considering carry propagation: 1+1=0 carry 1, then 1+1+1=1 carry 1, etc. Some students incorrectly state overflow when the carry into the sign bit differs from the carry out, but they might miscalculate the sign. The correct sum: 1011 (-5 in decimal) + 0111 (7) = 1 0010 after carry, but discarding the extra bit yields 0010 (2), and the carries into and out of the sign bit are both 1, so no overflow. However, a frequent mistake is to forget that 1011 is negative and treat it as 11, giving 11+7=18, then claim overflow because 18 cannot fit in 4 bits. The proper method uses two’s complement arithmetic.

一种常见错误是不考虑进位传播,简单地逐位相加:1+1=0 进位 1,然后 1+1+1=1 进位 1,等等。有些学生错误地认为溢出条件不满足,或者错误计算符号位。正确求和:1011₂(十进制 -5)+ 0111₂(7)= 进位的 1 0010,丢弃额外位得到 0010₂(2),并且符号位的进位输入和进位输出均为 1,因此无溢出。然而一个常见错误是忘记 1011 是负数,而将其视为 11,得出 11+7=18,然后声称溢出因为 18 无法用 4 位表示。正确的方法使用二进制补码运算。

  • For two’s complement, overflow occurs only when the carry into the sign bit is different from the carry out of the sign bit.
  • Always interpret operands according to the representation.
  • 对于二进制补码,只有当进入符号位的进位与出符号位的进位不同时,才发生溢出。
  • 务必根据表示法解释操作数。

2. Logic Gates and Truth Tables | 逻辑门与真值表常见错误

Students often misinterpret NAND as simply NOT AND and then apply De Morgan’s laws incorrectly. A typical mistake is to write the truth table for a NAND gate as the same as AND but negated output, but they sometimes flip the wrong column or forget that the output of NAND is 1 for all inputs except when all inputs are 1. Similarly for NOR.

学生常常将 NAND 简单地理解为“非与”,然后错误地应用德摩根定律。一个典型的错误是写出 NAND 门真值表时,与 AND 门混淆,仅对输出取反,但有时会弄错列,或者忘记 NAND 门的输出在所有输入不全为 1 时为 1。NOR 门类似。

Example: Consider a logic circuit where the output X = (A AND B) NAND C. A common error is to evaluate (A AND B) NAND C as equivalent to NOT((A AND B) AND C), which is correct, but then mistakenly build the truth table by applying NOT only to the final AND. This can lead to wrong 0/1 values. The correct evaluation must first compute Y = A AND B, then Z = Y NAND C, remembering that NAND is NOT (Y AND C).

例子: 考虑逻辑电路输出 X = (A AND B) NAND C。常见错误是将 (A AND B) NAND C 等同于 NOT((A AND B) AND C),虽然正确,但在构建真值表时错误地只对最终的 AND 取非,导致 0/1 数值错误。正确的计算必须先计算 Y = A AND B,然后 Z = Y NAND C,记住 NAND 是 NOT (Y AND C)。

For instance, when A=1, B=1, C=0: Y=1, then Y NAND C = NOT(1 AND 0) = NOT(0) = 1. A common wrong computation might take A AND B = 1, then directly NAND with C as 1 NAND 0, which still gives 1, but the problem arises when C=1: correct X = NOT(1 AND 1) = 0. Some erroneously produce 1 by misreading the gate. Always break down composite gates step by step.

例如,当 A=1, B=1, C=0 时:Y=1,然后 Y NAND C = NOT(1 AND 0) = NOT(0) = 1。常见错误计算可能是直接将 A AND B 的结果 1 与 C 进行 NAND,1 NAND 0 仍得 1,但当 C=1 时间题就出现了:正确 X = NOT(1 AND 1) = 0。有些人因误读门电路而得出 1。务必逐步分解复合门。


3. Pseudocode Tracing Errors | 伪代码跟踪执行错误

In IB pseudocode, loops like loop while and loop until can be confusing. Students often misread the exit condition and execute one extra or one fewer iteration. Another common mistake is not correctly updating loop counters inside the loop, leading to infinite loops in trace tables.

在 IB 伪代码中,loop while 和 loop until 循环容易混淆。学生常常误读退出条件,导致多执行或少执行一次迭代。另一个常见错误是没有在循环内部正确更新循环计数器,导致跟踪表中的无限循环。

Example: Trace the following pseudocode and write the output.

N = 5
loop while N > 0
   output N
   N = N - 2
end loop

A typical incorrect trace assumes the loop runs while N is positive, so the outputs are thought to be 5, 3, 1, -1. However, the condition is checked at the start of each iteration. After outputting 1, N becomes -1. When the loop condition N > 0 is checked again, it is false, so the loop terminates without outputting -1. The correct output is 5, 3, 1.

常见错误跟踪认为只要 N 为正就运行,因此输出被认为是 5, 3, 1, -1。然而,每次迭代开始时检查条件。输出 1 后,N 变为 -1。再次检查 N > 0 时条件为假,循环终止,不会输出 -1。正确的输出是 5, 3, 1。

Always maintain a trace table with columns for each variable and the condition evaluation. Update step by step to avoid off-by-one errors.

始终维护一个跟踪表,列出各变量列和条件计算列。逐步更新以避免差一错误。


4. Recursion Misunderstandings | 递归理解误区

A classic pitfall is writing a recursive function without a proper base case, or placing the base case after the recursive call, causing a stack overflow even in trace questions. Moreover, students often miscalculate the return values when functions unwind.

经典陷阱是编写递归函数时没有设置正确的基本情形,或将基本情形放在递归调用之后,即使在跟踪题中也会导致栈溢出。此外,学生经常在函数展开时错误计算返回值。

Example: Consider the recursive factorial function:

function factorial(N)
   if N = 0 then
      return 1
   else
      return N * factorial(N-1)
   end if
end function

Calculate factorial(3). Some students incorrectly unwind the recursion as 3 * 2 * 1 * 0 = 0, because they erroneously include the base case multiplication. The correct unwinding: factorial(3) = 3 * factorial(2). factorial(2) = 2 * factorial(1). factorial(1) = 1 * factorial(0). factorial(0) returns 1. Then factorial(1) = 1 * 1 = 1, factorial(2) = 2 * 1 = 2, factorial(3) = 3 * 2 = 6. The base case value 1 does not multiply the whole chain; it stops the recursion.

部分学生错误地将递归展开为 3 * 2 * 1 * 0 = 0,因为他们错误地将基本情形的 0 乘入链中。正确的展开:factorial(3) = 3 * factorial(2)。factorial(2) = 2 * factorial(1)。factorial(1) = 1 * factorial(0)。factorial(0) 返回 1。然后 factorial(1) = 1 * 1 = 1,factorial(2) = 2 * 1 = 2,factorial(3) = 3 * 2 = 6。基本情形的值 1 不会参与整个链条的乘法;它只是终止递归。


5. Sorting Algorithms Comparisons | 排序算法比较易混淆点

Students frequently mix up the mechanisms of bubble sort, selection sort, and insertion sort. For example, bubble sort repeatedly swaps adjacent elements; selection sort finds the minimum and swaps into place; insertion sort inserts elements into a sorted sublist. Mistakes arise when analyzing the number of comparisons or swaps, or when determining if an algorithm is stable.

学生们经常混淆冒泡排序、选择排序和插入排序的机制。例如,冒泡排序重复交换相邻元素;选择排序找出最小元素并将其交换到正确位置;插入排序将元素插入已排序的子列表。在分析比较次数或交换次数,或判断算法是否稳定时,常出现错误。

Example: The following steps were taken to sort the list [8, 3, 5, 2]. Identify the algorithm.
Pass 1: [3, 5, 2, 8] (8 moved to end)
Pass 2: [3, 2, 5, 8] (5 moved to its position)
Pass 3: [2, 3, 5, 8] (3 and 2 sorted)
A common error is to call this selection sort because smaller elements move left. However, in selection sort, the smallest element is found and swapped to the front in one pass; the list would become [2, 3, 5, 8] after pass 1. The described passes show adjacent swaps pushing the largest remaining element to the right, which is characteristic of bubble sort.

例子:以下步骤用于排序列表 [8, 3, 5, 2]。识别算法。
第一趟:[3,

Published by TutorHao | IB Computer Science Revision Series | aleveler.com

更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading