Typical Example Problem Walkthroughs in A-Level Edexcel Computer Science | A-Level Edexcel 计算机:典型例题详解

📚 Typical Example Problem Walkthroughs in A-Level Edexcel Computer Science | A-Level Edexcel 计算机:典型例题详解

Mastering the Edexcel A-Level Computer Science specification demands more than just theoretical knowledge — it calls for deliberate practice with structured problem-solving. This article presents a curated collection of typical exam-style questions, each broken down into clear, step-by-step solutions. By working through these examples, you will reinforce core concepts in binary arithmetic, logic design, data structures, algorithm analysis, Boolean algebra, assembly programming, object-oriented fundamentals, database normalisation, finite state machines, networking and SQL. Every walkthrough follows a paired approach: an English explanation immediately followed by its Chinese counterpart, making the revision process both accessible and thorough.

掌握 Edexcel A-Level 计算机科学大纲不仅需要理论知识,更需要通过结构化的问题求解来刻意练习。本文精选了一组典型真题风格的例题,每题都分解为清晰的逐步解答。通过练习这些例子,你将巩固二进制运算、逻辑设计、数据结构、算法分析、布尔代数、汇编编程、面向对象基础、数据库规范化、有限状态机、网络和 SQL 等核心概念。每道题的讲解都采用中英配对的形式:英文解释紧跟着中文说明,使复习过程既通俗又透彻。


1. Binary Arithmetic & Two’s Complement | 二进制算术与补码

Example: Using 8-bit two’s complement, add the binary numbers 01101010 and 00101101. Indicate whether an overflow occurs and justify your answer.

例题:使用8位补码计算二进制数 01101010 和 00101101 的和。判断是否发生溢出并说明理由。

Step 1: Write the two binary numbers aligned by their least significant bits. Both numbers are positive because the most significant bit (MSB) is 0.

步骤1:将两个二进制数按最低位对齐写出。两个数都为正数,因为最高有效位 (MSB) 均为0。

Step 2: Perform binary addition column by column from right to left, carrying values when the sum exceeds 1.

步骤2:从右向左逐列进行二进制加法,当某列和超过1时产生进位。

Step 3: 01101010 + 00101101 = 10010111. The result has an MSB of 1, which in two’s complement indicates a negative number.

步骤3:01101010 + 00101101 = 10010111。结果的 MSB 为1,在补码中表示一个负数。

Step 4: Identify overflow. Overflow occurs when adding two numbers with the same sign yields a result with a different sign. Here, both operands are positive (MSB 0) and the sum has MSB 1, so an overflow has occurred. In 8-bit two’s complement, the valid range is -128 to 127; 106 + 45 = 151, which exceeds 127, confirming overflow.

步骤4:识别溢出。当两个同符号数相加得到异号结果时便发生溢出。此处两个操作数均为正(MSB 0),而和的 MSB 为1,因此发生了溢出。在8位补码中,有效范围为 -128 至 127;106 + 45 = 151 超出了127,证实溢出。


2. Logic Gates and Truth Tables | 逻辑门与真值表

Example: A logic circuit is described by the Boolean expression Q = (A AND B) OR (NOT C). Draw a truth table for all combinations of inputs A, B, C and sketch the corresponding logic gate diagram.

例题:某逻辑电路由布尔表达式 Q = (A AND B) OR (NOT C) 描述。为输入 A、B、C 的所有组合绘制真值表,并画出对应的逻辑门电路图。

Step 1: List all input combinations. There are 2³ = 8 rows for inputs A, B, C (0 or 1).

步骤1:列出所有输入组合。输入 A、B、C 有 2³ = 8 种组合(0 或 1)。

Step 2: Evaluate the sub-expression A AND B for each row. Then compute NOT C. Finally apply the OR operation.

步骤2:对每一行计算子表达式 A AND B,再计算 NOT C,最后进行 OR 运算。

Step 3: Build the truth table. For example, when A=0, B=0, C=0: NOT C = 1, (A AND B)=0, so Q=1. Continue for all rows.

步骤3:构建真值表。例如当 A=0, B=0, C=0 时:NOT C=1,(A AND B)=0,因此 Q=1。依此类推完成所有行。

