📚 Unit Test Mock Paper Walkthrough | 单元测试模拟卷解析
This article provides a detailed walkthrough of a mock unit test for Year 13 Edexcel Computer Science. Each section presents a typical exam-style question, followed by a step-by-step solution, highlighting key concepts and common pitfalls. Follow along to strengthen your understanding and exam technique.
本文为 Year 13 Edexcel 计算机科学的单元测试模拟卷提供详细解析。每节呈现一道典型试题,逐步解答,突出关键概念与常见陷阱。跟随解析,加深理解、提升应试技巧。
1. Data Representation & Two’s Complement | 数据表示与二进制补码
Question: Convert the decimal integer -73 into its 8-bit two’s complement representation. Show all steps clearly.
问题:将十进制整数 -73 转换为 8 位二进制补码表示。清晰展示所有步骤。
Step 1: Represent the magnitude (73) in 8-bit unsigned binary. 73 = 64 + 8 + 1, giving 01001001.
步骤一:将绝对值 73 表示为 8 位无符号二进制。73 = 64 + 8 + 1,得到 01001001。
Step 2: Invert all bits (one’s complement). 01001001 → 10110110.
步骤二:将所有位取反(反码)。01001001 → 10110110。
Step 3: Add 1 to the least significant bit to obtain two’s complement. 10110110 + 1 = 10110111.
步骤三:最低位加 1 得到补码。10110110 + 1 = 10110111。
Therefore, the 8-bit two’s complement of -73 is 10110111₂. Always check the answer: the most significant bit is 1, confirming a negative number. Adding +73 (01001001₂) to 10110111₂ yields 1 00000000₂, which overflows the 8 bits leaving 00000000, confirming correctness.
因此,-73 的 8 位补码为 10110111₂。务必验证:最高位为 1,确认是负数。将 +73 (01001001₂) 与 10110111₂ 相加得到 1 00000000₂,超出 8 位溢出后得 00000000,验证正确。
2. Floating Point Normalisation | 浮点数规范化
Question: Convert the decimal number 10.75 into a normalised floating point binary representation using an 8-bit mantissa and a 4-bit exponent with two’s complement. Assume the format: mantissa then exponent.
问题:将十进制数 10.75 转换为规范化浮点二进制表示,使用 8 位尾数和 4 位阶码(均用补码)。假定格式:尾数后接阶码。
Step 1: Express the fixed-point binary. 10.75 = 1010.11₂ (10 = 1010₂, 0.75 = 0.11₂).
步骤一:转为定点二进制。10.75 = 1010.11₂(10 = 1010₂,0.75 = 0.11₂)。
Step 2: Move the binary point to normalise to the form 1.M × 2ᵉ. Shift left until a single 1 appears before the point: 1010.11 becomes 0.101011 × 2⁴. But for normalised two’s complement, a positive mantissa must start with 01. So shift to get 0.1010110₂ × 2⁴.
步骤二:移动小数点以规范化为 1.M × 2ᵉ 形式。左移至小数点前仅一位 1:1010.11 变为 0.101011 × 2⁴。但对于补码规范化,正尾数须以 01 开头,故得到 0.1010110₂ × 2⁴。
Step 3: Fit mantissa into 8 bits, padding with trailing zeros: 01010110₂ (the leading 0 is sign, then 1010110).
步骤三:将尾数填充至 8 位,末尾补零:01010110₂(前导 0 是符号位,后跟 1010110)。
Step 4: Represent exponent 4 in 4-bit two’s complement: 0100₂.
步骤四:将指数 4 用 4 位补码表示:0100₂。
Combine: mantissa 01010110, exponent 0100. Hence the binary word is 01010110 0100₂.
组合:尾数 01010110,阶码 0100。因此二进制字为 01010110 0100₂。
Always ensure the mantissa is in the range 0.5 ≤ |M| < 1 for normalisation.
须确保规范化后尾数满足 0.5 ≤ |M| < 1。
3. Boolean Algebra & Karnaugh Map Simplification | 布尔代数与卡诺图化简
Question: Simplify the Boolean expression F = (A ∧ ¬B) ∨ (A ∧ B) ∨ (¬A ∧ B) using algebraic laws. Then confirm the result with a Karnaugh map.
问题:使用代数定律化简布尔表达式 F = (A ∧ ¬B) ∨ (A ∧ B) ∨ (¬A ∧ B),并用卡诺图验证结果。
Algebraic simplification: Factor A from the first two terms: F = A ∧ (¬B ∨ B) ∨ (¬A ∧ B). Since ¬B ∨ B = 1, we get A ∧ 1 ∨ (¬A ∧ B) = A ∨ (¬A ∧ B). Expand: A ∨ (¬A ∧ B) = (A ∨ ¬A) ∧ (A ∨ B) = 1 ∧ (A ∨ B) = A ∨ B.
代数化简:前两项提取 A:F = A ∧ (¬B ∨ B) ∨ (¬A ∧ B)。因 ¬B ∨ B = 1,得 A ∧ 1 ∨ (¬A ∧ B) = A ∨ (¬A ∧ B)。展开:A ∨ (¬A ∧ B) = (A ∨ ¬A) ∧ (A ∨ B) = 1 ∧ (A ∨ B) = A ∨ B。
Karnaugh map: Draw a 2-variable map for A and B. Minterms where F=1 are m1 (¬A B), m2 (A ¬B), m3 (A B). Plotting shows a grouping of two adjacent cells (A ¬B + A B) forming A, and another grouping (¬A B + A B) forming B. Thus F = A ∨ B, confirming the result.
卡诺图:绘制两变量 A、B 的卡诺图。F=1 的最小项为 m1 (¬A B)、m2 (A ¬B)、m3 (A B)。填入后,相邻单元格 (A ¬B + A B) 可合并为 A,另一组 (¬A B + A B) 合并为 B。因此 F = A ∨ B,验证无误。
4. CPU Architecture & Pipelining | CPU 体系结构与流水线
Question: Explain how instruction pipelining improves processor performance. Illustrate with a 3-stage pipeline (fetch, decode, execute) and calculate the potential speedup when executing 100 instructions, assuming no hazards.
问题:解释指令流水线如何提升处理器性能。以三级流水线(取指、译码、执行)为例,计算在无冒险情况下执行 100 条指令可能获得的加速比。
Explanation: Without pipelining, each instruction must complete all three stages before the next begins. With a k-stage pipeline, once the first instruction completes its fetch, the second instruction can enter the fetch stage in the next clock cycle. Ideally, after k cycles to fill the pipeline, one instruction completes per cycle.
解释:无流水线时,每条指令必须完成所有三级后下一条才能开始。使用 k 级流水线后,第一条取指结束时,第二条可在下一时钟周期进入取指阶段。理想情况下,经过 k 个周期的填满时间后,每周期完成一条指令。
Speedup calculation: Non-pipelined time for N instructions = N × k cycles (each instruction takes 3 cycles). Pipelined time = k + (N-1) cycles. For N=100, k=3: non-pipelined = 300 cycles; pipelined = 3 + 99 = 102 cycles. Speedup = 300 / 102 ≈ 2.94.
加速比计算:非流水线执行 N 条指令需 N × k 周期(每条 3 周期)。流水线需 k + (N-1) 周期。N=100,k=3:非流水 = 300 周期;流水 = 3 + 99 = 102 周期。加速比 = 300 / 102 ≈ 2.94。
Note: Real speedup is limited by data hazards, control hazards, and structural hazards, requiring stalling or forwarding techniques.
注:实际加速比受数据冒险、控制冒险和结构冒险限制,需停顿或转发技术处理。
5. Operating System Scheduling | 操作系统调度
Question: Consider three processes P1, P2, P3 with burst times 8, 4, 4 ms arriving at time 0. Calculate the average waiting time for (a) First-Come First-Served (FCFS) and (b) Shortest Job First (SJF, non-preemptive). Show the Gantt chart and compare.
问题:设三个进程 P1、P2、P3,运行时间分别为 8、4、4 毫秒,同时到达。计算 (a) 先来先服务 (FCFS) 和 (b) 最短作业优先 (SJF,非抢占) 的平均等待时间。画出甘特图并比较。
(a) FCFS Gantt chart: P1 runs first (0-8 ms), then P2 (8-12 ms), then P3 (12-16 ms).
(a) FCFS 甘特图:P1 先运行 (0-8 毫秒),随后 P2 (8-12 毫秒),然后 P3 (12-16 毫秒)。
Waiting times: P1 = 0 ms, P2 = 8 ms, P3 = 12 ms. Average = (0+8+12)/3 = 6.67 ms.
等待时间:P1 = 0 毫秒,P2 = 8 毫秒,P3 = 12 毫秒。平均 = (0+8+12)/3 = 6.67 毫秒。
(b) SJF: Choose the shortest job first. P2 and P3 both have 4 ms, so assume order P2 then P3. Gantt: P2 (0-4), P3 (4-8), P1 (8-16).
(b) SJF:先选最短作业。P2、P3 均为 4 毫秒,假定顺序 P2 后 P3。甘特图:P2 (0-4)、P3 (4-8)、P1 (8-16)。
Waiting times: P2 = 0 ms, P3 = 4 ms, P1 = 8 ms. Average = (0+4+8)/3 = 4 ms. SJF yields lower average waiting time than FCFS.
等待时间:P2 = 0 毫秒,P3 = 4 毫秒,P1 = 8 毫秒。平均 = (0+4+8)/3 = 4 毫秒。SJF 平均等待时间低于 FCFS。
Summary: SJF average = 4 ms, FCFS average = 6.67 ms.
总结:SJF 平均 4 毫秒,FCFS 平均 6.67 毫秒。
6. Recursion & Call Stack | 递归与调用栈
Question: Trace the execution of the recursive function fact(4) defined as: fact(n) = 1 if n=0, else n * fact(n-1). Show the state of the call stack at each recursive call, and the final return value.
问题:跟踪递归函数 fact(4) 的执行过程,其定义为:fact(n) = 1(若 n=0),否则 n * fact(n-1)。展示每次递归调用时的调用栈状态及最终返回值。
Call stack steps: Initially, fact(4) is called. Stack: [fact(4)]. It calls fact(3), stack: [fact(4), fact(3)]. Then fact(3) calls fact(2) → [fact(4),fact(3),fact(2)]. Then fact(2) calls fact(1) → [fact(4),fact(3),fact(2),fact(1)]. fact(1) calls fact(0) → [fact(4),fact(3),fact(2),fact(1),fact(0)]. base case fact(0) returns 1.
调用栈步骤:初始调用 fact(4)。栈:[fact(4)]。它调用 fact(3),栈:[fact(4), fact(3)]。fact(3) 调用 fact(2) → [fact(4),fact(3),fact(2)]。fact(2) 调用 fact(1) → [fact(4),fact(3),fact(2),fact(1)]。fact(1) 调用 fact(0) → [fact(4),fact(3),fact(2),fact(1),fact(0)]。基线条件 fact(0) 返回 1。
Unwinding: fact(1) receives 1, returns 1*1=1. fact(2) returns 2*1=2. fact(3) returns 3*2=6. fact(4) returns 4*6=24. Stack empties.
回退:fact(1) 收到 1,返回 1*1=1。fact(2) 返回 2*1=2。fact(3) 返回 3*2=6。fact(4) 返回 4*6=24。栈清空。
Final result: 24. Be careful to identify the base case to avoid infinite recursion.
最终结果:24。注意识别基线条件,避免无限递归。
7. Linked List Insertion & Deletion | 链表插入与删除
Question: Given a singly linked list storing values A→B→D, write pseudocode to insert node C between B and D, ensuring pointers are updated correctly. Then outline how to delete node B.
问题:给定单链表存储值 A→B→D,编写伪代码在 B 和 D 之间插入节点 C,确保正确更新指针。然后概述如何删除节点 B。
Insertion steps: Create new node C with data ‘C’. Set C.next = B.next (which points to D). Then set B.next = C. It is critical to set C.next before overwriting B.next, otherwise the link to D is lost.
插入步骤:创建数据为 ‘C’ 的新节点 C。令 C.next = B.next(指向 D)。然后令 B.next = C。务必先设置 C.next 再覆盖 B.next,否则会丢失指向 D 的链。
Pseudocode: newNode = Node(‘C’); newNode.next = B.next; B.next = newNode;
伪代码:newNode = Node(‘C’); newNode.next = B.next; B.next = newNode;
Deletion of B: To delete node B, we need a reference to the previous node A. Set A.next = B.next (which is now C or D). Then free B. If the list is singly linked and we only have a pointer to B, we can copy data from C to B and delete C, but the question assumes we have access to the head and can traverse to A.
删除 B:要删除 B,需持有前驱节点 A 的引用。令 A.next = B.next(现为 C 或 D)。然后释放 B。若只有单向链表且仅持有指向 B 的指针,可将 C 的数据复制到 B 再删除 C,但本题假定可从头遍历找到 A。
Always update references to preserve list integrity.
务必更新引用以保持链表完整性。
8. Binary Tree Traversals | 二叉树遍历
Question: Given the binary tree where root is A, left child B (with left D, right E), right child C (with left F, right G). List the nodes in pre-order, in-order, and post-order traversal.
问题:给定二叉树:根 A,左子 B(左子树 D,右子树 E),右子 C(左子树 F,右子树 G)。列出前序、中序、后序遍历节点顺序。
Pre-order (Root, Left, Right): A, B, D, E, C, F, G.
前序(根、左、右):A, B, D, E, C, F, G。
In-order (Left, Root, Right): D, B, E, A, F, C, G. Remember to visit the entire left subtree before the root.
中序(左、根、右):D, B, E, A, F, C, G。记得在访问根之前遍历整个左子树。
Post-order (Left, Right, Root): D, E, B, F, G, C, A.
后序(左、右、根):D, E, B, F, G, C, A。
These sequences are fundamental for expression trees and memory management; ensure you can apply the recursive definitions correctly.
这些遍历序列是表达式树和内存管理的基础;确保能正确应用递归定义。
9. Graph Algorithm – Dijkstra’s Shortest Path | 图算法 – Dijkstra 最短路径
Question: Use Dijkstra’s algorithm to find the shortest path from node S to node T in the following weighted graph: S→A (4), S→B (2), A→B (1), A→C (5), B→C (8), B→D (10), C→T (3), D→T (6). Show
Published by TutorHao | Year 13 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