📚 Edexcel A-Level Programming: Paradigms, Data Structures and Algorithms | Edexcel A-Level 编程:范式、数据结构与算法
Programming is at the heart of the Edexcel A-Level Computer Science specification. This article consolidates the essential concepts you need to master: paradigms, data types, control flow, data structures, recursion, searching, sorting, complexity analysis, file handling, testing, object-oriented principles, and exam technique.
编程是 Edexcel A-Level 计算机科学课程的核心。本文整合你需要掌握的关键概念:编程范式、数据类型、控制流、数据结构、递归、查找、排序、复杂度分析、文件处理、测试、面向对象原则以及考试技巧。
1. Programming Paradigms: Procedural and Object-Oriented | 编程范式:过程式与面向对象
Edexcel requires you to compare procedural and object-oriented programming. Procedural programming organises code into procedures or subroutines that operate on data passed as parameters. It is straightforward, but large systems can become difficult to maintain. Object-oriented programming (OOP) bundles data and the methods that act on that data into classes and objects, supporting encapsulation, inheritance and polymorphism.
Edexcel 要求比较过程式编程与面向对象编程。过程式编程将代码组织为过程或子程序,通过参数传递数据并操作数据。它简单直接,但大型系统可能难以维护。面向对象编程(OOP)将数据和操作数据的方法封装在类和对象中,支持封装、继承和多态。
Edexcel paper questions often ask you to identify a paradigm from a code snippet or to justify a choice. Many exam scenarios involve a bank account, a library system or a game character; OOP is often preferred when entities have state and behaviour, while procedural style suits simple calculations or scripts.
Edexcel 考题常要求从代码片段识别范式或证明某一选择合理。许多考试情境涉及银行账户、图书馆系统或游戏角色;当实体同时具有状态和行为时,通常优先选择 OOP,而过程式风格适合简单计算或脚本。
When writing pseudocode, you must be consistent. If you choose OOP, use classes, constructors and method calls; if you choose procedural, use subroutines and parameter passing explicitly.
在编写伪代码时,你必须保持一致。如果你选择 OOP,使用类、构造函数和方法调用;如果选择过程式风格,明确使用子程序和参数传递。
2. Data Types, Variables and Constants | 数据类型、变量与常量
A variable is a named storage location whose value can change during execution; a constant is fixed at compile time or run time. Edexcel expects you to know integer, real/float, Boolean, character and string types, and to choose suitable types for given data.
变量是命名的存储位置,其值在执行期间可以改变;常量在编译时或运行时固定不变。Edexcel 要求你了解整型、实型/浮点型、布尔型、字符型和字符串类型,并能根据给定数据选择合适的类型。
Type mismatches and casting are common pitfalls. For example, dividing two integers in some languages performs integer division and truncates the result; you may need to cast to real before division to keep the fractional part. In pseudocode, use keywords such as INTEGER, REAL, BOOLEAN, CHAR and STRING.
类型不匹配和类型转换是常见错误。例如,在有些语言中两个整数相除会执行整除并截断结果;你可能需要在除法前转换为实型以保留小数部分。在伪代码中,使用 INTEGER、REAL、BOOLEAN、CHAR 和 STRING 等关键字。
| Data Type | 中文 | Example |
|---|---|---|
| INTEGER | 整型 | 42, -7 |
| REAL / FLOAT | 实型/浮点 | 3.14, -0.5 |
| BOOLEAN | 布尔型 | TRUE, FALSE |
| CHAR | 字符型 | 'A', '9' |
| STRING | 字符串 | "Hello" |
Always declare variables at the start of a pseudocode block in Edexcel style. This helps the examiner see that you understand type assignment and scope.
在 Edexcel 风格的伪代码块开始时始终声明变量。这有助于考官看到你理解类型赋值和作用域。
3. Control Structures: Sequence, Selection, Iteration | 控制结构:顺序、选择与迭代
All algorithms are built from three control structures: sequence (executing statements in order), selection (IF, ELSE, CASE) and iteration (FOR, WHILE, REPEAT/DO-WHILE). You must be able to trace pseudocode that combines these structures.
所有算法都由三种控制结构构建:顺序(按顺序执行语句)、选择(IF、ELSE、CASE)和迭代(FOR、WHILE、REPEAT/DO-WHILE)。你必须能够跟踪结合这些结构的伪代码。
Edexcel pseudocode uses common keywords such as IF...THEN...ELSE...ENDIF, FOR...TO...NEXT, WHILE...DO...ENDWHILE. Be careful with boundary conditions: a FOR loop with inclusive end and a WHILE loop that may never execute if the condition is initially false.
Edexcel 伪代码使用常见关键字,如 IF...THEN...ELSE...ENDIF、FOR...TO...NEXT、WHILE...DO...ENDWHILE。注意边界条件:包含结束值的 FOR 循环与条件初始为假时可能一次都不执行的 WHILE 循环。
For selection, CASE is useful when a variable can have multiple discrete values. For iteration, choose FOR when the number of repetitions is known; choose WHILE or REPEAT when termination depends on a condition.
对于选择结构,当变量可以有多个离散值时,CASE 非常有用。对于迭代,当重复次数已知时选择 FOR;当终止依赖于某个条件时选择 WHILE 或 REPEAT。
4. Data Structures: Arrays, Lists, Stacks and Queues | 数据结构:数组、列表、栈与队列
Arrays store elements of the same type in contiguous memory, accessed by index. Lists are dynamic structures that allow insertion and deletion. Stacks follow LIFO (last-in, first-out), while queues follow FIFO (first-in, first-out).
数组将相同类型的元素存储在连续内存中,通过下标访问。列表是允许插入和删除的动态结构。栈遵循后进先出(LIFO),队列遵循先进先出(FIFO)。
You must know standard operations: push and pop for stacks; enqueue and dequeue for queues. Exam questions often ask you to simulate a stack or queue after a sequence of operations, so practise drawing step-by-step diagrams.
你必须了解标准操作:栈的入栈 push 和出栈 pop;队列的入队 enqueue 和出队 dequeue。考试题常要求模拟一系列操作后的栈或队列,因此练习逐步画图。
| Operation | Stack (LIFO) | Queue (FIFO) |
|---|---|---|
| Add | push | enqueue |
| Remove | pop | dequeue |
| Access | top only | front and rear |
Understanding these structures is essential for topics such as recursion call stacks and breadth-first search using a queue.
理解这些结构对于递归调用栈和使用队列的广度优先搜索等主题至关重要。
5. Records, Hash Tables and Trees | 记录、哈希表与树
A record combines fields of different types into one entity, such as a Student record with name, age and grade. Hash tables provide average O(1) lookup by applying a hash function to a key; collisions are handled by chaining or open addressing.
记录将不同类型的字段组合成一个实体,例如包含姓名、年龄和成绩的学生记录。哈希表通过对键应用哈希函数提供平均 O(1) 的查找;冲突通过链表法或开放寻址法处理。
Trees, especially binary search trees (BST), store data hierarchically. In a BST, the left child is smaller and the right child is larger than its parent. In-order traversal visits nodes in ascending order.
树,特别是二叉搜索树(BST),以层次方式存储数据。在 BST 中,左子节点小于父节点,右子节点大于父节点。中序遍历按升序访问节点。
A common exam task is to insert values into an empty BST and then state the result of pre-order, in-order or post-order traversal. Practise drawing each insertion step by step.
常见的考试任务是向空 BST 中插入值,然后说明前序、中序或后序遍历的结果。练习逐步画出每次插入过程。
6. Recursion and Iteration | 递归与迭代
Recursion is a technique where a subroutine calls itself with a smaller input until a base case is reached. Every recursive algorithm can be converted to iteration, though the recursive version may be clearer for problems like tree traversal and factorial.
递归是一种子程序用更小的输入调用自身直到达到基本情况的技术。每个递归算法都可以转换为迭代,但递归版本对于树遍历和阶乘等问题可能更清晰。
To avoid infinite recursion, you must define a base case and ensure each recursive call moves closer to it. Edexcel questions may ask you to trace recursive functions such as Fibonacci or binary search.
为了避免无限递归,必须定义基本情况,并确保每次递归调用都向基本情况靠近。Edexcel 题目可能要求跟踪斐波那契或二分查找等递归函数。
The call stack is used to manage recursive calls; each call creates a new stack frame. This explains why recursion can use more memory than iteration but often provides clearer code.
调用栈用于管理递归调用;每次调用创建一个新的栈帧。这就解释了为什么递归比迭代使用更多内存,但通常代码更清晰。
7. Searching Algorithms: Linear and Binary Search | 查找算法:线性查找与二分查找
Linear search checks each element sequentially until the target is found or the end is reached. It works on unsorted data and has O(n) time complexity. Binary search divides a sorted list in half repeatedly; it has O(log n) complexity but requires sorted data.
线性查找按顺序检查每个元素,直到找到目标或到达末尾。它适用于未排序数据,时间复杂度为 O(n)。二分查找反复将有序列表二分;时间复杂度为 O(log n),但要求数据有序。
A common exam question asks you to state or trace the number of comparisons. Remember that binary search uses the midpoint index, often (low + high) DIV 2, and updates low or high after each comparison.
常见考题要求说明或跟踪比较次数。记住二分查找使用中间下标,通常为 (low + high) DIV 2,并在每次比较后更新 low 或 high。
For example, searching for 7 in [2, 5, 7, 9, 12] compares 7 with the middle element 7 and finds it in one step. If the target is 12, comparisons are with 7 then 9 then 12.
例如,在 [
Published by TutorHao | A-Level 编程 Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图