Step 4: The logic diagram consists of one AND gate receiving A and B, one NOT gate receiving C, and one OR gate combining the outputs of the AND and NOT gates.

步骤4:电路图由一个与门(输入 A 和 B)、一个非门(输入 C)以及一个或门(连接与门和非门的输出)组成。


3. Data Structures – Stacks and Queues | 数据结构——栈与队列

Example: An empty stack undergoes the following operations: push 5, push 8, pop, push 2, push 1, pop, pop. Show the contents of the stack after each operation, clearly indicating the top pointer.

例题:对一个空栈依次执行以下操作:push 5,push 8,pop,push 2,push 1,pop,pop。画出每次操作后栈的内容,并标明栈顶指针。

Step 1: Initially stack = [ ], top = -1. Push 5: stack becomes [5] with top at index 0.

步骤1:初始栈为空 [ ],栈顶指针 top = -1。Push 5:栈变为 [5],top = 0。

Step 2: Push 8: stack = [5, 8], top = 1.

步骤2:Push 8:栈变为 [5, 8],top = 1。

Step 3: Pop removes the top element (8). Stack returns to [5] and top = 0.

步骤3:Pop 移除栈顶元素 8。栈变回 [5],top = 0。

Step 4: Push 2 → [5, 2], top=1; push 1 → [5, 2, 1], top=2.

步骤4:Push 2 → [5, 2],top=1;push 1 → [5, 2, 1],top=2。

Step 5: Pop removes 1 → [5, 2], top=1; pop removes 2 → [5], top=0. Final stack contains only 5.

步骤5:Pop 移除 1 → [5, 2],top=1;pop 移除 2 → [5],top=0。最终栈中仅剩 5。


4. Tree Traversal Algorithms | 树的遍历算法

Example: Consider the following binary tree (root A; A’s left child B, right child C; B’s left child D, right child E; C’s left child F, right child absent). List the order of nodes visited using preorder, inorder, and postorder traversals.

例题:给定二叉树(根节点 A;A 的左子 B,右子 C;B 的左子 D,右子 E;C 的左子 F,右子为空)。分别列出前序、中序和后序遍历访问节点的顺序。

Step 1: Preorder (root, left, right): Start at A, then traverse left subtree (B, D, E), then right subtree (C, F). Result: A, B, D, E, C, F.

步骤1:前序遍历(根-左-右):从 A 开始,然后遍历左子树 (B, D, E),最后右子树 (C, F)。结果:A, B, D, E, C, F。

Step 2: Inorder (left, root, right): Traverse left subtree first (D, B, E), visit root A, then right subtree (F, C). Result: D, B, E, A, F, C.

步骤2:中序遍历(左-根-右):先遍历左子树 (D, B, E),访问根 A,再遍历右子树 (F, C)。结果:D, B, E, A, F, C。

Step 3: Postorder (left, right, root): Traverse left subtree (D, E, B), then right subtree (F, C), finally root A. Result: D, E, B, F, C, A.

步骤3:后序遍历(左-右-根):先左子树 (D, E, B),后右子树 (F, C),最后根 A。结果:D, E, B, F, C, A。


5. Sorting and Searching Algorithms | 排序与搜索算法

Example: Apply the bubble sort algorithm to the list [7, 3, 9, 2, 6] and show the list after each pass. Then, perform a binary search for the value 7 on the sorted list.

例题:对列表 [7, 3, 9, 2, 6] 应用冒泡排序算法,展示每趟排序后的列表。然后,在已排序列表上对数值 7 进行二分查找。

Step 1: First pass (compare adjacent items): 7>3 swap → [3,7,9,2,6]; 7<9 no swap; 9>2 swap → [3,7,2,9,6]; 9>6 swap → [3,7,2,6,9]. Largest element 9 is in place.

步骤1:第一趟(比较相邻元素):7>3 交换 → [3,7,9,2,6];7<9 不交换;9>2 交换 → [3,7,2,9,6];9>6 交换 → [3,7,2,6,9]。最大元素 9 已就位。

