📚 A-Level OCR Computer Science: Typical Exam Questions Explained | A-Level OCR 计算机:典型例题详解
This article presents a collection of typical exam-style questions for the A-Level OCR Computer Science specification (H446). Covering key topics from computer systems to algorithms, each worked example provides step-by-step solutions and explanations to help you consolidate your understanding and excel in the exam.
本文精选了 A-Level OCR 计算机科学(H446 考纲)的典型考题。涵盖从计算机系统到算法的核心主题,每道例题都提供分步解答和解析,帮助你巩固知识并取得优异成绩。
1. Number Systems: Binary and Hexadecimal Conversion | 数制系统:二进制与十六进制转换
Question: Convert the hexadecimal number 3A7F₁₆ into binary. Show your grouping and final binary representation.
问题:将十六进制数 3A7F₁₆ 转换为二进制。展示分组过程及最终二进制表示。
Each hexadecimal digit corresponds to exactly 4 bits because 16 = 2⁴. We map 3 → 0011, A (10) → 1010, 7 → 0111, F (15) → 1111.
每个十六进制数字恰好对应 4 个二进制位,因为 16 = 2⁴。依次映射:3 → 0011,A (10) → 1010,7 → 0111,F (15) → 1111。
3A7F₁₆ = 0011 1010 0111 1111₂
Omitting leading zeros gives the compact form: 11101001111111₂. Always ensure each hex digit expands to a full nibble, even if leading zeros disappear in the final result.
省略前导零后的紧凑形式为:11101001111111₂。务必确保每个十六进制数字都展开为完整的 4 位半字节,即使前导零在最终结果中消失。
2. Boolean Algebra Simplification | 布尔代数化简
Question: Simplify the Boolean expression F = A·B + ¬A·B + A·¬B using algebraic laws.
问题:使用代数定律化简布尔表达式 F = A·B + ¬A·B + A·¬B。
First, apply the distributive law to the first two terms: A·B + ¬A·B = B·(A + ¬A) = B·1 = B.
首先,对前两项应用分配律:A·B + ¬A·B = B·(A + ¬A) = B·1 = B。
Now the expression becomes F = B + A·¬B. Using the absorption rule (or by considering that B + A·¬B = B + A), we obtain the simplified result.
此时表达式变为 F = B + A·¬B。利用吸收律(或考虑 B + A·¬B = B + A),即得到最简结果。
F = A + B
This proves that the original three-term sum of products reduces to a single OR gate: the output is true whenever A is true or B is true.
这证明了原来三项乘积之和可以化简为一个单一的或门:当 A 为真或 B 为真时输出为真。
3. CPU Pipelining and Data Hazards | CPU 流水线与数据冒险
Question: Consider the instruction sequence: ADD R1, R2, R3 followed by SUB R4, R1, R5. Identify the type of hazard and explain how forwarding resolves it.
问题:给定指令序列:ADD R1, R2, R3 之后为 SUB R4, R1, R5。指出冒险类型,并解释旁路(转发)如何解决该问题。
The ADD instruction writes to R1 in the write-back stage, but SUB needs the updated R1 earlier in the execute stage. This is a RAW (read-after-write) data hazard.
ADD 指令在写回阶段将结果写入 R1,但 SUB 需要在执行阶段更早地读取更新后的 R1。这是一个 RAW(读后写)数据冒险。
Without forwarding, the pipeline would stall until R1 is available. Forwarding adds extra datapaths that feed the ALU result directly from the EX/MEM or MEM/WB pipeline registers back to the ALU input, bypassing the register file.
若无旁路,流水线将停顿直到 R1 可用。旁路通过添加额外数据路径,将 ALU 结果直接从 EX/MEM 或 MEM/WB 流水线寄存器转发回 ALU 输入端,从而绕开了寄存器堆。
Thus the SUB instruction can proceed with the correct R1 value one cycle after ADD produces it, avoiding a pipeline bubble.
因此 SUB 指令可在 ADD 产生结果的一个周期后使用正确的 R1 值继续执行,避免了流水线气泡。
4. Stack Operations | 栈操作
Question: An empty stack undergoes the following operations: push(5), push(10), pop(), push(15), pop(). State the elements popped and the final stack content.
问题:一个空栈依次执行以下操作:push(5),push(10),pop(),push(15),pop()。列出弹出的元素及最终栈内容。
After push(5) and push(10), the stack contains [5, 10] (top is 10). The first pop() removes and returns 10, leaving [5]. Push(15) then pushes 15 onto the stack, giving [5, 15]. The second pop() removes and returns 15, leaving [5].
执行 push(5) 和 push(10) 后,栈为 [5, 10](栈顶为 10)。第一个 pop() 移除并返回 10,剩下 [5]。随后 push(15) 将 15 压入,得到 [5, 15]。第二个 pop() 移除并返回 15,最终栈内为 [5]。
The popped elements, in order, are 10 and 15. Stacks follow a LIFO (last-in-first-out) discipline, which is crucial for subroutine calls and expression evaluation.
弹出元素的顺序为 10 和 15。栈遵循 LIFO(后进先出)原则,这对子程序调用和表达式求值至关重要。
5. Bubble Sort Algorithm | 冒泡排序算法
Question: Show the state of the array after the first pass of bubble sort on [9, 3, 7, 2, 1]. Describe each swap.
问题:对数组 [9, 3, 7, 2, 1] 执行第一趟冒泡排序,展示排序后的数组状态,并描述每次交换。
Bubble sort compares adjacent elements and swaps them if they are in the wrong order. First pass: compare 9 and 3 → swap → [3, 9, 7, 2, 1]. Compare 9 and 7 → swap → [3, 7, 9, 2, 1]. Compare 9 and 2 → swap → [3, 7, 2, 9, 1]. Compare 9 and 1 → swap → [3, 7, 2, 1, 9].
冒泡排序比较相邻元素,若顺序错误则交换。第一趟:比较 9 与 3 → 交换 → [3, 9, 7, 2, 1]。比较 9 与 7 → 交换 → [3, 7, 9, 2, 1]。比较 9 与 2 → 交换 → [3, 7, 2, 9, 1]。比较 9 与 1 → 交换 → [3, 7, 2, 1, 9]。
After the first pass, the largest element 9 has “bubbled” to its correct final position at the end of the array.
第一趟结束后,最大元素 9 已经“冒泡”到数组末尾的正确最终位置。
6. SQL Query Writing | SQL 查询编写
Question: A table Students has columns StudentID, Name, and Grade. Write an SQL statement to retrieve the names of all students whose grade is above 80.
问题:表 Students 包含列 StudentID、Name 和 Grade。编写 SQL 语句,检索成绩大于 80 的所有学生姓名。
The required query uses the SELECT and WHERE clauses to filter rows based on a condition.
所需查询使用 SELECT 和 WHERE 子句根据条件过滤行。
SELECT Name FROM Students WHERE Grade > 80;
This returns only the Name column for those records. You could also use SELECT * to retrieve all columns, but the question explicitly asks for names.
这将仅返回满足条件的记录的 Name 列。你也可以使用 SELECT * 检索所有列,但题目明确要求获取姓名。
7. Regular Expressions | 正则表达式
Question: Write a regular expression to match UK vehicle registration plates in the format ‘AB51 CDE’ (two letters, two digits, a space, three letters).
问题:编写一个正则表达式,匹配英国车牌格式 ‘AB51 CDE’(两个字母、两个数字、一个空格、三个字母)。
The pattern must enforce exactly two uppercase letters, followed by two digits, a literal space, and finally three uppercase letters.
该模式必须强制匹配两个大写字母,接着两个数字,一个空格,最后三个大写字母。
^[A-Z]{2}[0-9]{2} [A-Z]{3}$
Here, ^ and $ anchor the start and end of the string, [A-Z] matches any uppercase letter, {2} specifies exactly two, [0-9]{2} matches two digits, and the space is literal. This is typical of finite automata and pattern recognition topics in OCR.
其中 ^ 和 $ 分别锚定字符串起始和结尾,[A-Z] 匹配任意大写字母,{2} 指定恰好两个,[0-9]{2} 匹配两个数字,空格表示字面空格。这是 OCR 中有限自动机和模式识别主题的典型内容。
8. Object-Oriented Programming: Inheritance | 面向对象编程:继承
Question: Given a base class Animal with a method speak() that returns “Animal sound”, and a subclass Dog that overrides speak() to return “Bark”. What is the output of the following pseudocode?
Animal a = new Animal(); Dog d = new Dog(); Animal ref = d; print a.speak(); print d.speak(); print ref.speak();
问题:给定基类 Animal,其方法 speak() 返回 “Animal sound”,子类 Dog 重写 speak() 返回 “Bark”。下列伪代码输出是什么?
Animal a = new Animal(); Dog d = new Dog(); Animal ref = d; print a.speak(); print d.speak(); print ref.speak();
a.speak() calls the Animal version, printing “Animal sound”. d.speak() calls the overridden Dog version, printing “Bark”. ref is declared as Animal but refers to a Dog object, so dynamic dispatch invokes Dog’s speak(), printing “Bark”.
a.speak() 调用 Animal 版本,输出 “Animal sound”。d.speak() 调用重写的 Dog 版本,输出 “Bark”。ref 声明为 Animal 类型但引用的是 Dog 对象,因此动态分派会调用 Dog 的 speak(),输出 “Bark”。
This demonstrates polymorphism, a key OOP concept examined in OCR A-Level.
这展示了多态性,是 OCR A-Level 考查的 OOP 关键概念。
9. Big O Notation and Algorithm Analysis | 大 O 表示法与算法分析
Question: Determine the time complexity in Big O notation for the following nested loop:
问题:确定以下嵌套循环的大 O 时间复杂度:
for i in range(n):
for j in range(i, n):
print(i, j)
The outer loop runs n times. For each i, the inner loop runs (n – i) times. The total number of iterations is the sum from i=0 to n-1 of (n-i) = n + (n-1) + … + 1 = n(n+1)/2.
外层循环运行 n 次。对于每个 i,内层循环运行 (n – i) 次。总迭代次数为从 i=0 到 n-1 的 (n-i) 之和 = n + (n-1) + … + 1 = n(n+1)/2。
T(n) = n(n+1)/2 ∈ O(n²)
Because the dominant term is n², we drop constants and lower-order terms, giving O(n²). Quadratic complexity is often seen in sorting algorithms like bubble and selection sort.
由于主导项为 n²,我们舍弃常数和低阶项,得到 O(n²)。平方复杂度常见于冒泡排序和选择排序等算法。
10. Recursion: Factorial Calculation | 递归:阶乘计算
Question: Trace the recursive algorithm for factorial(4), defined as: factorial(n) = 1 if n = 0 else n * factorial(n – 1). Show the call stack and returned values.
问题:跟踪递归算法计算 factorial(4),定义:factorial(n) = 1 当 n = 0,否则 n * factorial(n – 1)。展示调用栈及返回值。
Call factorial(4) → 4 * factorial(3); factorial(3) → 3 * factorial(2); factorial(2) → 2 * factorial(1); factorial(1) → 1 * factorial(0); factorial(0) → returns 1 (base case).
调用 factorial(4) → 4 * factorial(3);factorial(3) → 3 * factorial(2);factorial(2) → 2 * factorial(1);factorial(1) → 1 * factorial(0);factorial(0) → 返回 1(基础情况)。
Unwinding the stack: factorial(1) = 1*1 = 1; factorial(2) = 2*1 = 2; factorial(3) = 3*2 = 6; factorial(4) = 4*6 = 24.
回卷栈:factorial(1) = 1×1 = 1;factorial(2) = 2×1 = 2;factorial(3) = 3×2 = 6;factorial(4) = 4×6 = 24。
factorial(4) = 24
Recursion requires a base case to prevent infinite calls; this example illustrates the call stack management crucial for OCR’s computational thinking topics.
递归需要有基础情况以防止无限调用;本例说明了调用栈管理,这对 OCR 计算思维主题至关重要。
11. Caesar Cipher Encryption | 凯撒密码加密
Question: Encrypt the plaintext “HELLO” using a Caesar cipher with a shift of 3. Provide the ciphertext.
问题:使用移位为 3 的凯撒密码加密明文 “HELLO”,给出密文。
Shift each letter forward by 3 positions in the alphabet (wrapping around from Z to A). H → K, E → H, L → O, L → O, O → R.
将每个字母在字母表中向前移动 3 个位置(Z 之后循环回 A)。H → K,E → H,L → O,L → O,O → R。
Ciphertext: KHOOR
Caesar cipher is a symmetric substitution cipher. Although trivial to break today, it is a foundation for understanding cryptography concepts and modular arithmetic in OCR.
凯撒密码是对称替换密码。尽管在今天极易破解,但它是理解 OCR 中密码学概念和模运算的基础。
12. Subnetting and IP Addressing | 子网划分与IP寻址
Question: Given the network address 192.168.1.0/26, determine the subnet mask and the number of usable host addresses.
问题:给定网络地址 192.168.1.0/26,确定子网掩码和可用主机地址数量。
The /26 CIDR notation means the first 26 bits are the network portion. The subnet mask in dotted decimal is 255.255.255.192 (because 26 bits of ones: 11111111.11111111.11111111.11000000).
/26 的 CIDR 表示法意味着前 26 位是网络部分。点分十进制子网掩码为 255.255.255.192(因为 26 位为 1:11111111.11111111.11111111.11000000)。
With 6 host bits (32 – 26 = 6), total possible addresses = 2⁶ = 64. Subtract 2 for the network and broadcast addresses, leaving 62 usable hosts.
主机位为 6 位(32 – 26 = 6),总地址数 = 2⁶ = 64。减去网络地址和广播地址,剩余 62 个可用主机地址。
Usable hosts = 62
Subnetting is a core networking skill examined in the OCR specification, alongside the architecture of the Internet and TCP/IP.
子网划分是 OCR 考纲中的核心网络技能,常与互联网架构和 TCP/IP 一起考查。
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课程辅导,国外大学本科硕士研究生博士课程论文辅导