📚 Unit Test Mock Paper Analysis | 单元测试模拟卷解析
Unit tests in the Pre-U OCR Computer Science course assess your grasp of fundamental computing concepts, from data representation and logic gates to algorithm design and object-oriented programming. This article walks you through a carefully designed mock paper, breaking down each question type, highlighting common pitfalls, and providing step-by-step solutions. By studying these model answers, you will strengthen your problem-solving skills and build confidence for the real examination.
Pre-U OCR 计算机科学课程中的单元测试旨在考察你对基础计算概念的掌握情况,包括数据表示、逻辑门、算法设计以及面向对象编程。本文带你逐题解析一套精心设计的模拟试卷,拆解每类问题的解法,指出常见错误,并提供分步解答。通过学习这些范例答案,你将提高解决问题的能力,从容应对正式考试。
1. Understanding the Pre-U OCR Computer Science Unit Test | 理解 Pre-U OCR 计算机科学单元测试
The Pre-U OCR Computer Science unit test is typically a 1-hour internal assessment covering one major topic area such as Fundamentals of Computing or Programming Techniques. Questions range from short factual recall to extended problem-solving scenarios that require you to analyse, design, and evaluate. The mock paper analysed here mirrors that structure, with a mix of short-answer questions in Section A and longer programming tasks in Section B.
Pre-U OCR 计算机科学单元测试通常为 1 小时的内部测评,覆盖一个主要专题,如计算基础或编程技术。题目既有简短的知识点回忆,也有需要分析、设计和评估的扩展性问题。本文解析的模拟试卷即模拟该结构,Section A 为简答题,Section B 为较长的编程任务。
2. Mock Paper Structure and Topics Covered | 模拟试卷结构与覆盖主题
This practice paper consists of two sections. Section A (40 marks) includes five compulsory short-answer questions testing binary arithmetic, logic circuits, data structures, algorithm efficiency, and basic hardware concepts. Section B (60 marks) presents a programming scenario requiring implementation of a simple inventory system, with sub-questions on recursion, object-oriented design, and error handling. The topics align closely with the Pre-U specification: data representation, Boolean algebra, arrays vs linked lists, Big O notation, and object-oriented principles.
本练习卷包含两个部分。Section A(40 分)设有 5 道必答简答题,考查二进制算术、逻辑电路、数据结构、算法效率和基础硬件概念。Section B(60 分)给出一个编程情境,要求实现一个简单的库存系统,子问题涉及递归、面向对象设计和错误处理。这些主题与 Pre-U 考纲紧密对应:数据表示、布尔代数、数组与链表对比、大 O 表示法以及面向对象原则。
3. Section A: Short-Answer Questions – Walkthrough | 第一部分:简答题 – 解题指导
Short-answer questions reward precision and clarity. Each response should be concise yet well reasoned. Let us examine the first question on binary arithmetic and logic, where many candidates lose marks by misapplying two’s complement or forgetting to show working steps.
简答题看重准确与清晰。每个答案应简洁但有推理过程。我们来看第一道关于二进制算术与逻辑的题目,许多考生因错误应用二进制补码或未展示步骤而失分。
4. Question 1: Binary Arithmetic and Logic Gates | 问题 1:二进制算术与逻辑门
Question: Perform the subtraction 45 – 18 using 8-bit two’s complement. Show all your steps. Then, draw a circuit diagram using only NAND gates that implements the XOR function for two inputs A and B.
题目:用 8 位二进制补码计算 45 – 18,并写出所有步骤。然后仅用与非门画出实现两输入 A 和 B 的异或功能的电路图。
Solution: First, represent 45 in 8-bit binary: 00101101. 18 is 00010010; its two’s complement is 11101110. Add 00101101 + 11101110 = 100011011. Discarding the carry, we get 00011011, which equals 27 in decimal. For the XOR using NAND: XOR = (A NAND (A NAND B)) NAND ((A NAND B) NAND B). The circuit requires four NAND gates connected accordingly.
解答:首先将 45 表示为 8 位二进制 00101101。18 是 00010010,其补码为 11101110。相加得 00101101 + 11101110 = 100011011。舍去进位得到 00011011,即十进制的 27。用与非门实现异或:XOR = (A NAND (A NAND B)) NAND ((A NAND B) NAND B)。电路需要 4 个与非门按此连接。
5. Question 2: Data Structures – Arrays and Linked Lists | 问题 2:数据结构 – 数组与链表
Question: Compare the use of arrays and singly linked lists for implementing a dynamic playlist. Discuss memory allocation, insertion at the head, and access to the k-th element. State which structure you would choose and why.
题目:比较数组和单链表在实现动态播放列表时的应用。讨论内存分配、在表头插入元素以及访问第 k 个元素。说明你会选择哪种结构并解释理由。
Model answer: An array stores elements in contiguous memory, allowing O(1) access to any index but requiring shifting for insertions at the head (O(n)). A linked list uses non-contiguous nodes; inserting at the head is O(1) because only the head pointer changes. However, accessing the k-th element requires O(k) traversal. For a playlist where songs are frequently added to the front (e.g., queue behaviour) and sequential access is common, I would choose a linked list. It avoids costly shifting and uses memory flexibly, though it incurs extra pointer overhead.
范例答案:数组将元素存储在连续内存中,可按索引 O(1) 时间访问,但在表头插入需要移动元素,为 O(n)。链表使用非连续节点,表头插入仅需修改头指针,为 O(1)。但访问第 k 个元素需 O(k) 的遍历时间。对于歌曲常添加到前端(如队列行为)且以顺序访问为主的播放列表,我会选择链表。它避免了昂贵的移位操作,内存使用灵活,尽管会带来额外指针开销。
6. Question 3: Algorithm Analysis – Big O Notation | 问题 3:算法分析 – 大 O 表示法
Question: A program contains a loop that runs log₂ n times for each of the n iterations of an outer loop. Express the worst-case time complexity in Big O notation. Then, analyse a recursive algorithm that solves a problem of size n by dividing it into three subproblems of size n/2 and combining in O(n) time. State the resulting recurrence and its solution.
题目:某程序外层循环执行 n 次,内层循环每次执行 log₂ n 次。请用大 O 表示法表示最坏时间复杂度。再分析一个递归算法:将规模为 n 的问题分为 3 个规模为 n/2 的子问题,合并需 O(n) 时间。写出递推关系式并求解。
Solution: Outer loop n iterations, each performing log₂ n operations → O(n log n). For the recursive algorithm: T(n) = 3T(n/2) + O(n). By the Master Theorem, a = 3, b = 2, log₂3 ≈ 1.585. Since f(n) = O(n) and log₂3 > 1, the running time is O(n^{log₂3}), roughly O(n¹·⁵⁸⁵).
解答:外层 n 次迭代,每次执行 log₂ n 次操作 → O(n log n)。对于递归算法:T(n) = 3T(n/2) + O(n)。由主定理,a = 3,b = 2,log₂3 ≈ 1.585。由于 f(n) = O(n) 且 log₂3 > 1,复杂度为 O(n^{log₂3}),约 O(n¹·⁵⁸⁵)。
7. Section B: Programming and Problem-Solving | 第二部分:编程与问题求解
Section B simulates a real-world programming task. You are given a partially completed class for an inventory item and must write code for several methods, explain design decisions, and identify error conditions. The following subsections break down the key sub-questions.
Section B 模拟真实编程任务。题目给出一个库存物品类的部分代码,你需编写多个方法,解释设计决策并指出错误条件。以下小节逐一分析关键子问题。
8. Question 4: Recursive Function in Python | 问题 4:Python 递归函数
Task: Implement a recursive function search_subtree(root, target_id) that searches a binary search tree for a product node. Return the node if found, otherwise None. Explain how your recursion terminates.
任务:实现递归函数 search_subtree(root, target_id),在二叉搜索树中查找产品节点。找到返回节点,否则返回 None。解释你的递归如何终止。
Sample solution in pseudocode:
function search_subtree(node, target):
if node is None:
return None
if node.id == target:
return node
elif target < node.id:
return search_subtree(node.left, target)
else:
return search_subtree(node.right, target)
The recursion terminates when node becomes None (base case) or when the target is found. Each call reduces the search space by descending one level in the tree.
示例解答(伪代码):
function search_subtree(node, target):
if node is None:
return None
if node.id == target:
return node
elif target < node.id:
return search_subtree(node.left, target)
else:
return search_subtree(node.right, target)
递归在 node 为 None 时(基线条件)或找到目标时终止。每次调用将搜索空间缩小一层。
9. Question 5: Object-Oriented Design Principles | 问题 5:面向对象设计原则
Question: You are to extend the Product class to create a DiscountedProduct subclass. The subclass must calculate price after applying a discount percentage, but the discount must never exceed 50%. Also, explain how encapsulation is preserved.
题目:你需要扩展 Product 类,创建 DiscountedProduct 子类。子类应计算应用折扣百分比后的价格,但折扣不得超过 50%。并说明如何保持封装性。
Answer: The DiscountedProduct class inherits Product and adds a private attribute __discount. The set_discount(percent) method validates that percent ≤ 50 before assignment. The get_price() method overrides the parent's to return base_price * (1 - __discount/100). Encapsulation is preserved by making the discount attribute private and exposing controlled access through getter and setter methods, preventing invalid states.
解答:DiscountedProduct 类继承 Product,并添加私有属性 __discount。set_discount(percent) 方法验证 percent ≤ 50 后才赋值。get_price() 重写父类方法,返回 base_price * (1 - __discount/100)。通过将折扣属性设为私有,并通过 getter 和 setter 方法控制访问,避免了无效状态,从而保持了封装性。
10. Common Mistakes and How to Avoid Them | 常见错误及避免方法
Many students lose marks by forgetting to show working in binary arithmetic, confusing Big O of recursive algorithms, or writing code that lacks base-case handling. In object-oriented questions, failing to use private attributes or not checking boundary conditions (e.g., discount > 50%) reduces marks. Always read the question carefully, underline key verbs, and structure your answer with clear headings if allowed.
许多学生因忘记展示二进制运算步骤、混淆递归算法的大 O 表示,或编写的代码缺少基线条件而失分。面向对象题目中,不使用私有属性或不检查边界条件(如折扣超过 50%)都会扣分。务必认真审题,划出关键动词,并在允许的情况下用清晰标题组织答案。
11. Final Tips for the Unit Test | 单元测试最后建议
Practise past mock papers under timed conditions. Focus on writing neat, commented code, and always justify your design choices. Revise the Pre-U specification glossary terms: abstraction, decomposition, recursion, and modularisation. For algorithms, be ready to derive Big O from nested loops and recurrence relations. Draw logic gate circuits neatly and label inputs/outputs.
在定时条件下练习模拟卷。注重编写整洁、带注释的代码,并始终给出设计选择的理由。复习 Pre-U 考纲术语:抽象、分解、递归和模块化。算法方面要会从嵌套循环和递推关系中推导大 O。绘制逻辑门电路要整齐,并标注输入输出。
Published by TutorHao | Computer 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