Step 2: Second pass: [3,7,2,6,9] → 3<7 no swap; 7>2 swap → [3,2,7,6,9]; 7>6 swap → [3,2,6,7,9]. 7 and 9 are sorted.

步骤2:第二趟:[3,7,2,6,9] → 3<7 不交换;7>2 交换 → [3,2,7,6,9];7>6 交换 → [3,2,6,7,9]。7 和 9 排好。

Step 3: Third pass: [3,2,6,7,9] → 3>2 swap → [2,3,6,7,9]. Now sorted. Binary search on [2,3,6,7,9] for 7: low=0, high=4, mid=2 (value 6). 7>6 so low=mid+1=3. New mid=3 (value 7) — found at index 3.

步骤3:第三趟:[3,2,6,7,9] → 3>2 交换 → [2,3,6,7,9]。完成排序。对 [2,3,6,7,9] 二分查找 7:low=0, high=4, mid=2 (值6)。7>6 故 low=3。新 mid=3 (值7) — 在索引3处找到。


6. Boolean Algebra Simplification | 布尔代数化简

Example: Simplify the Boolean expression F = A·B + A·B·C + A·B·C·D using the laws of Boolean algebra. State which law is applied in each step.

例题:使用布尔代数定律化简表达式 F = A·B + A·B·C + A·B·C·D。每一步写明所用定律。

Step 1: Factor A·B from the first two terms: F = A·B·(1 + C) + A·B·C·D. Using the identity 1 + C = 1, this reduces to F = A·B + A·B·C·D.

步骤1:从前两项提取公因子 A·B:F = A·B·(1 + C) + A·B·C·D。利用恒等式 1 + C = 1,化简为 F = A·B + A·B·C·D。

Step 2: Factor A·B again: F = A·B·(1 + C·D). Since 1 + anything = 1, we obtain F = A·B.

步骤2:再次提取 A·B:F = A·B·(1 + C·D)。由于 1+任意项=1,得到 F = A·B。

Step 3: The simplified expression is simply A AND B. The terms involving C and D are redundant and have been eliminated using the absorption/identity laws.

步骤3:简化后的表达式仅为 A AND B。包含 C 和 D 的项是冗余的,已通过吸收律/恒等律消去。


7. Assembly Language and Little Man Computer (LMC) | 汇编语言与小矮人计算机

Example: Write an LMC assembly program that takes two numbers as input, adds them, and outputs the result. Assume the instruction set: 1xx ADD, 2xx SUB, 3xx STA, 5xx LDA, 6xx BRA, 7xx BRZ, 8xx BRP, 901 INP, 902 OUT, 000 HLT.

例题:编写一个 LMC 汇编程序,接受两个数字作为输入,将它们相加并输出结果。指令集:1xx ADD,2xx SUB,3xx STA,5xx LDA,6xx BRA,7xx BRZ,8xx BRP,901 INP,902 OUT,000 HLT。

Step 1: Reserve a memory location for the first input. Use INP (901) to read the first number and STA (3xx) to store it in, say, address 99.

步骤1:为第一个输入保留一个内存单元。用 INP (901) 读取第一个数,并用 STA (3xx) 存入地址 99(假设)。

Step 2: Read the second number with INP (901) again. Now the accumulator holds the second input. Add the stored first number using ADD 199 (since 1xx is ADD and address 99).

步骤2:再次用 INP (901) 读第二个数。此时累加器中是第二个输入。用 ADD 199(1xx 为加法,地址99)加上已存储的第一个数。

Step 3: Output the result with OUT (902) and halt (000). The complete program: 901 (INP), 399 (STA first), 901 (INP), 199 (ADD first), 902 (OUT), 000 (HLT).

步骤3:用 OUT (902) 输出结果并停机 (000)。完整程序:901 (INP),399 (STA 存入地址99),901 (INP),199 (ADD 地址99),902 (OUT),000 (HLT)。


8. Object-Oriented Programming Concepts | 面向对象编程概念

Example: Define a class ‘Dog’ with private attributes ‘name’ (String) and ‘age’ (int) and a public method ‘bark()’ that returns a string. Then create a subclass ‘Puppy’ that inherits from Dog and overrides bark() to return ‘Woof woof (playful)’. Represent the relationship using a simple UML class diagram description.

