📚 IB & Edexcel Computer Science: In-Depth Analysis of Typical Exam Questions | IB与爱德思计算机典型例题详解
Mastering Computer Science for IB and Edexcel examinations requires not only understanding key concepts but also practising how to apply them under exam conditions. This article walks you through a curated collection of typical problems drawn from both syllabi, covering number systems, Boolean algebra, data structures, algorithms, OOP, databases, networking and more. Each example is followed by a step-by-step solution and commentary designed to reinforce your problem-solving skills.
要想在IB和爱德思计算机科学考试中取得好成绩,不仅要理解核心概念,还要练习如何在考试场景中应用它们。本文精选了来自两个大纲的典型例题,涵盖数制、布尔代数、数据结构、算法、面向对象编程、数据库、网络等内容。每一道题都配有逐步推导和讲评,旨在强化你的解题能力。
1. Number Systems & Binary Arithmetic | 数制与二进制运算
Example problem: Convert the binary number 101101₂ to decimal, then add it to the hexadecimal number 2F₁₆. Give the final answer in both decimal and binary.
典型例题: 将二进制数 101101₂ 转换为十进制,然后与十六进制数 2F₁₆ 相加。最后的结果请同时以十进制和二进制形式给出。
Step 1 – Binary to Decimal:
101101₂ = 1×2⁵ + 0×2⁴ + 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 32 + 0 + 8 + 4 + 0 + 1 = 45₁₀.
第1步 – 二进制转十进制:
101101₂ = 1×2⁵ + 0×2⁴ + 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 32 + 0 + 8 + 4 + 0 + 1 = 45₁₀。
Step 2 – Hexadecimal 2F₁₆ to Decimal:
2F₁₆ = 2×16¹ + 15×16⁰ = 32 + 15 = 47₁₀.
第2步 – 十六进制 2F₁₆ 转十进制:
2F₁₆ = 2×16¹ + 15×16⁰ = 32 + 15 = 47₁₀。
Step 3 – Addition:
45₁₀ + 47₁₀ = 92₁₀.
第3步 – 加法:
45₁₀ + 47₁₀ = 92₁₀。
Step 4 – Decimal 92 to Binary:
92 ÷ 2 = 46 remainder 0, 46 ÷ 2 = 23 remainder 0, 23 ÷ 2 = 11 remainder 1, 11 ÷ 2 = 5 remainder 1, 5 ÷ 2 = 2 remainder 1, 2 ÷ 2 = 1 remainder 0, 1 ÷ 2 = 0 remainder 1. Reading remainders upwards: 1011100₂.
第4步 – 十进制 92 转二进制:
92 ÷ 2 = 46 余 0,46 ÷ 2 = 23 余 0,23 ÷ 2 = 11 余 1,11 ÷ 2 = 5 余 1,5 ÷ 2 = 2 余 1,2 ÷ 2 = 1 余 0,1 ÷ 2 = 0 余 1。从下往上读余数:1011100₂。
Final answers: 92₁₀ and 1011100₂. This type of question frequently appears in IB Paper 1 and Edexcel Unit 1, testing conversion fluency and arithmetic across bases.
最终答案:92₁₀ 和 1011100₂。这类题目频繁出现于IB试卷一和爱德思单元一,考查不同进制间的转换熟练度和运算能力。
2. Boolean Algebra & Logic Gates | 布尔代数与逻辑门
Example problem: Simplify the Boolean expression F = A’B + AB + A’B’ using algebraic laws. Then draw the equivalent logic circuit using only NAND gates.
典型例题: 利用代数定律化简布尔表达式 F = A’B + AB + A’B’,然后画出仅使用与非门(NAND)的等效逻辑电路图。
Simplification: Combine A’B + AB = B(A’ + A) = B(1) = B. Now F = B + A’B’. Apply the redundancy or absorption law: B + A’B’ = B + A’B’ (no further trivial absorption). Recognise that B + A’B’ = (B + A’)(B + B’) = (B + A’)(1) = B + A’. So F = B + A’.
化简过程: 合并 A’B + AB = B(A’ + A) = B(1) = B。现在 F = B + A’B’。运用吸收律或冗余律:B + A’B’ = (B + A’)(B + B’) = (B + A’)(1) = B + A’。因此 F = B + A’。
Circuit realisation with NAND only: F = A’ + B. Using De Morgan: F = (A’ + B)” = ( (A’)’ · B’ )’ = (A · B’)’. So we need a NAND gate with inputs A and B’, where B’ can be obtained from a NAND configured as inverter (tie both inputs to B).
仅用与非门实现: F = A’ + B。利用德·摩根定律:F = (A’ + B)” = ( (A’)’ · B’ )’ = (A · B’)’。因此需要一个与非门,输入为 A 和 B’,而 B’ 可以由与非门接成反相器得到(将 B 同时接入该与非门的两个输入端)。
The final circuit: one NAND gate taking B tied together to produce B’; that output feeds into another NAND gate along with A, giving (A · B’)’ which equals A’ + B.
最终电路:一个与非门将 B 并接到两个输入端,产生 B’;其输出与 A 一同送入第二个与非门,输出 (A · B’)’ 即为 A’ + B。
These simplification and gate-conversion exercises are staple marks in both IB Topic 1.5 and Edexcel Boolean logic sections.
这类化简和门转换练习是IB主题1.5和爱德思布尔逻辑部分的必考题型。
3. Computer Architecture – Fetch-Decode-Execute | 计算机体系结构 – 取指译码执行
Example problem: Describe the role of the Program Counter (PC) and the Memory Address Register (MAR) during the fetch stage of the instruction cycle. Explain how the contents of these registers change when a JUMP instruction is encountered.
典型例题: 描述指令周期取指阶段程序计数器(PC)和存储器地址寄存器(MAR)的作用。解释当遇到跳转指令(JUMP)时,这些寄存器的内容如何变化。
During the fetch stage, the PC holds the address of the next instruction to be executed. This address is copied to the MAR, which then sends the address to memory via the address bus. The instruction is read and placed in the Memory Data Register (MDR), then the PC is incremented to point to the next sequential instruction. If a JUMP instruction is decoded and executed, the address part of that instruction is loaded directly into the PC, overriding the automatic increment. On the next fetch cycle, the PC content is transferred to the MAR, thus fetching from the target address.
在取指阶段,PC 中保存着下一条即将执行的指令地址。该地址被复制到 MAR,MAR 再通过地址总线送给存储器。存储器读出指令并放入存储数据寄存器(MDR),同时 PC 自动递增指向下一条顺序指令。如果译码并执行的是 JUMP 指令,则指令中的目标地址会直接加载到 PC,覆盖原来的自动递增值。在下一个取指周期,PC 的内容被送入 MAR,从而从跳转目标处取指。
Understanding this flow is essential for IB Paper 1 Section B questions on CPU organisation and for Edexcel’s computer architecture topics.
理解这一流程对IB试卷一B部分中关于CPU组织的题目以及爱德思计算机体系结构知识点至关重要。
4. Data Structures – Arrays and Linked Lists | 数据结构 – 数组与链表
Example problem: Compare the efficiency of inserting a new element at the beginning of an array versus a singly linked list. Justify your answer with reference to memory operations.
典型例题: 比较在数组和单链表的开头插入一个新元素的效率差异。请从内存操作的角度解释你的答案。
For an array stored in contiguous memory, inserting at index 0 requires shifting every existing element one position to the right. This takes O(n) time, where n is the number of elements. For a singly linked list, inserting at the head involves creating a new node, setting its next pointer to the current head, and updating the head pointer to the new node. This is an O(1) operation regardless of list size, as no shifting is required. Hence, linked lists are far more efficient for frequent front insertions.
对于以连续内存存储的数组,在下标0处插入一个新元素需要将所有已有元素向右移动一个位置,时间复杂度为 O(n),n 为元素个数。而对于单链表,在头部插入只需创建一个新节点,将其 next 指针指向当前头节点,然后更新头指针指向新节点。这是一个 O(1) 操作,与链表大小无关,因为无需移动元素。因此,若需频繁在头部插入,链表的效率远高于数组。
However, arrays provide O(1) random access, while linked lists require O(n) traversal. Exam questions often ask you to evaluate trade-offs in context, a key skill in both IB HL Paper 2 and Edexcel data structure evaluations.
但数组具备 O(1) 的随机访问能力,而链表则需要 O(n) 遍历。考试题目经常要求根据场景权衡利弊,这是IB高级水平试卷二和爱德思数据结构评估中的一项关键技能。
5. Sorting and Searching Algorithms | 排序与搜索算法
Example problem: Show the sequence of passes in a bubble sort on the list [5, 1, 4, 2, 8] and count the total number of comparisons. Then explain why binary search cannot be applied on an unsorted list.
典型例题: 展示对列表 [5, 1, 4, 2, 8] 进行冒泡排序的各趟过程,并统计比较总次数。然后解释为什么不能对未排序的列表使用二分查找。
Bubble sort passes:
Pass 1: (5,1) swap -> [1,5,4,2,8]; (5,4) swap -> [1,4,5,2,8]; (5,2) swap -> [1,4,2,5,8]; (5,8) no swap. End of pass 1: [1,4,2,5,8]. Comparisons: 4.
Pass 2: (1,4) no swap; (4,2) swap -> [1,2,4,5,8]; (4,5) no swap; (5,8) no swap. Comparisons: 4.
Pass 3: (1,2) no swap; (2,4) no swap; (4,5) no swap; (5,8) no swap. No swaps occurred, algorithm terminates. Comparisons: 4.
Total comparisons = 12 (worst-case would be 10 for n=5, but here due to implementation we checked all pairs). Binary search works by repeatedly dividing a sorted search space in half. If the list is unsorted, the middle element does not provide reliable information about where the target could be; the prerequisite ordering is violated, so the algorithm may fail to find an existing element or return an incorrect result.
冒泡排序各趟过程:
第1趟:比较(5,1) 交换 → [1,5,4,2,8];(5,4) 交换 → [1,4,5,2,8];(5,2) 交换 → [1,4,2,5,8];(5,8) 不交换。第1趟结束:[1,4,2,5,8],比较次数4。
第2趟:(1,4) 不交换;(4,2) 交换 → [1,2,4,5,8];(4,5) 不交换;(5,8) 不交换,比较次数4。
第3趟:(1,2) 不交换;(2,4) 不交换;(4,5) 不交换;(5,8) 不交换,无交换发生,算法终止,比较次数4。
总比较次数=12。二分查找依赖于重复将有序的搜索空间折半。如果列表未排序,中间元素的值无法可靠地判断目标值可能在哪一半,排序的先决条件被破坏,因此算法可能会找不到已存在的元素或返回错误结果。
6. Algorithm Efficiency and Big O | 算法效率与大O表示法
Example problem: Analyse the time complexity of the following pseudocode and express it in Big O notation.
for i = 0 to n-1
for j = i+1 to n-1
if arr[i] > arr[j] then swap
典型例题: 分析以下伪代码的时间复杂度,并用大O表示法表达。
for i = 0 to n-1
for j = i+1 to n-1
if arr[i] > arr[j] then swap
The outer loop runs n times. The inner loop runs (n-1) + (n-2) + … + 1 = n(n-1)/2 times. The total number of comparisons is approximately n²/2 for large n. Therefore, the time complexity is O(n²). This is the classic selection sort comparison pattern, though the swap is inside the inner loop here (makes it bubble-like but with same asymptotic complexity).
外循环执行 n 次。内循环的运行次数为 (n-1) + (n-2) + … + 1 = n(n-1)/2 次。当 n 很大时,总比较次数约等于 n²/2。因此时间复杂度为 O(n²)。这是经典的选择排序比较模式,尽管此处交换在内循环中执行(类似于冒泡但复杂度的渐近阶相同)。
In IB exams, you must also discuss best, average and worst case when relevant. Here all cases are O(n²) because the loops always execute fully. Edexcel papers similarly test Big O derivation from code snippets.
在IB考试中,你还需要在相关时讨论最好、平均和最坏情况。此处所有情况均为 O(n²),因为循环总是完整执行。爱德思的试卷同样会考查从代码片段推导大O表示法。
7. Core Object-Oriented Programming Concepts | 面向对象编程核心概念
Example problem: Define encapsulation and inheritance in OOP. Provide a Java or Python-like class diagram example where a Vehicle superclass is extended by Car and Motorcycle, illustrating data hiding with private attributes and public methods.
典型例题: 定义面向对象编程中的封装和继承。给出一个类似Java或Python的类图示例,其中超类 Vehicle 被 Car 和 Motorcycle 继承,并通过私有属性和公有方法展示数据隐藏。
Encapsulation means bundling data (attributes) and the methods that operate on that data within one unit and restricting direct access to some of an object’s components. This is commonly achieved using private attributes and public getter/setter methods. Inheritance allows a class (subclass) to acquire the properties and behaviours of an existing class (superclass), promoting code reusability.
封装指的是将数据(属性)和操作这些数据的方法捆绑在一个单元内,并限制对对象某些组成部分的直接访问。这通常通过私有属性和公有 getter/setter 方法来实现。继承允许一个类(子类)获得已有类(超类)的属性和行为,从而提高代码复用性。
For example, Vehicle has private attribute speed and public methods getSpeed() and setSpeed(). Car extends Vehicle, adding a private fuelType; Motorcycle extends Vehicle, adding a private hasSidecar. Both subclasses inherit the speed management methods but cannot directly access the superclass’s private speed field – they must use the inherited accessors. This satisfies encapsulation and inheritance simultaneously.
例如,Vehicle 类拥有私有属性 speed 以及公有方法 getSpeed() 和 setSpeed()。Car 继承 Vehicle,并增加私有属性 fuelType;Motorcycle 继承 Vehicle,增加私有属性 hasSidecar。两个子类都继承了速度管理方法,但不能直接访问超类的私有 speed 字段——它们必须使用继承来的访问器方法。这同时满足了封装和继承的要求。
Such questions appear in IB OOP option (Paper 2) and Edexcel Unit 2 programming paradigms.
此类题目出现在IB面向对象编程选项(试卷二)和爱德思单元二的编程范式中。
8. Database Design and SQL Queries | 数据库设计与SQL查询
Example problem: Given a table Students(StudentID, Name, YearGroup, TutorID) and Tutors(TutorID, TutorName, Subject), write an SQL query to list the names of all Year 12 students along with their tutor’s name. Also explain the need for a foreign key.
典型例题: 给定表 Students(StudentID, Name, YearGroup, TutorID) 和 Tutors(TutorID, TutorName, Subject),编写一个SQL查询,列出所有12年级学生的姓名及其导师姓名。并解释外键的必要性。
SQL query:
SELECT Students.Name, Tutors.TutorName
FROM Students
INNER JOIN Tutors ON Students.TutorID = Tutors.TutorID
WHERE Students.YearGroup = 'Year 12';
SQL查询:
SELECT Students.Name, Tutors.TutorName
FROM Students
INNER JOIN Tutors ON Students.TutorID = Tutors.TutorID
WHERE Students.YearGroup = 'Year 12';
The TutorID in the Students table is a foreign key that references the primary key of the Tutors table. This enforces referential integrity: a student cannot be assigned to a non-existent tutor, and it allows efficient joining of data from two related tables, avoiding data duplication.
Students 表中的 TutorID 是一个外键,它引用 Tutors 表的主键。这可以强制执行参照完整性:学生不能被分配给一个不存在的导师,同时支持从两个相关表中高效联接数据,避免了数据冗余。
IB and Edexcel both test simple joins, primary/foreign key concepts and the ability to interpret given table schemas.
IB和爱德思都会考查简单的联接查询、主键和外键概念以及对给定表结构的解读能力。
9. Networking Protocols and the OSI Model | 网络协议与OSI模型
Example problem: Explain the role of the TCP protocol in the transport layer. How does it differ from UDP in terms of reliability and use cases?
典型例题: 解释传输层中TCP协议的作用。它在可靠性和应用场景上与UDP有何不同?
TCP (Transmission Control Protocol) provides reliable, connection-oriented communication. It uses a three-way handshake to establish a session, sequences and acknowledges data, and retransmits lost packets. It is ideal for applications such as web browsing (HTTP/HTTPS), email (SMTP) and file transfers (FTP). UDP (User Datagram Protocol) is connectionless, offers no guarantee of delivery and no sequencing. Its overhead is lower, making it suitable for real-time applications like video streaming, online gaming or VoIP, where occasional packet loss is acceptable and speed is critical.
TCP(传输控制协议)提供可靠、面向连接的通信。它使用三次握手建立会话,对数据排序并确认,丢失的包会重传。它适用于网页浏览(HTTP/HTTPS)、电子邮件(SMTP)和文件传输(FTP)等应用。UDP(用户数据报协议)是无连接的,不保证交付,也不排序。其开销更小,因此适用于实时应用,如视频流、在线游戏或网络电话,这些场景允许偶尔丢包但对速度要求高。
Such questions bridge IB Topic 3 (Networks) and Edexcel communication and Internet technologies, asking for conceptual understanding rather than packet-level detail.
这类问题衔接了IB主题3(网络)和爱德思通信与互联网技术部分,要求的是概念理解而非数据包级别的细节。
10. Pseudocode Tracing and Flowcharts | 伪代码追踪与流程图
Example problem: Trace the following pseudocode and state the final value of sum and count.
sum = 0
count = 0
for i = 1 to 5
if i mod 2 = 0 then
sum = sum + i
count = count + 1
endif
endfor
典型例题: 追踪下列伪代码并说明 sum 和 count 的最终值。
sum = 0
count = 0
for i = 1 to 5
if i mod 2 = 0 then
sum = sum + i
count = count + 1
endif
endfor
Trace table:
i=1: mod2=1, skip.
i=2: mod2=0, sum=2, count=1.
i=3: mod2=1, skip.
i=4: mod2=0, sum=2+4=6, count=2.
i=5: mod2=1, skip.
Final output: sum=6, count=2. The algorithm sums even numbers from 1 to 5 and counts how many evens were processed.
追踪表:
i=1:模2=1,跳过。
i=2:模2=0,sum=2,count=1。
i=3:模2=1,跳过。
i=4:模2=0,sum=2+4=6,count=2。
i=5:模2=1,跳过。
最终:sum=6,count=2。该算法求1到5之间偶数的和并统计偶数的个数。
IB exams frequently present such tracing tasks, while Edexcel uses similar logic in code comprehension exercises and flowchart interpretation.
IB考试经常出现此类追踪任务,而爱德思在代码理解练习和流程解读中也使用类似的逻辑。
11. Operating System Concepts – Scheduling | 操作系统概念 – 调度
Example problem: Three processes P1, P2, P3 arrive at time 0 with burst times 24, 3, 3 (in ms). Calculate the average waiting time using Round Robin scheduling with a time quantum of 4 ms. Explain one advantage of this scheduling method.
典型例题: 三个进程 P1、P2、P3 在时刻0同时到达,CPU执行时间分别为 24、3、3(毫秒)。使用时间片为 4 ms 的轮转调度算法计算平均等待时间。并说明该调度方法的一个优点。
Gantt chart with quantum q=4:
Time 0: P1 runs 4ms (remaining 20).
Time 4: P2 runs 3ms and finishes at time 7.
Time 7: P3 runs 3ms and finishes at time 10.
Time 10: P1 runs 4ms (remaining 16).
Time 14: P1 runs 4ms (12).
Time 18: P1 runs 4ms (8).
Time 22: P1 runs 4ms (4).
Time 26: P1 runs last 4ms, finishes at 30.
Waiting time for P1 = completion time – burst time – arrival time = 30 – 24 – 0 = 6 ms? Actually, waiting time = turnaround time – burst time. Turnaround for P1 = 30 – 0 = 30, waiting = 30 – 24 = 6 ms. P2 turnaround = 7 – 0 = 7, waiting = 7 – 3 = 4 ms. P3 turnaround = 10 – 0 = 10, waiting = 10 – 3 = 7 ms. Average waiting = (6+4+7)/3 ≈ 5.67 ms.
甘特图(时间片 q=4):
时刻0:P1执行4ms(剩余20)。
时刻4:P2执行3ms,在时刻7完成。
时刻7:P3执行3ms,在时刻10完成。
时刻10:P1执行4ms(剩余16)。
时刻14:P1执行4ms(12)。
时刻18:P1执行4ms(8)。
时刻22:P1执行4ms(4)。
时刻26:P1执行最后4ms,于时刻30完成。
等待时间:P1 = 周转时间 – 执行时间 = (30-0) – 24 = 6 ms;P2 = (7-0) – 3 = 4 ms;P3 = (10-0) – 3 = 7 ms。平均等待时间 = (6+4+7)/3 ≈ 5.67 ms。
An advantage of Round Robin is fairness: no process monopolises the CPU; short processes get quick response, making it suitable for time-sharing systems.
轮转调度的一个优点是公平性:没有进程能垄断CPU,短进程能快速得到响应,适合分时系统。
12. Computational Thinking and Problem Solving | 计算思维与问题求解
Example problem: You need to design an algorithm to count the frequency of each word in a text file. Outline the steps using computational thinking principles (decomposition, pattern recognition, abstraction, algorithm design).
典型例题: 需要设计一个算法统计文本文件中每个单词出现的频率。运用计算思维原则(分解、模式识别、抽象、算法设计)简述步骤。
Decomposition: break the problem into reading the file, splitting text into words, normalising case, counting occurrences, and reporting results. Pattern recognition: identify that a hash map (dictionary) can efficiently map each unique word to its count, similar to frequency counting patterns. Abstraction: ignore punctuation details by removing non-alphabetic characters and focus on the word as a string key. Algorithm design:
1. Open file and read all text.
2. Convert to lowercase and remove punctuation.
3. Split text by whitespace to get a list of words.
4. Initialise an empty dictionary.
5. For each word: if word exists in dictionary, increment its value; else add it with value 1.
6. Output the dictionary.
This stepwise approach directly maps to exam rubrics assessing computational thinking in both IB and Edexcel.
分解:将问题拆分为读取文件、将文本分割为单词、统一大小写、统计出现次数和输出结果。模式识别:识别出哈希表(字典)能高效地将每个唯一单词映射到其出现次数,类似于一般的频率统计模式。抽象
Published by TutorHao | IB Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导