例题:定义类 ‘Dog’,包含私有属性 ‘name’(字符串)和 ‘age’(整数),以及公有方法 ‘bark()’ 返回一个字符串。然后创建一个子类 ‘Puppy’,继承自 Dog 并重写 bark() 方法,使之返回 ‘Woof woof (playful)’。用简单的 UML 类图描述表示两者关系。

Step 1: Class Dog – attributes: -name: String, -age: int; methods: +bark(): String, +constructor Dog(n, a). The bark() method returns ‘Woof!’.

步骤1:Dog 类 – 属性:-name: String,-age: int;方法:+bark(): String,+构造器 Dog(n, a)。bark() 方法返回 ‘Woof!’。

Step 2: Class Puppy extends Dog – it inherits all attributes and methods. Override bark() to return ‘Woof woof (playful)’. The UML arrow is an inheritance arrow (empty triangle) from Puppy to Dog.

步骤2:Puppy 类继承 Dog – 它继承了所有属性和方法。重写 bark() 返回 ‘Woof woof (playful)’。UML 中有一条从 Puppy 指向 Dog 的继承箭头(空心三角)。

Step 3: An object of type Puppy can be instantiated: Puppy p = new Puppy(‘Buddy’, 1); p.bark() would output the overridden string. This demonstrates polymorphism where a subclass provides a specific implementation of a method defined in the superclass.

步骤3:可以实例化 Puppy 类型的对象:Puppy p = new Puppy(‘Buddy’, 1); p.bark() 输出重写后的字符串。这体现了多态性——子类提供了父类方法的具体实现。


9. Database Normalisation (1NF, 2NF, 3NF) | 数据库规范化

Example: An unnormalised table ‘Enrolment’ contains: StudentID, StudentName, CourseID, CourseName, Tutor. A student can enroll in multiple courses, and each course has one tutor. Normalise this table to third normal form (3NF). Show the resulting tables with primary keys underlined.

例题:未规范化的表 ‘Enrolment’ 包含:学生ID、学生姓名、课程ID、课程名称、指导教师。一个学生可选修多门课程,每门课程有一位指导教师。将该表规范化为第三范式 (3NF)。展示结果表,用下划线标出主键。

Step 1: Identify repeating groups. The primary key would be a composite of StudentID and CourseID. StudentName depends only on StudentID (partial dependency), while CourseName and Tutor depend only on CourseID. This violates 2NF.

步骤1:识别重复组。主键应为 学生ID 和 课程ID 的组合。学生姓名仅依赖于学生ID(部分依赖),而课程名称和指导教师仅依赖于课程ID。这违反了 2NF。

Step 2: Remove partial dependencies by splitting into two tables: Student(StudentID, StudentName) and Course(CourseID, CourseName, Tutor). The original table becomes Enrol(StudentID, CourseID) linking students to courses.

步骤2:通过拆分成两个表消除部分依赖:Student(学生ID, 学生姓名) 和 Course(课程ID, 课程名称, 指导教师)。原表变为 Enrol(学生ID, 课程ID) 关联学生与课程。

Step 3: Check for transitive dependencies in Course. If Tutor depends only on CourseID, it is fine. Suppose we add TutorOffice that depends on Tutor – that would need further normalisation. For this example, no transitive dependency exists; the tables are in 3NF. Primary keys: StudentID in Student, CourseID in Course, composite (StudentID, CourseID) in Enrol.

步骤3:检查 Course 表中是否存在传递依赖。假设 Tutor 仅依赖于 CourseID,则无问题。若增加了依赖于 Tutor 的 TutorOffice,则需要进一步规范化。就本例而言,不存在传递依赖;表已达到 3NF。主键:Student 表的 学生ID,Course 表的 课程ID,Enrol 表的复合键 (学生ID, 课程ID)。


10. Finite State Machines (FSMs) | 有限状态机

Example: Design a Moore FSM that detects any binary string ending with ‘101’. The output should be 1 only after the sequence ‘101’ has been received, and 0 otherwise. Draw the state transition diagram and explain the states.

例题:设计一个摩尔型有限状态机,用于检测任何以 ‘101’ 结尾的二进制串。仅当收到序列 ‘101’ 后输出为 1,否则为 0。画出状态转换图并解释各个状态。

Step 1: Identify the states based on how much of the target sequence has been matched. Define S0 (no match, start), S1 (matched ‘1’), S2 (matched ’10’), S3 (matched ‘101’ — output 1).

步骤1:根据已匹配到目标序列的长度确定状态。定义 S0(无匹配,初始态),S1(匹配到 ‘1’),S2(匹配到 ’10’),S3(匹配到 ‘101’ — 输出1)。

Step 2: State transitions: From S0, on input 1 go to S1; on 0 stay at S0. From S1, on 0 go to S2; on 1 stay at S1 (overlapping matches allowed). From S2, on 1 go to S3; on 0 go back to S0. From S3, on 1 go to S1 (since new ‘1’ could start another match); on 0 go to S0. S3 output is 1; all others output 0.

步骤2:状态转移:从 S0,输入1到 S1;输入0保持在 S0。从 S1,输入0到 S2;输入1保持在 S1(支持重叠匹配)。从 S2,输入1到 S3;输入0回到 S0。从 S3,输入1到 S1(因为新的 ‘1’ 可能开启另一个匹配);输入0回到 S0。仅 S3 输出1,其他输出0。

Step 3: The Moore output depends solely on the state. The diagram shows directed edges labelled with the input that causes the transition.

步骤3:摩尔型输出仅取决于状态。图示为带箭头的有向边,边上标有触发转移的输入。


11. Networking – Subnet Mask Calculations | 网络——子网掩码计算

Example: Given the IP address 192.168.1.135 with subnet mask 255.255.255.224 (or /27), calculate the network address, broadcast address, and the number of usable host addresses in this subnet.

例题:给定 IP 地址 192.168.1.135 和子网掩码 255.255.255.224(即 /27),计算该子网的网络地址、广播地址以及可用主机地址数。

Step 1: Convert the IP and mask to binary. 192.168.1.135 = 11000000.10101000.00000001.10000111. Mask /27 = 11111111.11111111.11111111.11100000. The subnet mask leaves 5 bits for hosts.

步骤1:将 IP 地址和掩码转换为二进制。192.168.1.135 = 11000000.10101000.00000001.10000111。掩码 /27 = 11111111.11111111.11111111.11100000。子网掩码留出 5 位给主机。

Step 2: Network address is the bitwise AND of IP and mask. 10000111 AND 11100000 = 10000000, so the last octet is 128. Network address = 192.168.1.128.

步骤2:网络地址 = IP 与掩码的按位与。10000111 AND 11100000 = 10000000,故最后一个八位字节为 128。网络地址 = 192.168.1.128。

Step 3: Broadcast address sets all host bits to 1 within the subnet. Host bits are the last 5 bits. 128 in binary is 10000000; set host bits to 1 gives 10011111 = 159. Broadcast address = 192.168.1.159. Usable host range: 129 to 158, giving 2⁵ – 2 = 30 usable addresses.

步骤3:广播地址将子网内所有主机位置为1。主机位为最后 5 位。128 的二进制为 10000000,主机位置1得 10011111 = 159。广播地址 = 192.168.1.159。可用主机范围:129 至 158,共 2⁵ – 2 = 30 个可用地址。


12. SQL Queries | SQL 查询

Example: Consider the following database schema: Student(StuID, Name, Age), Course(CID, Title), Enrol(StuID, CID, Grade). Write an SQL statement to retrieve the names of all students who are enrolled in the course titled ‘Computer Science’, sorted alphabetically.

例题:给定以下数据库模式:Student(StuID, Name, Age),Course(CID, Title),Enrol(StuID, CID, Grade)。编写一条 SQL 语句,查询所有选修了 ‘Computer Science’ 课程的学生姓名,并按字母顺序排序。

Step 1: Recognise that the query requires joining the three tables. Enrol links Student and Course via foreign keys StuID and CID.

Published by TutorHao | A-Level 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