Tag: 编程

  • Coding for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学:编程核心精讲

    📚 Coding for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学:编程核心精讲

    Coding is the practical engine of computer science. In the Edexcel A-Level specification, coding skills are tested through problem solving, algorithm design, pseudocode interpretation and hands-on programming tasks. This article covers the core concepts you need to master, from variables and control flow to recursion and algorithm efficiency.

    编程是计算机科学的实践引擎。在 Edexcel A-Level 大纲中,编程能力通过问题解决、算法设计、伪代码解读和实际编程任务进行考查。本文涵盖你必须掌握的核心概念,从变量、控制流到递归与算法效率。


    1. Computational Thinking and Problem Decomposition | 计算思维与问题分解

    Computational thinking involves breaking down a problem into smaller parts, recognising patterns, abstracting away unnecessary detail and designing step-by-step algorithms. Before writing any code, Edexcel exam papers expect you to identify inputs, outputs, processes and storage requirements.

    计算思维包括将问题分解为更小的部分、识别模式、抽象掉不必要的细节以及设计逐步执行的算法。在编写任何代码之前,Edexcel 试卷要求你确定输入、输出、处理过程和存储需求。

    A good decomposition reduces a complex task into named sub-tasks, each with a clear responsibility. For example, a school attendance system can be split into ‘enter student ID’, ‘check timetable’, ‘record absence’ and ‘generate report’. This modular view maps directly to functions and procedures.

    良好的分解能将复杂任务拆分为命名清晰的子任务,每个子任务职责明确。例如,学校考勤系统可以拆分为“输入学生 ID”“核对课表”“记录缺勤”和“生成报告”。这种模块化视角直接对应函数和过程。


    2. Variables, Data Types and Constants | 变量、数据类型与常量

    Variables are named storage locations whose values can change during program execution. Constants hold fixed values and make code more readable and maintainable. In Edexcel pseudocode, declarations are usually written as INTEGER age, REAL price, STRING name, BOOLEAN valid, CHAR grade and DATE dob.

    变量是命名的存储位置,其值在程序执行期间可以改变。常量保存固定值,使代码更易读、更易维护。在 Edexcel 伪代码中,声明通常写为 INTEGER age、REAL price、STRING name、BOOLEAN valid、CHAR grade 和 DATE dob。

    Choosing the correct data type affects memory use and operations. Integer arithmetic is exact, while real arithmetic may introduce rounding errors. Boolean values are essential for selection and loop conditions. Casting between types, such as STRING_TO_INT, must be handled carefully to avoid runtime errors.

    选择正确的数据类型会影响内存使用和运算。整数运算是精确的,而实数运算可能引入舍入误差。布尔值对于选择结构和循环条件至关重要。类型之间的转换(如 STRING_TO_INT)必须谨慎处理,以免出现运行时错误。

    INT(x) → INTEGER | STRING_TO_REAL(s) → REAL


    3. Operators and Expressions | 运算符与表达式

    Operators build expressions from operands. Arithmetic operators include +, -, *, /, MOD, DIV and ^ for exponentiation. Relational operators such as =, <>, <, <=, >, >= compare values and return Boolean results. Logical operators AND, OR and NOT combine conditions following Boolean algebra.

    运算符将操作数组合成表达式。算术运算符包括 +、-、*、/、MOD、DIV 和 ^ 表示乘方。关系运算符如 =、<>、<、<=、>、>= 用于比较值并返回布尔结果。逻辑运算符 AND、OR 和 NOT 按照布尔代数组合条件。

    Operator precedence matters: brackets are evaluated first, then exponentiation, then multiplication/division, then addition/subtraction. In many pseudocode dialects, DIV returns the integer quotient and MOD returns the remainder. This is useful for problems such as extracting digits from a number.

    运算符优先级很重要:先算括号,再算乘方,然后乘除,最后加减。在许多伪代码方言中,DIV 返回整数商,MOD 返回余数。这对提取数字中的某一位等问题非常有用。

    17 DIV 5 = 3 | 17 MOD 5 = 2


    4. Sequence, Selection and Iteration | 顺序、选择与迭代

    All programs are built from three control structures: sequence, selection and iteration. Sequence means statements execute one after another in order. Selection uses IF…THEN…ELSE or CASE statements to choose between paths. Iteration repeats a block using FOR, WHILE or REPEAT…UNTIL loops.

    所有程序都由三种控制结构构建:顺序、选择和迭代。顺序指语句一条接一条按顺序执行。选择使用 IF…THEN…ELSE 或 CASE 语句在不同路径之间进行选择。迭代使用 FOR、WHILE 或 REPEAT…UNTIL 循环重复执行代码块。

    A FOR loop is count-controlled and runs a known number of times. A WHILE loop is condition-controlled and may run zero times. A REPEAT…UNTIL loop always executes at least once because the condition is tested at the end. Exam questions often ask you to trace loops and identify the final value of a variable.

    FOR 循环是计数控制的,执行已知次数。WHILE 循环是条件控制的,可能一次也不执行。REPEAT…UNTIL 循环因为条件在末尾测试,所以至少执行一次。考试题常要求你追踪循环并确定变量的最终值。


    5. Functions and Procedures | 函数与过程

    A procedure is a named block of code that performs a task but does not return a value. A function performs a task and returns exactly one value. Parameters allow data to be passed in; arguments are the actual values supplied at call time. Edexcel pseudocode often uses PROCEDURE and FUNCTION keywords.

    过程是执行任务但不返回值的命名代码块。函数执行任务并返回一个值。参数允许传入数据;实参是调用时提供的实际值。Edexcel 伪代码通常使用 PROCEDURE 和 FUNCTION 关键字。

    Using functions and procedures improves modularity and reusability. Pass-by-value copies data and leaves the original argument unchanged, while pass-by-reference lets the routine modify the caller’s variable. Questions may ask you to trace parameter passing and local versus global variables.

    使用函数和过程可提高模块化和可重用性。按值传递复制数据,原始实参不变;按引用传递允许例程修改调用者的变量。考试题可能要求你追踪参数传递以及局部变量与全局变量。


    6. Data Structures: Arrays, Lists and Records | 数据结构:数组、列表与记录

    Arrays store multiple items of the same type in contiguous memory and allow indexed access. In Edexcel pseudocode, a 1D array is declared as ARRAY scores[1:10] OF INTEGER; a 2D array as ARRAY grid[1:3,1:4] OF STRING. Indexing starts at 1 in most pseudocode, unlike Python’s 0-based indexing.

    数组在连续内存中存储多个相同类型的元素,并允许通过索引访问。在 Edexcel 伪代码中,一维数组声明为 ARRAY scores[1:10] OF INTEGER;二维数组声明为 ARRAY grid[1:3,1:4] OF STRING。大多数伪代码的索引从 1 开始,与 Python 从 0 开始不同。

    Lists can grow and shrink dynamically, whereas arrays usually have fixed length. Records group related fields of different types under one name, such as TYPE Student = RECORD name: STRING, age: INTEGER, average: REAL ENDRECORD. This is the basis for files and databases.

    列表可以动态增长和收缩,而数组通常长度固定。记录将不同类型的相关字段组合在一个名称下,例如 TYPE Student = RECORD name: STRING, age: INTEGER, average: REAL ENDRECORD。这是文件和数据库的基础。


    7. String Handling and File Operations | 字符串处理与文件操作

    String handling includes concatenation, substring extraction, length, and character access. Common pseudocode functions are LEN(s), LEFT(s,n), RIGHT(s,n), MID(s,start,n), UPPER(s), LOWER(s) and TO_STRING(n). Concatenation uses + or & depending on the dialect.

    字符串处理包括连接、提取子串、求长度和访问字符。常见伪代码函数有 LEN(s)、LEFT(s,n)、RIGHT(s,n)、MID(s,start,n)、UPPER(s)、LOWER(s) 和 TO_STRING(n)。连接使用 + 或 &,取决于具体方言。

    Files allow programs to persist data. Operations include opening a file for read, write or append, reading a line, writing a new line and closing the file. Pseudocode often uses OPENFILE, READFILE, WRITEFILE, CLOSEFILE and tests EOF. Exam questions may require you to process a text file line by line and update totals.

    文件使程序能够持久化数据。操作包括以读、写或追加模式打开文件、读取一行、写入新行以及关闭文件。伪代码通常使用 OPENFILE、READFILE、WRITEFILE、CLOSEFILE 并测试 EOF。考试题可能要求你逐行处理文本文件并更新汇总值。


    8. Debugging, Testing and Validation | 调试、测试与验证

    Debugging is the process of finding and correcting errors. Common error types are syntax errors, runtime errors and logic errors. Syntax errors occur when code breaks the language rules; runtime errors happen during execution, such as division by zero or file not found; logic errors produce incorrect output without crashing.

    调试是发现并纠正错误的过程。常见错误类型有语法错误、运行时错误和逻辑错误。语法错误发生在代码违反语言规则时;运行时错误在执行期间发生,如除以零或文件未找到;逻辑错误产生的输出不正确,但程序不会崩溃。

    Testing should use normal, boundary and erroneous data. Normal data is typical input, boundary data tests the edges of valid ranges, and erroneous data is invalid and should be rejected gracefully. Validation checks data is sensible before processing; verification checks data is entered correctly, for example by double entry.

    测试应使用正常数据、边界数据和错误数据。正常数据是典型输入

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Object-Oriented Programming Essentials for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学面向对象编程核心要点

    📚 Object-Oriented Programming Essentials for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学面向对象编程核心要点

    Object-oriented programming (OOP) is a core part of the Edexcel A-Level Computer Science specification. This article explains the key concepts examiners expect you to use accurately: classes, objects, inheritance, encapsulation, polymorphism and design thinking.

    面向对象编程(OOP)是 Edexcel A-Level 计算机科学课程的核心内容。本文解释了考试要求你准确使用的关键概念:类、对象、继承、封装、多态和设计思维。


    1. Programming Paradigms and the Need for OOP | 编程范式与面向对象编程的必要性

    Edexcel expects you to contrast procedural programming with object-oriented programming. A procedural program organises code into functions that operate on separate data, whereas OOP bundles data and the methods that act on it into objects.

    Edexcel 考试要求你对比面向过程编程与面向对象编程。面向过程程序将代码组织为操作独立数据的函数,而面向对象编程则将数据与操作这些数据的方法捆绑到对象中。

    OOP is useful for large systems because it promotes modularity, code reuse and easier maintenance. Real-world entities such as customers, accounts and orders can be modelled naturally as objects.

    面向对象编程对大型系统非常有用,因为它能促进模块化、代码复用和易于维护。客户、账户和订单等现实世界实体都可以被自然地建模为对象。


    2. Classes and Objects: Defining Blueprints | 类与对象:定义蓝图

    A class is a template or blueprint that defines the attributes and methods shared by a group of objects. An object is a specific instance of a class, created at runtime.

    类是定义一组对象共享的属性和方法的模板或蓝图。对象是类的具体实例,在运行时创建。

    For example, a Student class may define attributes such as name and yearGroup, and methods such as enrol(). Each individual student would then be an object of that class.

    例如,Student 类可以定义 nameyearGroup 等属性,以及 enrol() 等方法。每个具体的学生就是该类的一个对象。

    In exam answers, you must distinguish clearly between the class and the object. Saying ‘an object is a blueprint’ is a common mark-losing error; the class is the blueprint, the object is the instance.

    在考试答案中,你必须清楚区分类和对象。“对象是蓝图”是一种常见的失分错误;类才是蓝图,对象是实例。


    3. Attributes, Methods and Constructors | 属性、方法与构造函数

    Attributes store the state of an object, while methods define its behaviour. A constructor is a special method used to initialise a new object’s attributes when it is instantiated.

    属性存储对象的状态,而方法定义对象的行为。构造函数是一种特殊方法,用于在对象实例化时初始化新对象的属性。

    In Python-style pseudocode, a constructor is written as __init__(self). The self parameter refers to the current object being created or used.

    在 Python 风格伪代码中,构造函数写作 __init__(self)self 参数引用当前正在创建或使用的对象。

    Consider a BankAccount class with a constructor that sets the account number and opening balance. This ensures every new account object starts in a valid state.

    考虑一个 BankAccount 类,其构造函数设置账号和初始余额。这样可确保每个新账户对象都从一个有效状态开始。


    4. Encapsulation and Access Modifiers | 封装与访问修饰符

    Encapsulation means bundling attributes and methods inside a class and controlling access to the internal state. It protects data from accidental or unauthorised change.

    封装意味着将属性和方法捆绑在类内部,并控制对内部状态的访问。它保护数据免受意外或未经授权的更改。

    Access modifiers such as private, public and protected determine visibility. Exam questions often ask why attributes should be private and accessed through public getter and setter methods.

    privatepublicprotected 等访问修饰符决定了可见性。考试题经常问为什么属性应为私有,并通过公共的 getter 和 setter 方法访问。

    Modifier Meaning 中文含义
    private Only accessible within the same class 仅在同一类内可访问
    public Accessible from any class 任何类均可访问
    protected Accessible within the class and its subclasses 类及其子类可访问

    Encapsulation also improves maintainability because the internal implementation can change without affecting code that uses the public interface.

    封装还能提高可维护性,因为内部实现可以改变,而不会影响使用公共接口的代码。


    5. Inheritance: Building Class Hierarchies | 继承:构建类层次结构

    Inheritance allows a new class, called a subclass, to reuse and extend the attributes and methods of an existing class, called a superclass. It represents an ‘is-a’ relationship.

    继承允许新类(称为子类)复用并扩展现有类(称为父类)的属性和方法。它表示一种“is-a”关系。

    For example, a Dog class can inherit from an Animal class. The Dog class automatically has the features of Animal, but can also add a specific bark() method.

    例如,Dog 类可以继承自 Animal 类。Dog 类自动具有 Animal 的特征,也可以添加特定的 bark() 方法。

    Method overriding occurs when a subclass provides its own version of a method defined in the superclass. This is essential for customising behaviour without changing the superclass code.

    当子类提供父类中已定义方法的自身版本时,就发生了方法重写。这对于在不更改父类代码的情况下自定义行为至关重要。


    6. Polymorphism: Overriding and Overloading | 多态:重写与重载

    Polymorphism means ‘many forms’. It allows objects of different classes to respond to the same method call in different ways, provided they share a common interface or superclass.

    多态意为“多种形态”。它允许不同类的对象对同一方法调用作出不同响应,前提是它们共享一个公共接口或父类。

    Method overriding is the key form of polymorphism tested at A-Level. A parent reference can point to a child object, and the appropriate overridden method is selected at runtime.

    方法重写是 A-Level 考试中测试的多态的主要形式。父类引用可以指向子类对象,运行时将选择适当的被重写方法。

    Method overloading is having multiple methods with the same name but different parameter lists. Edexcel may mention it in Java-style contexts, but you should not confuse overloading with overriding.

    方法重载是指具有多个同名但参数列表不同的方法。Edexcel 可能在 Java 风格上下文中提到它,但你不应将重载与重写混淆。


    7. Aggregation and Composition | 聚合与组合

    Aggregation and composition describe ‘has-a’ relationships between objects. They are both forms of association, but they differ in object lifetime dependency.

    聚合和组合描述对象之间的“has-a”关系。它们都是关联的形式,但对象生命周期依赖性不同。

    In aggregation, the contained object can exist independently of the container. A Library object may contain Book objects, but a book can still exist if the library is deleted.

    在聚合中,被包含对象可以独立于容器存在。Library 对象可以包含 Book 对象,但如果图书馆被删除,书仍然可以存在。

    In composition, the contained object cannot exist without the container. For example, a Car has an Engine, and if the car is destroyed, the engine object is also destroyed.

    在组合中,被包含对象不能脱离容器存在。例如,Car 有一个 Engine,如果汽车被销毁,引擎对象也会被销毁。


    8. Abstract Classes and Interfaces | 抽象类与接口

    An abstract class is a class that cannot be instantiated directly. It may contain abstract methods, which have no implementation and must be overridden by concrete subclasses.

    抽象类是不能直接实例化的类。它可以包含抽象方法,抽象方法没有实现,必须由具体子类重写。

    An interface defines a contract of method signatures that implementing classes must provide. Unlike abstract classes, a class can implement multiple interfaces, which supports a form of multiple inheritance.

    接口定义了实现类必须提供的方法签名契约。与抽象类不同,一个类可以实现多个接口,从而支持一种多重继承形式。

    Use abstract classes when classes share common state or code, and use interfaces when unrelated classes must provide the same behaviour.

    当类共享公共状态或代码时使用抽象类,当不相关的类必须提供相同行为时使用接口。


    9. OOP Design Principles and Exam Technique | 面向对象设计原则与考试技巧

    Exam questions often give a scenario and ask you to identify suitable classes, attributes and methods. Start by listing the nouns, which often become classes, and verbs, which often become methods.

    考试题常给出一个场景,要求你识别合适的类、属性和方法。首先列出名词,名词通常成为类;列出动词,动词通常成为方法。

    Use precise terminology in your answers. For example, say ‘the subclass inherits from the superclass’ rather than ‘the child takes the parent’s stuff’.

    答案中要使用准确术语。例如,说“子类继承自父类”,而不是“子类拿了父类的东西”。

    Design principles such as low coupling and high cohesion are valued. Classes should have one clear responsibility and should not depend unnecessarily on other classes.

    低耦合和高内聚等设计原则受到重视。类应该只有一个明确职责,并且不应不必要地依赖其他类。


    10. Common Pitfalls and Mark Scheme Language | 常见误区与评分标准用语

    One common mistake is saying that encapsulation exists only to hide data. It also provides a controlled interface and improves maintainability, so explain both ideas in longer questions.

    一个常见误区是说封装只是为了隐藏数据。封装还提供受控接口并提高可维护性,因此在较长问题中要解释这两个方面。

    Another pitfall is confusing inheritance with aggregation. Inheritance models ‘is-a’, while aggregation and composition model ‘has-a’. Writing ‘a car is an engine’ would lose marks.

    另一个误区是混淆继承与聚合。继承表示“is-a”,而聚合和组合表示“has-a”。写出“汽车是一个引擎”会失分。

    Examiners look for phrases such as ‘instantiate an object’, ‘call the constructor’, ‘override the method’ and ‘encapsulate the attributes’. Practise using these terms under timed conditions.

    考官期待看到“实例化对象”“调用构造函数”“重写方法”“封装属性”等用语。请在限时条件下练习使用这些术语。


    Published by TutorHao | Programming Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Mastering Programming Constructs for Edexcel A-Level Computer Science | 掌握爱德思A-Level计算机科学编程结构

    📚 Mastering Programming Constructs for Edexcel A-Level Computer Science | 掌握爱德思A-Level计算机科学编程结构

    Programming is at the heart of the Edexcel A-Level Computer Science specification. This article explains the key constructs, data structures and paradigms that candidates must understand for Paper 1 and for the practical programming project.

    编程是爱德思A-Level计算机科学课程的核心。本文解释考生在试卷一和编程实践项目中必须掌握的关键结构、数据结构和编程范式。

    1. Programming Paradigms and Language Classification | 编程范式与语言分类

    Edexcel expects candidates to compare procedural, object-oriented, functional and declarative paradigms. Procedural languages use sequences of instructions; object-oriented languages model data and behaviour as objects; functional languages emphasise pure functions; declarative languages specify what to compute rather than how.

    爱德思考纲要求考生比较过程式、面向对象、函数式和声明式范式。过程式语言使用指令序列;面向对象语言将数据和行为建模为对象;函数式语言强调纯函数;声明式语言规定要计算什么,而不是如何计算。

    Low-level machine code and assembly language are imperative and platform-specific, while high-level languages such as Python, Java and C# provide abstraction, portability and readability.

    低级机器码和汇编语言是命令式且面向特定平台的,而 Python、Java 和 C# 等高级语言提供了抽象、可移植性和可读性。


    2. Data Types and Type Casting | 数据类型与类型转换

    The fundamental data types include integer, real/float, Boolean, character and string. Integer arithmetic produces integer results, but division may produce a real result unless integer division is used.

    基本数据类型包括整型、实型/浮点型、布尔型、字符型和字符串。整数算术产生整数结果,但除法除非使用整除,否则可能产生实数结果。

    Casting converts one type to another explicitly or implicitly. For example, in pseudocode, INT(3.7) returns 3, and STRING(25) returns ’25’. Implicit casting occurs when a programming language promotes an integer to a real during mixed expression evaluation.

    类型转换可以显式或隐式地将一种类型转换为另一种。例如,在伪代码中,INT(3.7) 返回 3,STRING(25) 返回 ’25’。当编程语言在混合表达式求值时将整数提升为实数时,会发生隐式转换。

    Use DIV for integer quotient and MOD for remainder in many pseudocode fragments, as this avoids confusion between real division and integer division.

    在许多伪代码片段中使用 DIV 求整数商,使用 MOD 求余数,这样可以避免实数除法与整数除法之间的混淆。


    3. Variables, Constants and Scope | 变量、常量与作用域

    A variable is a named storage location whose value can change during execution. A constant is assigned once and cannot be modified, which improves readability and protects critical values.

    变量是一个命名的存储位置,其值在执行过程中可以改变。常量只赋值一次,不能修改,这提高了可读性并保护关键值。

    Scope refers to the region of a program where an identifier is accessible. Local variables are declared inside a subroutine and destroyed when it returns; global variables persist but increase coupling and reduce maintainability.

    作用域是指程序中标识符可访问的区域。局部变量在子程序内部声明,并当子程序返回时销毁;全局变量持续存在,但会增加耦合并降低可维护性。

    Good practice keeps variables as local as possible, because this limits unintended side effects and makes testing individual modules easier.

    良好的实践是尽可能保持变量为局部变量,因为这可以限制意外的副作用,并使单个模块的测试更加容易。


    4. Operators and Precedence | 运算符与优先级

    Arithmetic operators: + − * / DIV MOD. Comparison operators: = ≠ < > ≤ ≥. Boolean operators: AND OR NOT. Operator precedence determines evaluation order. Parentheses take highest priority, followed by NOT, arithmetic, comparison, and finally AND before OR in many languages.

    算术运算符:+ − * / DIV MOD。比较运算符:= ≠ < > ≤ ≥。布尔运算符:AND OR NOT。运算符优先级决定求值顺序。括号优先级最高,其次是 NOT、算术、比较,最后在许多语言中 AND 优先于 OR。

    Result = (A + B) * C DIV 2

    This expression adds A and B, multiplies by C, then performs integer division by 2. Being precise about precedence prevents logic errors.

    该表达式先计算 A 加 B,再乘以 C,然后执行整除 2。明确优先级可以防止逻辑错误。

    When combining Boolean expressions, use truth tables to check that AND, OR and NOT produce the intended results for all input combinations.

    在组合布尔表达式时,使用真值表检查 AND、OR 和 NOT 是否对所有输入组合产生预期结果。


    5. Selection and Iteration Constructs | 选择与迭代结构

    Selection uses IF…THEN…ELSE…ENDIF and CASE/SWITCH statements. A CASE statement compares one expression against multiple constant values and can be clearer than nested IFs.

    选择使用 IF…THEN…ELSE…ENDIF 和 CASE/SWITCH 语句。CASE 语句将一个表达式与多个常量值进行比较,比嵌套 IF 更清晰。

    Iteration includes definite loops (FOR…NEXT) and indefinite loops (WHILE…ENDWHILE, REPEAT…UNTIL). A WHILE loop tests before each iteration, possibly executing zero times. A REPEAT loop tests after each iteration, so the body executes at least once.

    迭代包括确定循环(FOR…NEXT)和不确定循环(WHILE…ENDWHILE、REPEAT…UNTIL)。WHILE 循环在每次迭代前测试,可能执行零次。REPEAT 循环在每次迭代后测试,因此循环体至少执行一次。

    Trace tables help candidates follow loop counters and boolean conditions accurately, especially when nested loops change multiple variables simultaneously.

    跟踪表帮助考生准确跟踪循环计数器和布尔条件,尤其是当嵌套循环同时改变多个变量时。


    6. Arrays and Lists | 数组与列表

    An array stores multiple values of the same type in contiguous memory locations. One-dimensional arrays are indexed from 0 or 1 depending on the language. Two-dimensional arrays model tables and matrices.

    数组将多个相同类型的值存储在连续的内存位置中。一维数组根据语言从 0 或 1 开始索引。二维数组建模表格和矩阵。

    Common algorithms include linear search, binary search, bubble sort and insertion sort. Binary search requires a sorted list and repeatedly halves the search interval.

    常见算法包括线性搜索、二分搜索、冒泡排序和插入排序。二分搜索需要有序列表,并反复将搜索区间减半。

    mid ← (low + high) DIV 2

    This gives the middle index used in binary search. After comparing the target value with the middle element, the search continues in the left or right half.

    这给出二分搜索中使用的中间索引。将目标值与中间元素比较后,搜索在左半部分或右半部分继续进行。


    7. Stacks, Queues and Records | 栈、队列与记录

    A stack is a LIFO (last in, first out) structure. Operations include push, pop and peek. A queue is FIFO (first in, first out) with enqueue and dequeue operations. Both can be represented using arrays with pointer variables.

    栈是一种 LIFO(后进先出)结构。操作包括 push、pop 和 peek。队列是 FIFO(先进先出)结构,具有 enqueue 和 dequeue 操作。两者都可以使用带指针变量的数组表示。

    A record combines fields of different types under one name. For example, a student record may contain name as string, age as integer and average as real.

    记录将不同类型的字段组合在一个名称下。例如,学生记录可以包含字符串类型的姓名、整数类型的年龄和实数类型的平均分。

    When a stack or queue is full, attempting to add an item causes an overflow error. When it is empty, removing an item causes an underflow error.

    当栈或队列已满时,尝试添加项目会导致溢出错误。当其为空时,删除项目会导致下溢错误。


    8. Functions, Procedures and Parameter Passing | 函数、过程与参数传递

    A procedure performs a task without returning a value; a function returns a value. Both improve modularity and reuse. Parameters can be passed by value or by reference.

    过程执行任务但不返回值;函数返回一个值。两者都提高模块化和重用性。参数可以按值或按引用传递。

    Passing by value copies the argument, so changes inside the subroutine do not affect the original variable. Passing by reference gives the subroutine access to the original memory location.

    按值传递复制实参,因此子程序内部的更改不会影响原始变量。按引用传递使子程序可以访问原始内存位置。

    Choosing the correct passing mechanism prevents accidental modifications and clarifies which variables may be changed by a call.

    选择正确的传递机制可以防止意外修改,并明确哪些变量可能因调用而被更改。


    9. Recursion and Stack Frames | 递归与栈帧

    Recursion occurs when a function calls itself. It must have a base case to terminate. Each recursive call creates a new stack frame containing local variables and return address.

    递归发生在函数调用自身时。它必须有终止递归的基准情形。每次递归调用都会创建一个新的栈帧,包含局部变量和返回地址。

    A classic example is the factorial function: factorial(0) = 1, factorial(n) = n × factorial(n − 1). Recursion is elegant but can cause stack overflow if the base case is missing or too deep.

    经典示例是阶乘函数:factorial(0) = 1,factorial(n) = n × factorial(n − 1)。递归很优雅,但如果缺少基准情形或递归过深,可能导致栈溢出。

    Infinite recursion occurs when the base case is never reached. This consumes stack space until a runtime error occurs.

    当基准情形永远无法到达时,会发生无限递归。这会持续消耗栈空间,直到出现运行时错误。


    10. Object-Oriented Programming Basics | 面向对象编程基础

    OOP uses classes to define blueprints for objects. Encapsulation hides internal state and exposes methods. Inheritance allows a subclass to extend a parent class. Polymorphism lets different classes respond to the same method call in their own way.

    面向对象编程使用类来定义对象的蓝图。封装隐藏内部状态并暴露方法。继承允许子类扩展父类。多态性允许不同类以自己的方式响应相同的方法调用。

    For Edexcel, candidates should understand class diagrams, attributes, methods, constructors and the difference between private and public access modifiers.

    对于爱德思考试,考生应理解类图、属性、方法、构造函数以及私有和公共访问修饰符之间的区别。

    A constructor initialises an object’s state when it is created. Private attributes are only accessible from inside the class, while public methods form the interface for other objects.

    构造函数在创建对象时初始化对象的状态。私有属性只能在类内部访问,而公共方法构成其他对象可用的接口。


    11. Defensive Design and Error Handling | 防御性设计与错误处理

    Defensive design anticipates misuse and invalid input. Input validation checks whether data is sensible before processing. Range checks, presence checks, format checks and look-up checks are common techniques.

    防御性设计预见到误用和无效输入。输入验证在数据处理之前检查数据是否合理。范围检查、存在性检查、格式检查和查找检查是常见技术。

    Syntax errors are detected by the compiler or interpreter. Runtime errors occur during execution, such as division by zero. Logic errors produce incorrect output but do not crash the program.

    语法错误由编译器或解释器检测。运行时错误在执行过程中发生,例如除以零。逻辑错误产生错误的输出,但不会使程序崩溃。

    Good defensive programming also includes meaningful prompts, clear error messages and fail-safe defaults for unexpected conditions.

    良好的防御性编程还包括有意义的提示、清晰的错误消息以及针对意外情况的故障安全默认值。


    12. Testing and Debugging Techniques | 测试与调试技术

    Testing should be planned using normal, boundary and erroneous data. A boundary test uses the maximum, minimum and adjacent values. Erroneous data is invalid and should be rejected gracefully.

    测试应使用正常、边界和异常数据进行规划。边界测试使用最大值、最小值和相邻值。异常数据是无效的,应被妥善拒绝。

    Debugging techniques include dry runs, trace tables, breakpoints and print statements. A trace table shows variable changes line by line and helps locate logic errors.

    调试技术包括人工演算、跟踪表、断点和打印语句。跟踪表逐行显示变量变化,有助于定位逻辑错误。

    A dry run manually executes a program on paper using sample data, which reveals errors in control flow before the program is run on a computer.

    人工演算在纸上使用示例数据手动执行程序,可以在计算机运行之前发现控制流中的错误。


    Published by TutorHao | Programming Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • A-Level Edexcel Programming: Core Concepts and Exam Skills | A-Level Edexcel 编程:核心概念与考试技巧

    📚 A-Level Edexcel Programming: Core Concepts and Exam Skills | A-Level Edexcel 编程:核心概念与考试技巧

    Edexcel A-Level programming exams test both coding fluency and theoretical understanding. You need to read pseudocode, trace algorithms, compare data structures, and justify efficiency. This revision guide covers the core programming topics most often assessed, with bilingual explanations to support both English and Chinese learners.

    Edexcel A-Level 编程考试既考查编码熟练度,也考查理论理解。你需要阅读伪代码、追踪算法、比较数据结构并解释效率。本复习指南涵盖最常考查的核心编程主题,用双语解释帮助中英文学习者。


    1. Programming Basics and Data Types | 编程基础与数据类型

    In Edexcel programming questions, you must select appropriate data types for variables. The main primitive types are integer, real or float, Boolean, character and string. Composite types include arrays, records and sets. Strong typing, used in many exam pseudocode languages, requires each variable to have a declared type, which helps catch errors.

    在 Edexcel 编程题中,必须为变量选择合适的数据类型。主要的原始类型有整数、实数或浮点数、布尔型、字符和字符串。复合类型包括数组、记录和集合。许多考试伪代码语言采用强类型,要求每个变量声明类型,这有助于发现错误。

    Data Type | 数据类型 Example | 示例
    Integer | 整数 42, -7, 0
    Real/Float | 实数 3.14, -0.5
    Boolean | 布尔 True, False
    Character | 字符 ‘A’, ‘7’, ‘$’
    String | 字符串 “hello”, “TutorHao”

    2. Sequence, Selection and Iteration | 顺序、选择与迭代

    Programs are built from three control structures: sequence, selection and iteration. Sequence executes statements in order. Selection uses IF, ELSE IF, ELSE and CASE to branch. Iteration uses FOR, WHILE and REPEAT UNTIL to repeat blocks. Trace tables are a common exam tool; they record variable values after each line of pseudocode.

    程序由三种控制结构构成:顺序、选择和迭代。顺序按顺序执行语句。选择使用 IF、ELSE IF、ELSE 和 CASE 进行分支。迭代使用 FOR、WHILE 和 REPEAT UNTIL 重复代码块。追踪表是常见的考试工具,记录每行伪代码执行后的变量值。

    IF score >= 60 THEN grade ← ‘Pass’ ELSE grade ← ‘Fail’

    You should be able to convert between flowchart diagrams and pseudocode, and to determine how many times a loop runs for a given input.

    你应当能够在流程图和伪代码之间转换,并能确定给定输入下循环执行的次数。


    3. Subprograms and Parameter Passing | 子程序与参数传递

    A subprogram can be a function or a procedure. A function returns a single value and can appear in expressions. A procedure performs a task but does not return a value. Parameters may be passed by value or by reference. By value copies the argument, so changes inside the subprogram do not affect the caller. By reference passes the memory address, so changes do affect the original variable.

    子程序可以是函数或过程。函数返回一个值并可出现在表达式中。过程执行任务但不返回值。参数可以按值或按引用传递。按值复制实参,所以子程序内部的更改不影响调用者。按引用传递内存地址,所以更改会影响原始变量。

    • Pass by value | 按值传递: safe, no side effects | 安全,无副作用
    • Pass by reference | 按引用传递: efficient for large data, allows modification | 适用于大数据,允许修改

    4. Recursion and Stack Frames | 递归与栈帧

    Recursion occurs when a subprogram calls itself. Every recursive solution needs a base case to terminate and a recursive case that moves towards the base case. For example, factorial n can be defined as n times factorial of n minus 1, with factorial of 0 equal to 1. Each call uses a stack frame, so deep recursion can cause stack overflow.

    递归发生在子程序调用自身时。每个递归方案都需要终止的基准情形和向基准情形推进的递归情形。例如,n 的阶乘可定义为 n 乘以 n-1 的阶乘,0 的阶乘为 1。每次调用使用一个栈帧,因此递归过深会导致栈溢出。

    factorial(n) = n × factorial(n – 1), factorial(0) = 1

    Exam questions may ask you to trace a recursive function or to convert a recursive algorithm into an iterative one.

    考试题可能要求你追踪递归函数,或将递归算法转换为迭代算法。


    5. Object-Oriented Programming in Edexcel | Edexcel 中的面向对象编程

    Object-oriented programming models real-world entities as classes and objects. Encapsulation keeps an object’s data private and exposes only necessary methods. Inheritance lets a subclass reuse and extend a parent class. Polymorphism allows the same method name to behave differently in different subclasses. Edexcel exams may ask you to identify these features in class diagrams or code.

    面向对象编程将现实世界实体建模为类和对象。封装保持对象的数据私有,仅公开必要的方法。继承允许子类复用并扩展父类。多态使同一方法名在不同子类中有不同行为。Edexcel 考试可能要求你在类图或代码中识别这些特征。

    • Encapsulation | 封装: data hiding and access methods | 数据隐藏与访问方法
    • Inheritance | 继承: subclass extends superclass | 子类扩展父类
    • Polymorphism | 多态: same interface, different implementation | 同一接口,不同实现
    • Abstraction | 抽象: hide complex details | 隐藏复杂细节

    6. Searching Algorithms | 搜索算法

    Linear search inspects each element from the start until it finds the target or reaches the end. Its worst-case time complexity is O(n). Binary search works on a sorted list by comparing the middle element and discarding half the list each time. Its time complexity is O(log₂ n). For large sorted data, binary search is much faster.

    线性搜索从开头检查每个元素,直到找到目标或到达末尾。其最坏时间复杂度为 O(n)。二分搜索在有序列表上工作,比较中间元素并每次舍弃一半列表。时间复杂度为 O(log₂ n)。对大型有序数据,二分搜索快得多。

    A binary search algorithm sets low to 0, high to length – 1, then repeats while low <= high: mid = (low + high) DIV 2, compare, and adjust low or high.

    二分搜索算法将 low 设为 0,high 设为长度减 1,然后当 low <= high 时重复:mid = (low + high) DIV 2,比较并调整 low 或 high。


    7. Sorting Algorithms | 排序算法

    Bubble sort repeatedly compares adjacent pairs and swaps them if they are in the wrong order. Insertion sort takes one unsorted item at a time and inserts

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Mastering Programming for Edexcel A-Level Computer Science | 掌握 Edexcel A-Level 计算机科学编程

    📚 Mastering Programming for Edexcel A-Level Computer Science | 掌握 Edexcel A-Level 计算机科学编程

    Programming is at the heart of Edexcel A-Level Computer Science. It moves beyond writing code to testing, debugging and evaluating solutions against computational problems. This article reviews key programming concepts that regularly appear in Edexcel examinations, including algorithmic thinking, data structures, recursion, object-oriented design and efficiency.

    编程是 Edexcel A-Level 计算机科学的核心。它不仅仅是编写代码,还涉及测试、调试以及根据计算问题评估解决方案。本文回顾 Edexcel 考试中经常出现的关键编程概念,包括算法思维、数据结构、递归、面向对象设计和算法效率。


    1. Computational Thinking and Problem Decomposition | 计算思维与问题分解

    Computational thinking involves abstraction, decomposition and pattern recognition. Students must break complex tasks into smaller, manageable sub-problems before coding.

    计算思维包括抽象、分解和模式识别。学生必须在编写代码之前将复杂任务分解为更小、可管理的子问题。

    Decomposition makes a problem easier to solve because each module can be developed and tested independently. For example, an order processing system can be split into user input, stock checking, payment and confirmation.

    分解使问题更容易解决,因为每个模块都可以独立开发和测试。例如,订单处理系统可以分解为用户输入、库存检查、支付和确认模块。


    2. Programming Paradigms: Procedural vs Object-Oriented | 编程范式:过程式与面向对象

    Edexcel expects understanding of procedural, object-oriented and event-driven paradigms. Procedural programming uses sequences of instructions and functions, while object-oriented programming models real-world entities as objects with state and behaviour.

    Edexcel 要求理解过程式、面向对象和事件驱动范式。过程式编程使用一系列指令和函数,而面向对象编程将现实世界实体建模为具有状态和行为的对象。

    Event-driven programming responds to user actions such as clicks and key presses, which is common in graphical interfaces.

    事件驱动编程响应用户操作,例如点击和按键,这在图形界面中很常见。

    Paradigm Core Idea Typical Use
    Procedural Sequential instructions and functions System scripts, simple games
    Object-oriented Objects, classes, inheritance Large applications, GUI libraries
    Event-driven Responds to user events Interactive interfaces

    3. Data Types, Variables and Constants | 数据类型、变量与常量

    Programs manipulate data through variables and constants. Common types include integer, real/float, Boolean, character and string.

    程序通过变量和常量操作数据。常见类型包括整型、实数/浮点型、布尔型、字符型和字符串型。

    Constants cannot be changed after initialisation, which helps avoid accidental modification and improves readability. Variable names should be meaningful and follow local scope rules.

    常量在初始化后不能被改变,这有助于避免意外修改并提高可读性。变量名应具有意义并遵循局部作用域规则。


    4. Control Structures: Sequence, Selection, Iteration | 控制结构:顺序、选择、迭代

    All algorithms are built from three control structures: sequence, selection (IF, CASE) and iteration (FOR, WHILE, REPEAT-UNTIL).

    所有算法都由三种控制结构构建:顺序、选择(IF、CASE)和迭代(FOR、WHILE、REPEAT-UNTIL)。

    Nested selection and loops allow complex decision-making but must be carefully indented and tested. A simple summation loop can be written as:

    嵌套选择和循环允许复杂决策,但必须仔细缩进和测试。一个简单的求和循环可以写成:

    total ← 0; FOR i ← 1 TO n DO total ← total + i; ENDFOR


    5. Data Structures: Arrays, Lists and Records | 数据结构:数组、列表与记录

    Arrays store a fixed number of elements of the same type, while lists can grow dynamically. Records group fields of different types under one name.

    数组存储固定数量的同类型元素,而列表可以动态增长。记录将不同类型的字段组合在一个名称下。

    Choosing the right structure affects memory usage and speed. For example, accessing an array by index is O(1), but searching an unsorted list is O(n).

    选择正确的结构会影响内存使用和速度。例如,按索引访问数组是 O(1),但在未排序列表中查找是 O(n)。


    6. Stacks and Queues | 栈与队列

    A stack is a last-in-first-out (LIFO) structure with push and pop operations. A queue is first-in-first-out (FIFO) with enqueue and dequeue operations.

    栈是后进先出(LIFO)结构,具有压入和弹出操作。队列是先进先出(FIFO)结构,具有入队和出队操作。

    Stacks support recursion and backtracking; queues are used in scheduling and breadth-first search. Overflow and underflow must be handled in both structures.

    栈支持递归和回溯;队列用于调度和广度优先搜索。两种结构都必须处理溢出和下溢。


    7. Subroutines, Functions and Recursion | 子程序、函数与递归

    Subroutines break code into reusable blocks. Functions return a value, while procedures perform actions. Parameters can be passed by value or by reference.

    子程序将代码分解为可重用的块。函数返回值,而过程执行操作。参数可以按值或按引用传递。

    Recursion occurs when a subroutine calls itself. Every recursive algorithm needs a base case to terminate, such as factorial:

    递归发生在子程序调用自身时。每个递归算法都需要一个基准条件来终止,例如阶乘:

    factorial(n) = n × factorial(n−1) for n > 1, factorial(1) = 1


    8. Searching and Sorting Algorithms | 查找与排序算法

    Linear search checks every element until a match is found; binary search repeatedly halves a sorted list. Binary search runs in O(log n) time, far faster for large data sets.

    线性查找逐个检查每个元素直到找到匹配项;二分查找反复将有序列表减半。二分查找的时间复杂度为 O(log n),对于大数据集要快得多。

    Common sorting algorithms include bubble sort, insertion sort and merge sort. Merge sort is O(n log n), while bubble sort is O(n²) in the worst case.

    常见排序算法包括冒泡排序、插入排序和归并排序。归并排序为 O(n log n),而冒泡排序在最坏情况下为 O(n²)。

    Algorithm Best Case Worst Case
    Linear search O(1) O(n)
    Binary search O(1) O(log n)
    Bubble sort O(n) O(n²)
    Merge sort O(n log n) O(n log n)

    9. Algorithm Efficiency and Big-O Notation | 算法效率与 Big-O 表示法

    Big-O notation describes how time or space grows with input size n. It ignores constants and lower-order terms to focus on dominant behaviour.

    Big-O 表示法描述时间或空间如何随输入规模 n 增长。它忽略常数和低阶项,专注于主导行为。

    Common classes are O(1), O(log n), O(n), O(n log n), O(n²) and O(2ⁿ). An O(2ⁿ) algorithm becomes impractical very quickly.

    常见类别有 O(1)、O(log n)、O(n)、O(n log n)、O(n²) 和 O(2ⁿ)。O(2ⁿ) 算法很快变得不实用。


    10. Object-Oriented Programming in Practice | 面向对象编程实践

    Classes define attributes and methods. Encapsulation hides internal state, inheritance enables code reuse, and polymorphism allows one interface to represent different forms.

    类定义属性和方法。封装隐藏内部状态,继承实现代码复用,多态允许一个接口表示不同形式。

    For example, a base class Vehicle can have subclasses Car and Bike that override the move() method. This reduces duplication and makes systems easier to maintain.

    例如,基类 Vehicle 可以有子类 Car 和 Bike,它们覆盖 move() 方法。这减少了重复并使系统更易于维护。


    11. File Handling and Exception Management | 文件处理与异常管理

    Programs often read from and write to files. Opening a file, processing records, and closing the file must be managed carefully to avoid data loss.

    程序经常读写文件。必须小心管理打开文件、处理记录和关闭文件,以避免数据丢失。

    Exception handling uses try, except/finally blocks to catch runtime errors such as division by zero, file not found or invalid input. Edexcel questions may ask you to trace such blocks.

    异常处理使用 try、except/finally 块捕获运行时错误,例如除零、文件未找到或无效输入。Edexcel 题目可能要求你跟踪这些代码块。


    12. Testing, Debugging and IDE Skills | 测试、调试与 IDE 技能

    Testing includes normal, boundary and erroneous data. A good test plan records expected and actual outcomes. Debugging uses breakpoints, stepping and watch expressions.

    测试包括正常、边界和错误数据。好的测试计划记录预期结果和实际结果。调试使用断点、单步执行和监视表达式。

    Trace tables are essential in Edexcel exams to simulate variable changes step by step. They show exactly how an algorithm behaves on given inputs.

    在 Edexcel 考试中,跟踪表对于逐步模拟变量变化至关重要。它们准确地显示算法在给定输入上的行为。


    Published by TutorHao | Computer Science Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Programming Constructs, Data Structures and Problem Solving for Edexcel A-Level | Edexcel A-Level 编程结构、数据结构与问题求解

    📚 Programming Constructs, Data Structures and Problem Solving for Edexcel A-Level | Edexcel A-Level 编程结构、数据结构与问题求解

    This revision guide covers the core programming knowledge that Edexcel A-Level Computer Science candidates need to master, from control flow and data structures to recursion, object-oriented ideas and exam technique. It is designed to help you read, trace and write pseudocode confidently under timed conditions.

    本复习指南涵盖 Edexcel A-Level 计算机科学考生需要掌握的核心编程知识,包括控制流、数据结构、递归、面向对象思想以及考试技巧。它旨在帮助你在限时条件下自信地阅读、跟踪和编写伪代码。


    1. Programming Paradigms and Exam Expectations | 编程范式与考试要求

    Edexcel A-Level programming questions test your ability to read, trace and write structured pseudocode in a style close to Python. You are expected to understand procedural programming, especially sequence, selection and iteration, as well as more advanced object-oriented ideas such as classes and inheritance.

    Edexcel A-Level 编程题目要求你能够阅读、跟踪并编写接近 Python 风格的结构化伪代码。考试要求你理解过程式编程,特别是顺序、选择和迭代,同时也要掌握类、继承等更高级的面向对象思想。

    • Procedural programming: code is organised into procedures and functions.
      过程式编程:代码被组织为过程和函数。
    • Object-oriented programming: code is organised around classes and objects.
      面向对象编程:代码围绕类和对象进行组织。
    • Exam pseudocode: Edexcel does not require a specific programming language, but your syntax must be consistent and unambiguous.
      考试伪代码:Edexcel 不要求使用特定编程语言,但语法必须一致且无歧义。

    2. Sequence, Selection and Iteration | 顺序、选择与迭代

    The three fundamental control structures are sequence, selection and iteration. Sequence means statements execute one after another. Selection uses IF, ELSE IF and ELSE or CASE statements to make decisions. Iteration repeats code with count-controlled FOR loops, condition-controlled WHILE loops, or post-condition REPEAT loops.

    三种基本控制结构是顺序、选择和迭代。顺序表示语句逐条执行;选择使用 IF、ELSE IF、ELSE 或 CASE 语句进行判断;迭代使用计数控制的 FOR 循环、条件控制的 WHILE 循环或后条件 REPEAT 循环重复执行代码。

    IF score ≥ 90 THEN grade = ‘A’
    ELSE IF score ≥ 80 THEN grade = ‘B’
    ELSE grade = ‘C’

    In this pseudocode, the selection checks the score in descending order. A trace of any selection must test every branch, including the final ELSE case. For iteration, be clear about the loop counter, the condition, and the values at the moment the loop exits.

    在这段伪代码中,选择按从高到低的顺序检查分数。跟踪任何选择结构时,必须测试每个分支,包括最后的 ELSE 情况。对于迭代,必须清楚循环计数器、条件以及循环退出瞬间的变量值。


    3. Variables, Data Types, Casting and Constants | 变量、数据类型、类型转换与常量

    Variables must be declared with a clear type in Edexcel pseudocode: INTEGER, REAL, BOOLEAN, CHAR and STRING are the main types. Type casting converts one type to another, such as converting a string input to an integer before arithmetic. Constants are named values that do not change during execution.

    在 Edexcel 伪代码中,变量必须使用明确的数据类型声明:INTEGER、REAL、BOOLEAN、CHAR 和 STRING 是主要类型。类型转换用于把一种类型转换为另一种类型,例如在计算前把字符串输入转换为整数。常量是在执行过程中不改变的命名值。

    Data type Example 中文说明
    INTEGER age = 17 整数
    REAL price = 9.99 实数/浮点
    BOOLEAN valid = TRUE 布尔
    CHAR symbol = ‘A’ 字符
    STRING name = ‘Ada’ 字符串

    Incorrect type handling is a common source of runtime errors. If the user enters “17” into a text field, it is stored as a string, so you must cast it to INTEGER before adding 1.

    错误的数据类型处理是常见的运行时错误来源。如果用户在文本框中输入 “17”,它被存储为字符串,因此你必须在进行加 1 操作前将其转换为整数类型。


    4. Arrays, Lists and 2D Structures | 数组、列表与二维结构

    A one-dimensional array stores a fixed-size collection of elements of the same type, accessed by an index. In Edexcel pseudocode, indexing often starts at 0. A two-dimensional array uses row and column indices and is ideal for grids, tables and matrices.

    一维数组存储固定大小的相同类型元素集合,通过下标访问。在 Edexcel 伪代码中,下标通常从 0 开始。二维数组使用行下标和列下标,非常适合表示网格、表格和矩阵。

    arrNames[0] = ‘Ada’
    matrix[1][2] = 7

    When tracing a 2D array, first locate the row, then the column. Iterating through a 2D structure usually requires nested loops: an outer loop for rows and an inner loop for columns. Edexcel questions often present a 2D array as a grid and ask you to fill a trace table or write code to search through it.

    跟踪二维数组时,应先定位行,再定位列。遍历二维结构通常需要嵌套循环:外层循环控制行,内层循环控制列。Edexcel 题目经常把二维数组表示为网格,要求你填写跟踪表或编写搜索代码。

    • Row-major order: elements are stored row by row.
      行主序:元素按行存储。
    • Column-major order: elements are stored column by column.
      列主序:元素按列存储。
    • Index out of bounds: accessing an invalid index causes an error.
      下标越界:访问无效下标会导致错误。

    5. String Handling and Validation | 字符串处理与验证

    String manipulation includes finding length, extracting substrings, concatenation, and conversion between upper and lower case. Validation checks whether input is reasonable before processing. Common validation techniques are presence check, range check, length check, format check and check digit.

    字符串处理包括求长度、提取子串、拼接以及大小写转换。验证在处理输入之前检查数据是否合理。常见验证技术有存在检查、范围检查、长度检查、格式检查和校验位。

    • Presence check: ensures a field is not empty.
      存在检查:确保字段不为空。
    • Range check: ensures a value falls between a minimum and maximum.
      范围检查:确保值在最小值和最大值之间。
    • Length check: ensures a string has the expected number of characters.
      长度检查:确保字符串具有预期字符数。
    • Format check: ensures data follows a pattern, such as XX999.
      格式检查:确保数据遵循模式,如 XX999。
    • Check digit: uses an extra digit to detect input errors in codes.
      校验位:使用额外数字检测代码中的输入错误。

    String handling questions often ask you to extract initials, count characters, or compare substrings. Always state whether indexing starts at 0 or 1 in your pseudocode.

    字符串处理题目经常要求你提取首字母、统计字符或比较子串。在你的伪代码中,必须始终说明下标是从 0 还是 1 开始。


    6. Subprograms: Procedures, Functions and Parameter Passing | 子程序:过程、函数与参数传递

    A procedure performs a task without returning a value, while a function returns exactly one value. Parameters can be passed by value or by reference; by value copies the data, but by reference allows changes to affect the original variable. Local variables exist only inside the subroutine, while global variables are visible throughout the program.

    过程执行任务但不返回值,而函数恰好返回一个值。参数可以按值传递或按引用传递;按值传递会复制数据,而按引用传递允许函数内部修改原变量。局部变量仅存在于子程序内部,而全局变量在整个程序中可见。

    FUNCTION Add(a, b)
    RETURN a + b
    ENDFUNCTION

    Edexcel expects you to identify whether a parameter is passed by value or by reference. In a trace table, a by value parameter gets its own copy, so changes inside the subroutine do not alter the original argument. A by reference parameter points to the same memory location, so changes do propagate back.

    Edexcel 要求你能够识别参数是按值传递还是按引用传递。在跟踪表中,按值传递的参数获得自己的副本,因此子程序内部的变化不会改变原始实参。按引用传递的参数指向相同的内存位置,因此内部变化会传回。


    7. Recursion and the Call Stack | 递归与调用栈

    Recursion occurs when a subroutine calls itself. Every recursive algorithm must have a base case to stop, and a recursive case that reduces the problem toward the base case. The call stack stores return addresses and local variables for each active call.

    递归发生在子程序调用自身时。每个递归算法必须有停止递归的基准情形,以及把问题规模向基准情形缩小的递归情形。调用栈为每一次活动调用存储返回地址和局部变量。

    FUNCTION Factorial(n)
    IF n = 0 THEN RETURN 1
    ELSE RETURN n × Factorial(n – 1)
    ENDIF
    ENDFUNCTION

    Without a base case, recursion continues until the stack overflows. In Edexcel papers, you may be asked to dry-run a recursive function for a small value such as Factorial(3). Write each stack frame on a separate row and update the return value as the stack unwinds.

    没有基准情形,递归会一直进行直到栈溢出。在 Edexcel 试卷中,你可能需要对较小的数值如 Factorial(3) 手工执行递归函数。把每个栈帧单独写一行,并在栈展开时更新返回值。

    • Base case: the condition that stops recursion.
      基准情形:停止递归的条件。
    • Recursive case: the part that calls itself with a smaller problem.
      递归情形:以更小规模问题调用自身的部分。
    • Stack overflow: too many recursive calls with no base case.
      栈溢出:递归调用过多且没有基准情形。

    8. Searching and Sorting Algorithms | 查找与排序算法

    Linear search works on unsorted lists and checks each element in turn with O(n) time. Binary search requires a sorted list and repeatedly halves the search interval with O(log n) time. Sorting algorithms include bubble sort O(n²), merge sort O(n log n), and quick sort O(n log n) average.

    线性查找适用于未

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Edexcel A Level Programming Essentials: Constructs, Data Types and Subroutines | 爱德思 A-Level 编程核心:结构、数据类型与子程序

    📚 Edexcel A Level Programming Essentials: Constructs, Data Types and Subroutines | 爱德思 A-Level 编程核心:结构、数据类型与子程序

    Programming is at the centre of the Edexcel A Level Computer Science specification. Success depends on your ability to read, write and trace code using sequence, selection and iteration, and to design modular solutions with subroutines and appropriate data structures. This revision guide walks through the key concepts and common exam pitfalls from Paper 1 and the NEA.

    编程是爱德思 A-Level 计算机科学考试的核心。要取得好成绩,你需要能够阅读、编写和追踪使用顺序、选择与迭代的代码,并能够使用子程序和合适的数据结构设计模块化解决方案。本复习指南梳理 Paper 1 和课程作业中的关键概念与常见易错点。

    1. Programming Constructs and Pseudocode | 编程结构与伪代码

    Every program is built from three fundamental constructs: sequence, selection and iteration. Sequence means instructions are executed in the order they are written; selection allows a choice between paths; iteration repeats a block of code while a condition holds.

    每个程序都由三种基本结构构建:顺序、选择和迭代。顺序表示指令按书写顺序执行;选择允许在不同路径之间做出抉择;迭代在条件成立时重复执行一段代码。

    Edexcel often asks you to convert between pseudocode and a high-level language such as Python. Your pseudocode should be clear, consistent and language-independent, using indentation to show nesting.

    爱德思经常要求你在伪代码和 Python 等高级语言之间转换。伪代码应当清晰、一致且不依赖具体语言,并使用缩进表示嵌套。


    2. Data Types and Variables | 数据类型与变量

    You must select and justify appropriate data types: integer for whole numbers, float or real for decimals, Boolean for true/false, character for a single symbol, and string for text. Choosing the correct type affects memory, validation and operations.

    你必须选择并说明合适的数据类型:整数用于整数值,浮点数或实数用于小数,布尔型用于真/假,字符用于单个符号,字符串用于文本。选择正确的类型会影响内存、验证和运算。

    Variables are named storage locations whose value can change during execution. Constants are fixed values that cannot be changed, which improves readability and prevents accidental modification.

    变量是命名的存储位置,其值在程序执行期间可以改变。常量是不能更改的固定值,它可以提高可读性并防止意外修改。

    Data type Example Typical use
    Integer 7 counts, indexes
    Float / Real 3.14 measurements, prices
    Boolean True / False flags, conditions
    Character ‘A’ single letters
    String “hello” words, names

    3. Operators and Expressions | 运算符与表达式

    Arithmetic operators such as +, -, *, /, MOD and DIV follow standard precedence. Boolean operators AND, OR and NOT are used to combine conditions, while relational operators =, <, >, <=, >= and != compare values.

    算术运算符(+、-、*、/、MOD、DIV)遵循标准优先级。布尔运算符 AND、OR 和 NOT 用于组合条件,关系运算符 =、<、>、<=、>= 和 != 用于比较值。

    In Python, DIV is written as // and MOD as %. The expression 17 MOD 5 evaluates to 2, while 17 DIV 5 evaluates to 3.

    在 Python 中,DIV 写作 //,MOD 写作 %。表达式 17 MOD 5 的值为 2,而 17 DIV 5 的值为 3。

    remainder = 17 − (17 DIV 5) × 5 = 17 − 3 × 5 = 2


    4. Selection Statements | 选择语句

    Selection allows a program to take different branches using IF, ELSE IF or ELIF, and ELSE. Nested IF statements handle multiple levels of decision-making but can become hard to read.

    选择允许程序使用 IF、ELSE IF 或 ELIF 和 ELSE 选择不同的分支。嵌套 IF 语句处理多层决策,但可能变得难以阅读。

    A common exam task is to rewrite a nested IF as a CASE or SELECT statement. Edexcel also expects you to choose the most efficient condition ordering to avoid redundant checks.

    常见的考试任务是使用 CASE 或 SELECT 语句重写嵌套 IF。爱德思还要求你选择最高效的条件顺序,以避免冗余判断。


    5. Iteration: Count-Controlled and Condition-Controlled | 迭代:计数控制与条件控制

    Count-controlled iteration repeats a set number of times, typically using a FOR loop: FOR i = 1 TO 10. Condition-controlled iteration uses WHILE or REPEAT…UNTIL and continues while or until a condition is met.

    计数控制迭代重复固定的次数,通常使用 FOR 循环:FOR i = 1 TO 10。条件控制迭代使用 WHILE 或 REPEAT…UNTIL,在满足或直到满足某个条件时继续执行。

    A WHILE loop checks the condition before each pass, so it may execute zero times. A REPEAT…UNTIL loop checks after the first pass, so the body always executes at least once. This distinction is frequently tested.

    WHILE 循环在每次循环前检查条件,因此可能执行零次。REPEAT…UNTIL 循环在第一次执行后检查条件,因此循环体至少执行一次。这一区别经常出现在考题中。


    6. Subroutines, Procedures and Functions | 子程序、过程与函数

    A subroutine is a named block of code that can be called from elsewhere. Procedures perform a task but do not return a value; functions perform a task and return a value. Both support modularity and reuse.

    子程序是可以在其他地方调用的命名代码块。过程执行任务但不返回值;函数执行任务并返回一个值。两者都支持模块化和代码复用。

    You should be able to write a function such as: FUNCTION calculateArea(r) RETURN 3.14 * r * r. A procedure might display the result instead, for example: PROCEDURE printArea(r) OUTPUT 3.14 * r * r.

    你应当能编写函数,例如:FUNCTION calculateArea(r) RETURN 3.14 * r * r。过程则可以显示结果,例如:PROCEDURE printArea(r) OUTPUT 3.14 * r * r


    7. Parameter Passing and Scope | 参数传递与作用域

    Parameters allow data to be passed into a subroutine. Passing by value copies the argument, so changes inside the subroutine do not affect the original variable. Passing by reference gives the subroutine access to the original memory location, so changes persist.

    参数允许将数据传入子程序。按值传递复制实参,因此子程序内部对参数的更改不会影响原变量。按引用传递允许子程序访问原内存位置,因此更改会保留。

    Scope determines where a variable can be used. A local variable is declared inside a subroutine and exists only during that call. A global variable is declared outside all subroutines and can be accessed throughout the program, but overusing globals makes code harder to debug.

    作用域决定变量可以在哪里使用。局部变量在子程序内部声明,仅在该调用期间存在。全局变量在所有子程序之外声明,可在整个程序中访问,但过度使用全局变量会使代码难以调试。


    8. Recursion and the Call Stack | 递归与调用栈

    Recursion occurs when a subroutine calls itself. Every recursive routine must have a base case to stop the recursion and a recursive case that moves towards the base case. Without a base case, the program causes a stack overflow.

    递归发生在子程序调用自身时。每个递归例程必须有一个基准条件来停止递归,以及一个向基准条件靠近的递归条件。没有基准条件会导致栈溢出。

    Each recursive call is placed on the call stack with its own local variables and return address. When the base case is reached, the calls unwind and return values are combined. Edexcel often asks you to trace a recursive function such as factorial.

    每次递归调用都会被放入调用栈,并带有自己的局部变量和返回地址。当达到基准条件时,调用逐层返回并合并返回值。爱德思经常要求你追踪阶乘等递归函数。

    factorial(n) = n × factorial(n − 1) for n > 0, with factorial(0) = 1


    9. Arrays, Lists and Records | 数组、列表与记录

    Arrays store multiple items of the same data type under one identifier, with each element accessed by an index. A 1D array is a list; a 2D array is a table with rows and columns. In Python, lists can store mixed types and are mutable.

    数组在一个标识符下存储多个相同数据类型的元素,每个元素通过索引访问。一维数组是列表;二维数组是带行和列的表。在 Python 中,列表可以存储混合类型并且可变。

    A record combines fields of different data types to represent a single entity, such as a student record with name, age and grade. Records are useful for database-style problems and are often tested through pseudocode.

    记录将不同数据类型的字段组合起来表示单个实体,例如包含姓名、年龄和成绩的学生记录。记录适用于数据库类问题,常在伪代码题中考查。


    10. File Handling and Exception Handling | 文件处理与异常处理

    Programs may need to read from or write to external files. Text files store readable characters, while binary files store data in machine-readable form. You should understand open, close, read, write and append operations.

    程序可能需要从外部文件读取或写入。文本文件存储可读字符,二进制文件以机器可读形式存储数据。你应当理解打开、关闭、读取、写入和追加等操作。

    Exception handling uses TRY, EXCEPT and FINALLY blocks to manage runtime errors such as division by zero or a missing file. In pseudocode, you can describe the action taken when an error occurs.

    异常处理使用 TRY、EXCEPT 和 FINALLY 块来管理运行时错误,例如除零或文件缺失。在伪代码中,你可以描述发生错误时采取的操作。


    11. Testing, Trace Tables and Debugging | 测试、追踪表与调试

    Thorough testing uses normal, boundary and erroneous data. A trace table records the values of variables at each step and is a common exam question for demonstrating how an algorithm works.

    充分的测试应使用正常、边界和错误数据。追踪表记录每一步变量的值,是考试中常见的要求展示算法如何运行的题型。

    Debugging involves identifying and correcting logic, runtime and syntax errors. You should be able to suggest suitable test data and explain the expected result for each case.

    调试涉及识别并纠正逻辑错误、运行时错误和语法错误。你应当能够为每种情况提出合适的测试数据并解释预期结果。


    Published by TutorHao | Programming Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Searching and Sorting Algorithms for Edexcel A Level Programming | Edexcel A Level 编程:搜索与排序算法

    📚 Searching and Sorting Algorithms for Edexcel A Level Programming | Edexcel A Level 编程:搜索与排序算法

    Searching and sorting algorithms are central to the Edexcel A Level Programming topic. This guide follows the specification and the style of the Pearson ActiveLearn OPS combined 203 resource, focusing on linear search, binary search, bubble sort, insertion sort, merge sort and quick sort. You will learn how to trace these algorithms, compare their efficiency using Big O notation, and answer exam-style questions with confidence.

    搜索与排序算法是 Edexcel A Level 编程主题的核心内容。本指南依据考试大纲并参照 Pearson ActiveLearn OPS combined 203 资源的风格,重点讲解线性搜索、二分搜索、冒泡排序、插入排序、归并排序和快速排序。你将学会如何追踪这些算法,使用大 O 表示法比较它们的效率,并自信地解答考试题目。


    1. Why Algorithms Matter in A Level Programming | 为什么算法在 A Level 编程中很重要

    An algorithm is a finite sequence of unambiguous steps that transforms an input into an output. Edexcel A Level Computer Science requires you not only to read pseudocode but also to trace algorithms, count comparisons, identify best and worst cases, and choose the most suitable algorithm for a given data set.

    算法是一组有限且无歧义的步骤,将输入转换为输出。Edexcel A Level 计算机科学不仅要求你阅读伪代码,还要求你追踪算法、统计算法中的比较次数、识别最佳和最坏情况,并为给定数据集选择最合适的算法。

    Searching and sorting algorithms therefore provide a perfect test of computational thinking. You must model the process step by step, understand how the number of steps grows, and evaluate trade-offs such as speed versus memory usage. These skills appear repeatedly in written papers and practical programming tasks.

    因此,搜索与排序算法是对计算思维的完美考查:你必须逐步建立模型、理解步骤数量的增长方式,并评估速度与内存使用之间的权衡。这些技能在笔试和实际编程任务中反复出现。

    In the Edexcel specification, algorithmic reasoning is linked directly to problem solving with programs. A strong grasp of searching and sorting allows you to explain why a program behaves efficiently or inefficiently, which is a common requirement in high-band questions.

    在 Edexcel 考试大纲中,算法推理与程序化问题解决直接相关。扎实掌握搜索与排序算法后,你就能解释程序为何高效或低效,这也是高分题目中的常见要求。


    2. Key Terms and Core Concepts | 关键术语与核心概念

    Before tracing algorithms, you should be confident with these terms: time complexity, space complexity, Big O notation, in-place sorting, stable sorting, recursion and iteration. These ideas underpin almost every mark scheme for algorithm questions.

    在追踪算法之前,你应该熟练掌握以下术语:时间复杂度、空间复杂度、大 O 表示法、原地排序、稳定排序、递归和迭代。这些概念是几乎所有算法题评分方案的基础。

    Time complexity describes how the number of operations grows with the input size n, while space complexity describes how much extra memory is needed. Big O notation gives an upper bound on that growth and ignores constant factors and lower-order terms.

    时间复杂度描述操作

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • A-Level Edexcel Programming: Core Topics and Exam Technique | A-Level Edexcel 编程:核心主题与考试技巧

    📚 A-Level Edexcel Programming: Core Topics and Exam Technique | A-Level Edexcel 编程:核心主题与考试技巧

    In A-Level Edexcel Computer Science, programming is not just about writing code; it is about applying computational thinking, selecting appropriate data structures, designing algorithms, and evaluating solutions. This guide walks through the core programming topics and exam strategies you need to handle both theory questions and practical coding tasks.

    在 A-Level Edexcel 计算机科学中,编程不仅是编写代码,更是应用计算思维、选择合适的数据结构、设计算法并评估解决方案。本指南将带你梳理核心编程主题与考试策略,帮助你应对理论题和实际编码任务。

    1. Computational Thinking and Problem Solving | 计算思维与问题解决

    Computational thinking underpins every programming task in Edexcel A-Level Computer Science. It consists of decomposition (breaking a large problem into smaller parts), pattern recognition (identifying similarities), abstraction (removing unnecessary detail), and algorithm design (creating step-by-step instructions). Before writing any code, you should show these steps in your answer.

    计算思维是 Edexcel A-Level 计算机科学中每个编程任务的基础。它包括分解(将大问题拆成小部分)、模式识别(找出相似性)、抽象(去除不必要细节)和算法设计(创建逐步指令)。在编写任何代码之前,你应在答案中体现这些步骤。

    In exams, you may be asked to represent a solution as a flowchart or pseudocode. Flowcharts use standard symbols: ovals for start/end, rectangles for processes, diamonds for decisions, and parallelograms for input/output. Pseudocode should be clear, consistent, and independent of any specific programming language.

    在考试中,你可能需要用流程图或伪代码表示解决方案。流程图使用标准符号:椭圆表示开始/结束,矩形表示处理,菱形表示判断,平行四边形表示输入/输出。伪代码应清晰、一致,并且不依赖于任何特定编程语言。


    2. Programming Constructs | 编程基本结构

    All programs are built from three basic constructs: sequence, selection, and iteration. Sequence means instructions run one after another. Selection uses IF, ELSE IF, ELSE or CASE statements to choose between alternatives. Iteration allows repeated execution using FOR, WHILE, or REPEAT…UNTIL loops.

    所有程序都由三种基本结构组成:顺序、选择和迭代。顺序表示指令一条接一条执行。选择使用 IF、ELSE IF、ELSE 或 CASE 语句在不同路径之间选择。迭代允许使用 FOR、WHILE 或 REPEAT…UNTIL 循环重复执行。

    For example, a WHILE loop checks the condition before each iteration, whereas a REPEAT…UNTIL loop checks the condition after at least one execution. Understanding this difference helps prevent logic errors such as off-by-one errors.

    例如,WHILE 循环在每次迭代之前检查条件,而 REPEAT…UNTIL 循环在至少执行一次后才检查条件。理解这一差异有助于防止诸如差一错误之类的逻辑错误。

    Construct 结构 Typical form 典型形式 Use case 使用场景
    Sequence 顺序 statement 1, statement 2, statement 3 Linear tasks 线性任务
    Selection 选择 IF, ELSE IF, ELSE, CASE Decision making 决策判断
    更多咨询请联系16621398022(同微信)

  • Edexcel A-Level Programming: Core Concepts and Algorithms | Edexcel A-Level 编程:核心概念与算法

    📚 Edexcel A-Level Programming: Core Concepts and Algorithms | Edexcel A-Level 编程:核心概念与算法

    Programming is the practical foundation of the Edexcel A-Level Computer Science specification. This guide walks through the essential constructs, data structures, algorithms and development practices that you are expected to understand, apply and evaluate in Paper 1 and Paper 2.

    编程是 Edexcel A-Level 计算机科学考试大纲的实践基础。本指南涵盖你在 Paper 1 和 Paper 2 中需要理解、应用和评估的基本结构、数据结构、算法和开发实践。


    1. Programming Paradigms | 编程范式

    A programming paradigm is a style or way of thinking about writing code. Edexcel expects you to compare procedural, object-oriented and low-level approaches, and to justify the choice of paradigm for a given problem.

    编程范式是一种编写代码的风格或思维方式。Edexcel 要求你比较过程式、面向对象和低级编程方法,并能为给定问题选择范式并说明理由。

    In procedural programming, a problem is broken down into a sequence of instructions and reusable procedures. In object-oriented programming, data and behaviour are grouped into classes and objects, supporting encapsulation and inheritance.

    在过程式编程中,问题被分解为一系列指令和可重用过程。在面向对象编程中,数据和行为被组合成类和对象,从而支持封装和继承。


    2. Data Types and Variables | 数据类型与变量

    Variables are named memory locations that store data during program execution. Each variable has a data type that determines what values it can hold and what operations can be performed on it.

    变量是在程序执行期间存储数据的命名内存位置。每个变量都有一种数据类型,决定了它可以保存哪些值以及可以对它执行哪些操作。

    Common primitive data types include integer, real, Boolean, character and string. Choosing the correct data type is important for memory efficiency and for avoiding type errors.

    常见的原始数据类型包括整型、实型、布尔型、字符型和字符串型。选择正确的数据类型对于内存效率和避免类型错误非常重要。


    3. Operators and Expressions | 运算符与表达式

    Operators are symbols that perform operations on operands. Arithmetic operators include +, −, ×, ÷ and MOD, while comparison operators include =, ≠, <, >, ≤ and ≥.

    运算符是对操作数执行操作的符号。算术运算符包括 +、−、×、÷ 和 MOD,比较运算符包括 =、≠、<、>、≤ 和 ≥。

    Boolean operators AND, OR and NOT are used to combine conditions. The truth tables for these operators must be memorised for questions on logic and condition evaluation.

    布尔运算符 AND、OR 和 NOT 用于组合条件。这些运算符的真值表必须牢记,以应对逻辑和条件求值相关问题。

    total ← price × quantity + delivery


    4. Selection and Iteration | 选择与迭代

    Selection allows a program to choose between different paths. The main selection constructs are IF…THEN…ELSE and CASE statements.

    选择结构允许程序在不同路径之间进行选择。主要的选择结构是 IF…THEN…ELSE 和 CASE 语句。

    Iteration allows a block of code to repeat. Definite iteration uses FOR loops when the number of repetitions is known, while indefinite iteration uses WHILE or REPEAT…UNTIL loops when the repetition depends on a condition.

    迭代结构允许一段代码重复执行。当重复次数已知时使用计数控制的 FOR 循环;当重复取决于条件时使用条件控制的 WHILE 或 REPEAT…UNTIL 循环。

    WHILE score < 50 DO score ← score + 10


    5. Subprograms and Parameters | 子程序与参数

    Subprograms, including procedures and functions, allow large problems to be split into smaller, manageable modules. A function returns a value, while a procedure does not.

    子程序(包括过程和函数)可以将大型问题拆分为更小、更易于管理的模块。函数会返回一个值,而过程不会返回值。

    Parameters pass data into subprograms. Value parameters copy the original value, so changes inside the subprogram do not affect the caller. Reference parameters pass the address, so changes do affect the caller.

    参数将数据传入子程序。值参数复制原始值,因此子程序内部的更改不会影响调用者。引用参数传递地址,因此更改会影响调用者。


    6. Arrays and Lists | 数组与列表

    An array is a static data structure that stores elements of the same data type in contiguous memory locations. Elements are accessed by an index, typically starting at 0 or 1.

    数组是一种静态数据结构,在连续的内存位置中存储相同数据类型的数据元素。元素通过索引访问,通常从 0 或 1 开始。

    A list is a dynamic data structure that can grow and shrink at runtime. Lists support operations such as append, insert, remove and search.

    列表是一种动态数据结构,可以在运行时增长和缩小。列表支持追加、插入、删除和查找等操作。

    • Array: fixed size, direct access, memory efficient
    • List: dynamic size, flexible insertion and deletion
    • 数组:固定大小,可直接访问,内存效率高
    • 列表:动态大小,插入和删除灵活

    7. Stacks and Queues | 栈与队列

    A stack is a Last In First Out data structure. The primary operations are push to add an item and pop to remove the most recently added item.

    栈是一种后进先出的数据结构。主要操作是 push 用于添加元素,pop 用于移除最近添加的元素。

    A queue is a First In First Out data structure. Items are added at the rear and removed from the front, making queues useful for scheduling and buffering.

    队列是一种先进先出的数据结构。元素在队尾添加,在队首移除,因此队列适用于调度和缓冲。

    Stacks are used in recursion, expression evaluation and undo features. Queues are used in printer spooling, keyboard buffers and breadth-first search.

    栈用于递归、表达式求值和撤销功能。队列用于打印池、键盘缓冲和广度优先搜索。


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

    Linear search checks each element in sequence. It works on unsorted data and has worst-case time complexity O(n). Binary search repeatedly halves a sorted list and has time complexity O(log n).

    线性搜索按顺序检查每个元素。它适用于未排序的数据,最坏时间复杂度为 O(n)。二分搜索不断将有序列表减半,时间复杂度为 O(log n)。

    Bubble sort repeatedly compares adjacent items and swaps them if they are in the wrong order. Merge sort divides the list into halves, sorts each half recursively and merges them.

    冒泡排序反复比较相邻元素,如果顺序错误则交换它们。归并排序将列表分成两半,递归地对每一半排序然后合并。

    Algorithm Best case Worst case
    Linear search O(1) O(n)
    Binary search O(1) O(log n)
    Bubble sort O(n) O(n²)
    Merge sort O(n log n) O(n log n)

    9. Recursion and Trace Tables | 递归与跟踪表

    Recursion is a technique where a subprogram calls itself. Every recursive routine must have a base case to stop the recursion and a recursive case that moves toward the base case.

    递归是一种子程序调用自身的技术。每个递归例程必须有一个终止递归的基准情形,以及一个使问题逐步接近基准情形的递归情形。

    A trace table records the values of variables at each step of an algorithm. It is a vital tool for testing logic, identifying errors and answering exam questions involving loops, recursion and arrays.

    跟踪表记录算法每一步的变量值。它是测试逻辑、识别错误以及解答涉及循环、递归和数组考题的重要工具。

    fib(n) = fib(n−1) + fib(n−2), with fib(1) = fib(2) = 1


    10. Object-Oriented Programming | 面向对象编程

    Object-oriented programming organises code into classes and objects. A class is a blueprint, while an object is an instance of a class with its own state and behaviour.

    面向对象编程将代码组织为类和对象。类是蓝图,而对象是具有自身状态和行为的类实例。

    Encapsulation hides internal data and only exposes necessary methods. Inheritance allows a subclass to reuse and extend the features of a superclass, while polymorphism lets different objects respond to the same method call in different ways.

    封装隐藏内部数据,只暴露必要的方法。继承允许子类重用和扩展父类的特性,而多态让不同对象能够以不同方式响应同一方法调用。


    11. Translators and Development Tools | 翻译器与开发工具

    A compiler translates the entire source code into machine code before execution. An interpreter translates and executes source code line by line, which makes debugging easier but often runs more slowly.

    编译器在执行之前将整个源代码翻译为机器代码。解释器逐行翻译并执行源代码,这使调试更容易但运行通常更慢。

    An assembler converts assembly language into machine code. Assemblers are specific to a processor architecture and produce very efficient low-level code.

    汇编器将汇编语言转换为机器代码。汇编器针对特定处理器架构,并能生成非常高效的低级代码。

    An integrated development environment typically includes a code editor, translator, debugger, auto-completion, breakpoints and step-through tools to support the software development process.

    集成开发环境通常包括代码编辑器、翻译器、调试器、自动补全、断点和单步执行工具,以支持软件开发过程。


    12. Testing and Debugging | 测试与调试

    Testing ensures that a program meets its requirements and handles invalid input correctly. Normal, boundary and erroneous test data should be used to cover all important paths.

    测试确保程序满足其需求并能正确处理无效输入。应使用正常、边界和错误测试数据覆盖所有重要路径。

    Debugging is the process of finding and correcting errors. Syntax errors break language rules, logic errors produce wrong results, and runtime errors occur during execution such as division by zero or stack overflow.

    调试是发现并纠正错误的过程。语法错误违反语言规则,逻辑错误产生错误结果,运行时错误在执行期间发生,例如除以零或栈溢出。

    Maintainability is improved through meaningful identifiers, modular design, comments, constants instead of magic numbers, and consistent indentation.

    通过使用有意义的标识符、模块化设计、注释、用常量代替魔数以及一致的缩进,可以提高程序的可维护性。


    Published by TutorHao | Programming Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • A-Level Edexcel Programming: Operators and Combined Expressions | 运算符与组合表达式

    📚 A-Level Edexcel Programming: Operators and Combined Expressions | 运算符与组合表达式

    In Edexcel A-Level Computer Science, programming questions often require you to combine arithmetic, comparison and logical operators into a single expression. This topic looks at how operators are classified, how precedence controls evaluation, and how to avoid common mistakes in pseudocode and Python.

    在 Edexcel A-Level 计算机科学中,编程题经常要求你把算术、比较和逻辑运算符组合到同一个表达式中。本专题介绍运算符的分类、优先级如何控制求值顺序,以及如何在伪代码和 Python 中避免常见错误。

    Operators are not isolated tools: they interact with data types, variables and Boolean logic. Understanding them clearly will help you trace code, predict output and write robust solutions in both Paper 1 and the programming project.

    运算符不是孤立的工具:它们与数据类型、变量和布尔逻辑相互作用。清晰地理解运算符有助于你在 Paper 1 和编程项目中追踪代码、预测输出并写出可靠的程序。

    1. Operators in the Specification | 考试大纲中的运算符

    The Edexcel specification expects you to use arithmetic, relational, Boolean and assignment operators confidently. You may see them in pseudocode or in a high-level language such as Python, so you need to recognise both forms.

    Edexcel 大纲要求你能够熟练使用算术、关系、布尔和赋值运算符。这些运算符可能出现在伪代码或 Python 等高级语言中,因此你需要认识两种写法。

    An operator is a symbol that tells the computer to perform a specific operation on one or more operands. For example, in the expression a + b, the plus sign is the operator and a and b are the operands.

    运算符是一个符号,指示计算机对一个或多个操作数执行特定操作。例如,在表达式 a + b 中,加号是运算符,a 和 b 是操作数。

    Classification matters because different operator groups have different precedence, associativity and return types. A combined expression such as x + 2 > y AND z = 3 uses arithmetic, comparison and logical operators together.

    分类很重要,因为不同类型的运算符具有不同的优先级、结合性和返回类型。像 x + 2 > y AND z = 3 这样的组合表达式同时使用了算术、比较和逻辑运算符。

    • Arithmetic operators: +, -, *, /, DIV, MOD, exponentiation | 算术运算符
    • Comparison operators: =, ≠, <, >, ≤, ≥ | 比较运算符
    • Logical operators: AND, OR, NOT | 逻辑运算符
    • Assignment operators: ←, =, +=, -= | 赋值运算符

    2. Arithmetic Operators | 算术运算符

    Arithmetic operators produce numeric results. The most common are +, -, *, /, DIV, MOD and exponentiation. In Python, / gives a float result while // gives integer floor division.

    算术运算符产生数值结果。最常见的有 +、-、*、/、DIV、MOD 和幂运算。在 Python 中,/ 给出浮点数结果,而 // 给出整数向下取整除法。

    Integer division and modulo are essential for problems involving digits, remainders, cycling and parity. For example, 17 DIV 5 gives 3 and 17 MOD 5 gives 2.

    整数除法和取模对涉及数位、余数、循环和奇偶性的问题非常重要。例如,17 DIV 5 得到 3,17 MOD 5 得到 2。

    17 DIV 5 = 3  and  17 MOD 5 = 2

    Exponentiation is represented as ^ in pseudocode and ** in Python. For example, 2^3 or 2 ** 3 equals 8. This is used when calculating powers, growth or repeated multiplication.

    幂运算在伪代码中写作 ^,在 Python 中写作 **。例如,2^3 或 2 ** 3 等于 8。这在计算幂、增长或重复乘法时会用到。

    Unary operators such as a leading minus sign change the sign of a single operand. For example, -x + 3 means first take the negative of x, then add 3.

    一元运算符如前置负号会改变单个操作数的符号。例如,-x + 3 表示先取 x 的相反数,然后加上 3。


    3. Comparison and Relational Operators | 比较与关系运算符

    Comparison operators compare two values and return a Boolean result: TRUE or FALSE. The main operators are =, ≠, <, >, ≤ and ≥.

    比较运算符比较两个值并返回布尔结果:TRUE 或 FALSE。主要运算符有 =、≠、<、>、≤ 和 ≥。

    In Python, equality is written as == while pseudocode often uses =. Inequality uses != in Python and ≠ or <> in some pseudocode styles. Mixing up = and == is a common exam error.

    在 Python 中,等于写作 ==,而伪代码常用 =。不等于在 Python 中用 !=,在部分伪代码中写作 ≠ 或 <>。混淆 = 和 == 是考试中的常见错误。

    Relational expressions can compare numbers, characters and sometimes strings using the underlying Unicode or ASCII ordering. For example, ‘A’ < ‘B’ is TRUE because A has a lower code point than B.

    关系表达式可以比较数字、字符,有时也可以按底层 Unicode 或 ASCII 顺序比较字符串。例如,’A’ < ‘B’ 为 TRUE,因为 A 的码点低于 B。

    A comparison always evaluates to one of two Boolean values. This is why it is often used inside IF, WHILE or REPEAT conditions to control program flow.

    比较运算的结果总是两个布尔值之一。这就是为什么它经常用于 IF、WHILE 或 REPEAT 条件中,以控制程序的执行流程。


    4. Logical Operators | 逻辑运算符

    Logical operators combine Boolean values and return a Boolean result. The Edexcel pseudocode uses AND, OR and NOT, while Python uses and, or and not.

    逻辑运算符组合布尔值并返回布尔结果。Edexcel 伪代码使用 AND、OR 和 NOT,Python 使用 and、or 和 not。

    AND returns TRUE only when both operands are TRUE. OR returns TRUE when at least one operand is TRUE. NOT reverses a single Boolean value.

    AND 仅在两个操作数都为 TRUE 时返回 TRUE。OR 在至少一个操作数为 TRUE 时返回 TRUE。NOT 反转单个布尔值。

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Edexcel A-Level Programming: Core Concepts and Exam Skills | Edexcel A-Level 编程:核心概念与考试技巧

    📚 Edexcel A-Level Programming: Core Concepts and Exam Skills | Edexcel A-Level 编程:核心概念与考试技巧

    This bilingual revision guide covers the programming topics examined in the Pearson Edexcel A-Level Computer Science specification, including the skills practised in ActiveLearn programming resources. It is designed for quick review and exam preparation.

    本双语复习指南涵盖 Pearson Edexcel A-Level 计算机科学考试中的编程主题,包括 ActiveLearn 编程资源中练习的技能。它旨在用于快速复习和备考。


    1. Programming Paradigms and Edexcel Expectations | 编程范式与 Edexcel 要求

    Edexcel A-Level Programming questions expect you to understand both procedural/imperative programming and object-oriented programming. Imperative programming uses statements that directly change the program state, such as assignment, loops and conditional branches.

    Edexcel A-Level 编程题目要求你理解过程式/命令式编程和面向对象编程。命令式编程使用直接改变程序状态的语句,例如赋值、循环和条件分支。

    Object-oriented programming organises code around classes and objects rather than actions alone. This distinction is important when you are asked to compare programming paradigms or select an appropriate structure for a given problem.

    面向对象编程围绕类和对象而不是仅仅围绕动作来组织代码。当你被要求比较编程范式或为给定问题选择合适结构时,这种区别非常重要。


    2. Sequence, Selection and Iteration | 顺序、选择和迭代

    The three fundamental control structures are sequence, selection and iteration. Sequence means statements run one after another in the order they are written.

    三种基本控制结构是顺序、选择和迭代。顺序意味着语句按照书写顺序一条接一条执行。

    Selection uses conditions to branch: IF, ELSE IF and ELSE (or CASE/SWITCH) allow different code paths. Iteration repeats a block: definite iteration uses FOR, while indefinite iteration uses WHILE or REPEAT…UNTIL.

    选择使用条件来分支:IF、ELSE IF 和 ELSE(或 CASE/SWITCH)允许不同的代码路径。迭代重复一个代码块:定次迭代使用 FOR,而不定次迭代使用 WHILE 或 REPEAT…UNTIL。

    When tracing pseudocode, always record the value of the condition at each step and update a trace table after every statement.

    追踪伪代码时,始终记录每一步的条件值,并在每条语句之后更新跟踪表。


    3. Variables, Constants and Data Types | 变量、常量与数据类型

    Variables are named storage locations whose values can change while a program runs. Constants are named values that cannot be changed after being assigned, which improves readability and prevents accidental modification.

    变量是命名的存储位置,其值在程序运行时可以改变。常量是赋值后不能更改的命名值,这提高了可读性并防止意外修改。

    Edexcel programming papers commonly use these data types: integer, real/float, Boolean, character and string. Knowing the difference is essential for type conversion, arithmetic and comparisons.

    Edexcel 编程试卷通常使用以下数据类型:整型、实数/浮点型、布尔型、字符和字符串。理解它们之间的区别对于类型转换、算术运算和比较至关重要。

  • A B A AND B A OR B NOT A
    TRUE TRUE TRUE TRUE FALSE
    TRUE FALSE FALSE TRUE FALSE
    Data type | 数据类型 Example | 示例
    integer | 整型 42, -7
    real/float | 实数/浮点型 3.14, -0.5
    Boolean | 布尔型 TRUE, FALSE
    character | 字符 ‘A’, ‘7’
    string | 字符串 “hello”

    4. Functions and Procedures | 函数与过程

    A procedure is a subroutine that carries out a task but does not return a value. A function is a subroutine that returns a single value using a RETURN statement.

    过程是执行任务但不返回值的子程序。函数是使用 RETURN 语句返回单个值的子程序。

    Using well-named subroutines makes a program modular, easier to test and reusable. In Edexcel pseudocode, functions are often written as FUNCTION name(…) RETURN … ENDFUNCTION.

    使用命名良好的子程序使程序模块化、更易于测试和重用。在 Edexcel 伪代码中,函数通常写作 FUNCTION name(…) RETURN … ENDFUNCTION。


    5. Parameter Passing and Scope | 参数传递与作用域

    Parameters let subroutines receive data. Passing by value copies the value into the subroutine, so changes inside do not affect the original variable. Passing by reference passes the memory location, so changes inside do affect the original variable.

    参数让子程序接收数据。按值传递将值复制到子程序中,因此内部的更改不会影响原始变量。按引用传递传递的是内存地址,因此内部的更改会影响原始变量。

    Scope defines where a variable can be accessed. Local variables

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Operators and Expressions in Programming | 编程中的运算符与表达式

    📚 Operators and Expressions in Programming | 编程中的运算符与表达式

    In A-Level programming, a large part of your success depends on how precisely you can write and evaluate expressions. Operators are the symbols that tell the computer what action to perform on one or more operands, while expressions combine operators, operands, and function calls into values.

    在 A-Level 编程中,能否准确书写和求值表达式在很大程度上决定了你的成绩。运算符是告诉计算机对一个或多个操作数执行什么操作的符号,而表达式将运算符、操作数和函数调用组合成值。


    1. Operators as Fundamental Building Blocks | 运算符是基本构建块

    In Edexcel A-Level Computer Science, a program is built from statements, and most statements contain expressions. An expression is a combination of operators, operands, constants, variables, and function calls that the program evaluates to produce a value. For example, in ‘total + 5’, ‘total’ and ‘5’ are operands, ‘+’ is the operator, and the whole line forms an expression. Operators are classified into arithmetic, relational, logical, bitwise, and assignment operators. Understanding these categories is essential because exam questions often ask you to trace code, simplify Boolean expressions, or spot errors in operator use.

    在 Edexcel A-Level 计算机科学中,程序由语句组成,而大多数语句都包含表达式。表达式是运算符、操作数、常量、变量和函数调用的组合,程序对它们求值以产生一个值。例如,在 ‘total + 5′ 中,’total’ 和 ‘5’ 是操作数,’+’ 是运算符,整行构成一个表达式。运算符分为算术、关系、逻辑、位和赋值运算符。理解这些类别非常重要,因为考试题经常要求你跟踪代码、简化布尔表达式或找出运算符使用中的错误。

    Arithmetic operators perform calculations, relational operators compare values, logical operators combine Boolean conditions, and assignment operators store results. Each category has its own syntax rules and expected operand types, so recognising which category a symbol belongs to is the first step in any trace-table or code-correction task.

    算术运算符执行计算,关系运算符比较值,逻辑运算符组合布尔条件,赋值运算符存储结果。每一类都有各自的语法规则和预期操作数类型,因此识别符号属于哪一类是所有跟踪表或代码修正任务的第一步。


    2. Arithmetic Operators and Integer Division | 算术运算符与整数除法

    The core arithmetic operators are addition ‘+’, subtraction ‘−’, multiplication ‘×’, real division ‘/’, integer division ‘DIV’, and exponentiation ‘^’. In Edexcel pseudo code, integer division ‘DIV’ returns the whole-number part of a quotient, discarding the remainder. For example, 17 DIV 5 gives 3, while 17 / 5 gives 3.4. Python uses ‘//’ for integer division and ‘/’ for real division, so the same values would be written as 17 // 5 and 17 / 5. Many students lose marks by using ‘/’ when the question requires whole-number division, especially when counting complete groups or pages.

    核心算术运算符包括加法 ‘+’、减法 ‘−’、乘法 ‘×’、实数除法 ‘/’、整数除法 ‘DIV’ 和指数 ‘^’。在 Edexcel 伪代码中,整数除法 ‘DIV’ 返回商的整数部分并舍弃余数。例如,17 DIV 5 得到 3,而 17 / 5 得到 3.4。Python 使用 ‘//’ 表示整数除法、’/’ 表示实数除法,因此同样的值可以写为 17 // 5 和 17 / 5。很多学生在题目要求整数除法时误用了 ‘/’,尤其是在统计完整组数或页数时容易失分。

    17 DIV 5 = 3, 17 MOD 5 = 2

    Exponentiation is written as ‘^’ in pseudo code, such as 2^3 = 8, while Python uses ‘**’. Be careful to distinguish exponentiation from multiplication and to apply it before DIV or MOD unless brackets indicate otherwise. In A-Level questions, integer division is frequently used to split a total into whole parts, for example converting minutes into hours and minutes: ‘hours ← totalMinutes DIV 60’ and ‘remainingMinutes ← totalMinutes MOD 60’.

    伪代码中指数写作 ‘^’,例如 2^3 = 8,而 Python 使用 ‘**’。注意区分指数与乘法,并在没有括号指示的情况下先于 DIV 或 MOD 计算。在 A-Level 题目中,整数除法经常用于将总数拆分为整份,例如将分钟转换为小时和分钟:’hours ← totalMinutes DIV 60’ 以及 ‘remainingMinutes ← totalMinutes MOD 60’。


    3. Modulus and Its Applications | 取模运算及其应用

    The modulus operator ‘MOD’ returns the remainder after integer division. It is extremely useful for determining divisibility, cycling through lists, and pattern-finding. For example, 17 MOD 5 returns 2 because 5 goes into 17 three times with 2 left over. A typical exam question might ask you to write a condition to test whether a number is even: ‘IF number MOD 2 = 0 THEN’. Modulus is also widely used to wrap an index around an array: ‘index ← (index + 1) MOD length’.

    取模运算符 ‘MOD’ 返回整数除法后的余数。它在判断整除性、循环遍历列表和查找规律时非常有用。例如,17 MOD 5 返回 2,因为 5 进入 17 三次后余 2。常见考试题可能要求你写出判断一个数是否为偶数的条件:’IF number MOD 2 = 0 THEN’。取模还广泛用于将数组索引回绕:’index ← (index + 1) MOD length’。

    When working with integer division and modulus, the relationship is: dividend = divisor × quotient + remainder. This means ’17 = 5 × 3 + 2′. Understanding this relationship helps you predict the result of MOD and check whether a calculation is correct. In trace-table tasks, each MOD step should be written out separately to avoid arithmetic mistakes.

    在处理整数除法和取模

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Mastering Programming Techniques for Edexcel A-Level Computer Science | 掌握 Edexcel A-Level 计算机科学编程技巧

    📚 Mastering Programming Techniques for Edexcel A-Level Computer Science | 掌握 Edexcel A-Level 计算机科学编程技巧

    Programming is at the heart of Edexcel A-Level Computer Science. To succeed, you need to move beyond writing code that merely works and understand the paradigms, data structures, algorithms, and efficiency concerns that examiners expect.

    编程是 Edexcel A-Level 计算机科学的核心。要想取得好成绩,你不能只满足于写出能运行的代码,还需要理解考纲要求的编程范式、数据结构、算法以及效率问题。

    1. Programming Paradigms: An Overview | 编程范式概述

    A programming paradigm is a fundamental style or approach to structuring code. Edexcel expects you to compare procedural, object-oriented, and functional paradigms, recognising where each is most suitable.

    编程范式是组织代码的基本风格或方法。Edexcel 要求你比较过程式、面向对象和函数式范式,并识别每种范式最适合的场景。

    Procedural programming uses step-by-step instructions and shared state; object-oriented programming organises code around objects with state and behaviour; functional programming treats computation as evaluation of mathematical functions and avoids mutable state.

    过程式编程使用逐步指令和共享状态;面向对象编程围绕具有状态和行为的对象组织代码;函数式编程将计算视为数学函数的求值,并避免可变状态。


    2. Procedural Programming: Sequence, Selection, Iteration | 过程式编程:顺序、选择、迭代

    Procedural programming is built on three control structures: sequence, selection, and iteration. Sequence means statements execute in the order written.

    过程式编程建立在三种控制结构之上:顺序、选择和迭代。顺序意味着语句按照编写顺序执行。

    Selection uses IF, ELSE IF, and ELSE statements to branch based on conditions. Iteration uses FOR, WHILE, or REPEAT loops to repeat blocks until a condition changes.

    选择使用 IF、ELSE IF 和 ELSE 语句根据条件分支。迭代使用 FOR、WHILE 或 REPEAT 循环重复代码块,直到条件发生变化。

    In Edexcel pseudocode, assignment is often written with an arrow or equals sign, and indentation shows block structure clearly.

    在 Edexcel 伪代码中,赋值常用箭头或等号表示,缩进清晰展示代码块结构。


    3. Object-Oriented Programming: Classes and Objects | 面向对象编程:类与对象

    A class is a blueprint that defines attributes and methods. An object is an instance of a class, created at runtime.

    类是定义属性和方法的模板。对象是类的实例,在运行时创建。

    Key OOP concepts include encapsulation, inheritance, polymorphism, and association. Encapsulation hides internal state; inheritance allows a subclass to reuse and extend a parent class; polymorphism lets different classes respond to the same method name.

    面向对象的关键概念包括封装、继承、多态和关联。封装隐藏内部状态;继承允许子类重用并扩展父类;多态让不同类对同一方法名做出不同响应。

    You may need to interpret UML-style class diagrams or write simple class definitions in pseudocode, showing private and public members.

    你可能需要解读 UML 风格的类图,或用伪代码编写简单的类定义,标明私有和公有成员。


    4. Functional Programming: Pure Functions and Immutability | 函数式编程:纯函数与不可变性

    Functional programming emphasises pure functions: functions whose output depends only on their inputs and which have no side effects.

    函数式编程强调纯函数:输出只取决于输入,并且没有副作用。

    Immutability means data cannot be changed after it is created. Instead of modifying a list, you create a new list. This reduces bugs caused by unexpected state changes.

    不可变性意味着数据创建后不能被修改。你不是修改列表,而是创建一个新列表。这减少了由意外状态变化引起的错误。

    Higher-order functions such as map, filter, and reduce are common in functional programming. A higher-order function takes another function as an argument or returns a function.

    高阶函数(如 map、filter 和 reduce)在函数式编程中很常见。高阶函数接受另一个函数作为参数,或返回一个函数。


    5. Data Types and Type Checking | 数据类型与类型检查

    Edexcel requires knowledge of primitive data types: integer, real/float, Boolean, character, and string. Choosing the correct type affects storage and operations.

    Edexcel 要求掌握基本数据类型:整数、实数/浮点数、布尔、字符和字符串。选择正确的类型会影响存储和运算。

    Static typing checks types at compile time, while dynamic typing checks at runtime. A-Level pseudocode is usually considered strongly typed, so assigning a string to an integer variable is an error.

    静态类型在编译时检查类型,动态类型在运行时检查。A-Level 伪代码通常被视为强类型,因此将字符串赋给整数变量是错误的。

    You should understand type conversion functions such as int(), str(), float(), and bool(), and know when implicit coercion may occur.

    你应该理解 int()、str()、float() 和 bool() 等类型转换函数,并知道何时可能发生隐式强制转换。


    6. Control Structures and Boolean Logic | 控制结构与布尔逻辑

    Boolean expressions evaluate to TRUE or FALSE. Operators include AND, OR, NOT, and comparison operators such as =, ≠, less than, greater than, ≤, ≥.

    布尔表达式求值为 TRUE 或 FALSE。运算包括 AND、OR、NOT,以及 =、≠、小于、大于、≤、≥ 等比较运算。

    Truth tables are used to evaluate complex conditions. For example, A AND B is true only when both A and B are true; A OR B is true when at least one is true.

    真值表用于计算复杂条件。例如,A AND B 只有在 A 和 B 都为真时才为真;A OR B 在至少一个为真时为真。

    Nested IF statements can become difficult to read. Edexcel-style pseudocode often uses ELSE IF to avoid deep nesting and maintain clarity.

    嵌套 IF 语句可能难以阅读。Edexcel 风格伪代码常使用 ELSE IF 避免深层嵌套,保持清晰。


    7. Arrays, Lists and Records | 数组、列表与记录

    An array is a collection of elements of the same type, accessed by index, usually starting at 0 or 1 depending on the language/pseudocode convention.

    数组是相同类型元素的集合,通过索引访问,通常根据语言/伪代码约定从 0 或 1 开始。

    A list is a dynamic data structure that can grow or shrink. In Edexcel pseudocode, lists are often declared with square brackets, such as myList ← [5, 12, 8].

    列表是一种可以增长或缩小的动态数据结构。在 Edexcel 伪代码中,列表常用方括号声明,如 myList ← [5, 12, 8]

    A record is a composite data type that groups fields of possibly different types, similar to a row in a database table. Fields are accessed by name.

    记录是一种复合数据类型,将可能不同类型的字段组合在一起,类似于数据库表中的一行。字段按名称访问。

    Common list operations include append, insert, remove, length, and slicing. Examiners often test your ability to trace these operations.

    常见列表操作包括追加、插入、删除、求长度和切片。考官经常考查你是否能跟踪这些操作。


    8. Stacks and Queues | 栈与队列

    A stack is a last-in-first-out (LIFO) structure. The main operations are push to add an item, pop to remove the top item, and peek to inspect the top item without removing it.

    栈是一种后进先出(LIFO)结构。主要操作是 push 添加元素、pop 移除栈顶元素,以及 peek 查看栈顶元素而不移除。

    A queue is a first-in-first-out (FIFO) structure. Items are added at the rear and removed from the front, making queues useful for scheduling and buffers.

    队列是一种先进先出(FIFO)结构。元素在队尾加入,从队头移除,因此队列适用于调度和缓冲。

    You may be asked to simulate stack or queue operations with pointer variables, or to identify overflow when a fixed-size structure is full and underflow when it is empty.

    你可能被要求用指针变量模拟栈或队列操作,或在固定大小结构已满时识别溢出、为空时识别下溢。


    9. Recursion and Base Cases | 递归与基准情形

    Recursion is when a subroutine calls itself to solve a smaller instance of the same problem. A recursive algorithm must have at least one base case to stop the recursion.

    递归是指子程序调用自身来解决同一问题的较小实例。递归算法必须至少有一个基准情形来停止递归。

    A classic example is factorial: factorial(n) = n × factorial(n-1) with base case factorial(0) = 1. Without a base case, the recursion continues until a stack overflow occurs.

    经典例子是阶乘:factorial(n) = n × factorial(n-1),基准情形为 factorial(0) = 1。没有基准情形,递归会一直持续到栈溢出。

    Recursion can produce elegant solutions for tree traversal, binary search, and divide-and-conquer algorithms, but it may use more memory than iteration due to the call stack.

    递归可以为树遍历、二分查找和分治算法提供优雅的解决方案,但由于调用栈,它可能比迭代消耗更多内存。


    10. Algorithm Efficiency and Big O | 算法效率与大 O 记号

    Big O notation describes the upper bound of an algorithm’s time or space complexity as the input size n grows. It focuses on the dominant term and ignores constants.

    大 O 记号描述随着

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Edexcel A-Level Programming: Core Concepts and Practical Techniques | Edexcel A-Level 编程:核心概念与实践技巧

    📚 Edexcel A-Level Programming: Core Concepts and Practical Techniques | Edexcel A-Level 编程:核心概念与实践技巧

    Programming is at the heart of the Edexcel A-Level Computer Science specification. From mastering fundamental constructs to applying object-oriented design, students must demonstrate both theoretical understanding and practical coding skill.

    编程是 Edexcel A-Level 计算机科学考试的核心。从掌握基本结构到应用面向对象设计,学生必须同时展示理论理解和实际编码能力。


    1. Programming Paradigms | 编程范式

    Edexcel expects learners to recognise procedural, object-oriented and event-driven paradigms. Procedural programming breaks a task into step-by-step instructions, while object-oriented programming organises code around objects that combine data and behaviour.

    Edexcel 要求学习者识别过程式、面向对象和事件驱动范式。过程式编程将任务分解为逐步指令,而面向对象编程围绕结合数据与行为的对象来组织代码。

    Event-driven programming is common in graphical user interfaces, where code executes in response to events such as button clicks or key presses. Understanding these paradigms helps you choose the right structure for a given problem.

    事件驱动编程常见于图形用户界面,代码在按钮点击或按键等事件发生时执行。理解这些范式有助于你为给定问题选择正确结构。


    2. Data Types and Variables | 数据类型与变量

    Variables store values in memory, and every variable has a data type that determines what operations are valid. In Edexcel pseudocode, common types include integer, real, Boolean, character and string.

    变量在内存中存储值,每个变量都有决定有效操作的数据类型。在 Edexcel 伪代码中,常见类型包括整型、实型、布尔型、字符型和字符串型。

    • Integer: whole numbers such as -3, 0, 42
    • Real: decimal numbers such as 3.14, -0.5
    • Boolean: TRUE or FALSE
    • Character: a single symbol such as ‘A’, ‘7’, ‘#’
    • String: a sequence of characters such as ‘hello’

    Type conversion is often required, for example changing a string input into an integer before arithmetic. Careful type handling prevents runtime errors and data loss.

    类型转换常常是必需的,例如在算术运算前将字符串输入转换为整数。谨慎处理类型可以防止运行时错误和数据丢失。


    3. Sequence, Selection and Iteration | 顺序、选择与迭代

    The three building blocks of structured programming are sequence, selection and iteration. Sequence means statements are executed in order, one after another.

    结构化编程的三大构建块是顺序、选择和迭代。顺序意味着语句按顺序一条接一条执行。

    Selection allows branching using IF, ELSE IF and ELSE statements, or CASE/SWITCH structures. Iteration repeats code using FOR, WHILE or REPEAT UNTIL loops.

    选择允许使用 IF、ELSE IF 和 ELSE 语句或 CASE/SWITCH 结构进行分支。迭代使用 FOR、WHILE 或 REPEAT UNTIL 循环重复执行代码。

    WHILE condition DO … ENDWHILE

    This loop checks the condition before each pass, so it may execute zero times. A REPEAT UNTIL loop runs at least once because the condition is checked at the end.

    此循环在每次执行前检查条件,因此可能执行零次。REPEAT UNTIL 循环至少执行一次,因为条件在末尾检查。


    4. Procedures and Functions | 过程与函数

    Subroutines break large programs into manageable pieces. A procedure performs a task but does not return a value, while a function returns a value to the caller.

    子程序将大型程序分解为可管理的部分。过程执行任务但不返回值,而函数向调用者返回值。

    For example, a function calculateArea(radius) might return π × radius². A procedure displayMenu() might simply print options without returning data.

    例如,函数 calculateArea(radius) 可能返回 π × radius²。过程 displayMenu() 可能只打印选项而不返回数据。

    FUNCTION calculateArea(r) RETURN π × r²

    Using subroutines improves readability, reusability and testability. Edexcel questions often ask you to trace or write pseudocode for subroutines.

    使用子程序可提高可读性、可重用性和可测试性。Edexcel 试题经常要求你跟踪或编写子程序的伪代码。


    5. Parameter Passing | 参数传递

    Parameters allow data to be passed into subroutines. Edexcel distinguishes between passing by value and passing by reference.

    参数允许将数据传入子程序。Edexcel 区分按值传递和按引用传递。

    • By value: a copy of the value is passed; changes inside the subroutine do not affect the original variable.
    • By reference: the memory address is passed; changes affect the original variable.

    Passing by reference is useful when a subroutine needs to update multiple values or return modified data.

    当子程序需要更新多个值或返回修改后的数据时,按引用传递很有用。

    Example: swap(x, y) using reference parameters exchanges the values of x and y. Using value parameters would leave the originals unchanged.

    示例:使用引用参数的 swap(x, y) 交换 x 和 y 的值。使用值参数将保持原变量不变。


    6. Recursion and Stack Frames | 递归与栈帧

    Recursion is a technique where a subroutine calls itself to solve smaller instances of a problem. A base case stops the recursion; without one, infinite recursion causes a stack overflow.

    递归是一种子程序调用自身来解决更小问题实例的技术。基准情形停止递归;没有基准情形,无限递归会导致栈溢出。

    factorial(n) = n × factorial(n-1), where factorial(0) = 1

    Each recursive call creates a stack frame storing local variables and the return address. This explains why recursion uses more memory than simple iteration.

    每次递归调用都会创建一个栈帧,存储局部变量和返回地址。这解释了为什么递归比简单迭代使用更多内存。

    Edexcel may ask you to trace recursive algorithms such as Fibonacci or binary search. Always identify the base case and how the problem shrinks towards it.

    Edexcel 可能要求你跟踪递归算法,如斐波那契或二分查找。始终确定基准情形以及问题如何向基准情形缩小。


    7. Arrays, Lists and Records | 数组、列表与记录

    Data structures organise multiple values. A one-dimensional array stores elements of the same type under one identifier, accessed by index.

    数据结构组织多个值。一维数组在同一个标识符下存储相同类型的元素,通过索引访问。

    A two-dimensional array is often used to represent tables or matrices. For example, grid[2][3] refers to the element in row 2, column 3.

    二维数组常用于表示表格或矩阵。例如,grid[2][3] 指第 2 行第 3 列的元素。

    A record (or structure) groups related fields of different types, such as a student record containing name, age and grade. This supports organising complex data.

    记录(或结构)将不同类型的相关字段组合在一起,例如包含姓名、年龄和成绩的学生记录。这有助于组织复杂数据。


    8. File Handling and Exceptions | 文件处理与异常

    Programs often need to read from or write to files. Typical operations include opening a file, reading lines, writing data and closing the file.

    程序经常需要读取或写入文件。典型操作包括打开文件、读取行、写入数据和关闭文件。

    OPEN ‘data.txt’ FOR READ → READ line → CLOSE

    Exception handling catches runtime errors such as missing files or invalid data. Using TRY…EXCEPT…ENDTRY prevents the program from crashing and allows recovery.

    异常处理捕获运行时错误,如文件缺失或无效数据。使用 TRY…EXCEPT…ENDTRY 可防止程序崩溃并允许恢复。

    Edexcel pseudocode uses a clear syntax for file operations. Always close files to release system resources and avoid data corruption.

    Edexcel 伪代码使用清晰的文件操作语法。始终关闭文件以释放系统资源并避免数据损坏。


    9. Object-Oriented Programming | 面向对象编程

    Object-oriented programming (OOP) models real-world entities as objects. A class defines attributes (data) and methods (behaviour), and objects are instances of that class.

    面向对象编程将现实世界实体建模为对象。类定义属性(数据)和方法(行为),对象是该类的实例。

    Key OOP principles include encapsulation, inheritance and polymorphism. Encapsulation hides internal details; inheritance allows a subclass to reuse and extend a superclass; polymorphism lets objects of different classes respond to the same method call.

    关键的面向对象原则包括封装、继承和多态。封装隐藏内部细节;继承允许子类重用和扩展超类;多态允许不同类的对象响应相同的方法调用。

    Concept Meaning
    Encapsulation Bundling data and methods, restricting direct access.
    Inheritance Creating new classes from existing classes.
    Polymorphism Same interface, different behaviour based on object type.

    Understanding OOP helps in designing maintainable systems and is central to many Edexcel programming questions.

    理解面向对象编程有助于设计可维护的系统,并且是许多 Edexcel 编程问题的核心。


    10. Debugging, Testing and Trace Tables | 调试、测试与跟踪表

    Thorough testing is essential for reliable programs. Edexcel expects you to use normal, boundary and erroneous test data to validate algorithms.

    彻底的测试对于可靠程序至关重要。Edexcel 期望你使用正常、边界和错误测试数据来验证算法。

    • Normal data: typical valid inputs
    • Boundary data: values at the edge of acceptable ranges
    • Erroneous data: invalid inputs that should be rejected

    A trace table records line numbers, variable values and outputs as an algorithm runs. It helps identify logic errors and is a common exam technique.

    跟踪表在算法运行时记录行号、变量值和输出。它有助于识别逻辑错误,是常见的考试技巧。

    Line | variable | output

    Debugging involves locating and correcting errors. Use breakpoints, print statements and step-through tracing to isolate faults systematically.

    调试涉及定位和纠正错误。使用断点、打印语句和逐步跟踪来系统地隔离故障。


    Published by TutorHao | Programming Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Object-Oriented Programming: Classes, Objects, and Inheritance | 面向对象编程:类、对象与继承

    📚 Object-Oriented Programming: Classes, Objects, and Inheritance | 面向对象编程:类、对象与继承

    Object-oriented programming (OOP) is a programming paradigm that organises software design around objects rather than functions and logic. In Edexcel A-Level Computer Science, you need to understand how classes act as blueprints, how objects are instantiated, and how inheritance and polymorphism support code reuse.

    面向对象编程(OOP)是一种围绕对象而非函数和逻辑来组织软件设计的编程范式。在 Edexcel A-Level 计算机科学中,你需要理解类如何充当蓝图、对象如何实例化,以及继承和多态如何支持代码复用。


    1. Programming Paradigms and the Rise of OOP | 编程范式与面向对象编程的兴起

    A programming paradigm is a style or way of thinking about software construction. Procedural programming uses step-by-step procedures, while declarative programming states what should be achieved without specifying every control flow detail.

    编程范式是一种构建软件的思维方式或风格。面向过程的编程使用逐步执行的过程,而声明式编程只说明需要实现什么,不指定每个控制流细节。

    OOP introduces classes and objects so that data and the methods that operate on that data are bundled together. This makes large systems easier to model, debug, and extend.

    OOP 引入了类和对象,使数据以及操作这些数据的方法被捆绑在一起。这使得大型系统更容易建模、调试和扩展。

    In the Edexcel specification, you may be asked to explain why OOP is suitable for simulations, games, or GUI applications where real-world entities have clear attributes and behaviours.

    在 Edexcel 大纲中,你可能会被要求解释为什么 OOP 适合模拟、游戏或 GUI 应用,因为这些场景中的现实世界实体具有清晰的属性和行为。


    2. Classes and Objects: Blueprint and Instance | 类与对象:蓝图与实例

    A class is a template that defines the attributes and methods common to all objects of a certain kind. An object is a concrete instance of a class, created at runtime.

    类是定义某一类对象共有的属性和方法的模板。对象是类的具体实例,在运行时创建。

    For example, a class Car may define attributes such as colour and speed, and methods such as accelerate() and brake(). The object myCar = Car(“red”) is one particular car with its own state.

    例如,类 Car 可以定义 colour 和 speed 等属性,以及 accelerate() 和 brake() 等方法。对象 myCar = Car(“red”) 是一辆具有自身状态的特定汽车。

    • Class = blueprint or template. | 类 = 蓝图或模板。

    • Object = instance with concrete values. | 对象 = 具有具体值的实例。

    • Instantiation = the process of creating an object from a class. | 实例化 = 从类创建对象的过程。


    3. Attributes: Data Stored Inside an Object | 属性:对象中存储的数据

    Attributes are variables that belong to an object. They store the state of the object and can be public, private, or protected depending on the programming language and access modifiers.

    属性是属于对象的变量。它们存储对象的状态,根据编程语言和访问修饰符,可以是公开的、私有的或受保护的。

    In pseudocode for Edexcel, attributes are often declared at the top of a class. For example: PRIVATE colour : STRING.

    在 Edexcel 的伪代码中,属性通常在类的顶部声明。例如:PRIVATE colour : STRING。

    When an object is created, each attribute receives its own copy in memory, so two Car objects can have different colour values.

    当对象被创建时,每个属性在内存中都会获得自己的副本,因此两个 Car 对象可以有不同的 colour 值。


    4. Methods: Behaviour Defined by a Class | 方法:类定义的行为

    Methods are functions defined inside a class that describe what an object can do. They can access and modify the object’s attributes.

    方法是定义在类内部的函数,描述对象能够执行的操作。它们可以访问和修改对象的属性。

    A method signature includes its name, parameters, and return type. In OOP, methods are invoked on an object using dot notation, such as myCar.accelerate(10).

    方法签名包括其名称、参数和返回类型。在 OOP 中,方法通过点表示法在对象上调用,例如 myCar.accelerate(10)。

    Methods can be public for external use or private for internal helper tasks. This distinction supports encapsulation.

    方法可以是公开的供外部使用,也可以是私有的用于内部辅助任务。这种区分支持封装。


    5. Encapsulation: Protecting Data with Access Modifiers | 封装:用访问修饰符保护数据

    Encapsulation means hiding the internal state of an object and only allowing access through a controlled interface. In many languages this is achieved with private attributes and public getter/setter methods.

    封装意味着隐藏对象的内部状态,只允许通过受控接口访问。在许多语言中,这通过私有属性和公共的 getter/setter 方法实现。

    Encapsulation protects data integrity. For example, a setter for speed can reject negative values, preventing an invalid state.

    封装保护数据的完整性。例如,speed 的 setter 可以拒绝负值,从而防止无效状态。

    Access modifier | 访问修饰符 Meaning | 含义
    Public | 公开 Accessible from anywhere | 任何地方都可访问
    Private | 私有 Only accessible inside the class | 只能在类内部访问
    Protected | 受保护 Accessible in the class and its subclasses | 类及其子类中可访问

    In Edexcel pseudocode, you may be asked to rewrite code to make an attribute private and add getters/setters, so practise this pattern.

    在 Edexcel 伪代码中,你可能会被要求改写代码,将属性设为私有并添加 getter/setter,因此请练习这种模式。


    6. Inheritance: Reusing and Extending Classes | 继承:复用和扩展类

    Inheritance allows a new class (subclass) to adopt the attributes and methods of an existing class (superclass). This promotes code reuse and establishes an “is-a” relationship.

    继承允许新类(子类)采用现有类(超类)的属性和方法。这促进了代码复用,并建立了 “is-a” 关系。

    A subclass can add new attributes and methods, or override inherited methods to provide specialised behaviour. For example, ElectricCar can inherit from Car and add batteryCapacity.

    子类可以添加新的属性和方法,或重写继承的方法以提供专门的行为。例如,ElectricCar 可以继承自 Car 并添加 batteryCapacity。

    In pseudocode, inheritance is often shown with a colon or keyword INHERITS. In Python, class ElectricCar(Car) means ElectricCar is a subclass of Car.

    在伪代码中,继承通常用冒号或关键字 INHERITS 表示。在 Python 中,class ElectricCar(Car) 表示 ElectricCar 是 Car 的子类。

    Be careful: inheritance should only be used when there is a genuine is-a relationship. A Car has an Engine, so engine should be an attribute, not a subclass.

    注意:只有当存在真正的 is-a 关系时才应使用继承。汽车有一个引擎,因此引擎应该是属性,而不是子类。


    7. Polymorphism: One Interface, Many Implementations | 多态:一个接口,多种实现

    Polymorphism allows objects of different classes to respond to the same method call in different ways. This is often achieved through method overriding.

    多态允许不同类的对象以不同的方式响应相同的方法调用。这通常通过方法重写来实现。

    For example, a base class Shape may define a method area(), and subclasses Circle and Rectangle each override area() with their own formulas.

    例如,基类 Shape 可以定义方法 area(),子类 Circle 和 Rectangle

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Mastering A-Level Edexcel Programming: Algorithms, Data Structures and Problem Solving | 掌握A-Level Edexcel编程:算法、数据结构与问题求解

    📚 Mastering A-Level Edexcel Programming: Algorithms, Data Structures and Problem Solving | 掌握A-Level Edexcel编程:算法、数据结构与问题求解

    Programming in the Edexcel A-Level Computer Science specification is not just about remembering syntax. It tests your ability to break down problems, choose suitable data structures, trace code accurately, and evaluate algorithm efficiency. This revision guide walks through the programming core topics that appear in Paper 2 and the non-exam assessment, with bilingual explanations and exam-focused examples.

    Edexcel A-Level 计算机科学大纲中的编程不只是记忆语法。它考查你分解问题、选择合适数据结构、精确跟踪代码以及评估算法效率的能力。本复习指南按双语讲解和考点示例,梳理 Paper 2 与非考试评估中最常出现的编程核心主题。


    1. Computational Thinking and Problem Decomposition | 计算思维与问题分解

    Computational thinking involves abstraction, decomposition, pattern recognition and algorithmic thinking. For any extended programming question, examiners expect you to identify subproblems before writing code.

    计算思维包括抽象、分解、模式识别和算法思维。对于任何较长编程题,考官希望你在写代码前先识别子问题。

    In an Edexcel coding question, you should first decompose the problem into clear modules such as input validation, core calculation and formatted output. This makes your solution easier to trace, test and mark.

    在 Edexcel 编程题中,你应先把问题分解为清晰的模块,例如输入验证、核心计算和格式化输出。这会让你的解决方案更容易跟踪、测试和得分。

    Thinking technique What it means in code
    Abstraction Keep only relevant details, such as modelling a student as name, ID and score
    Decomposition Split input, processing, output and validation into separate sections
    Pattern recognition Reuse known solutions for similar tasks such as finding max or counting matches
    Algorithmic thinking Write step-by-step instructions that solve the whole problem

    The table shows how each thinking technique connects directly to exam evidence. Always label your modules clearly in pseudocode answers.

    上表展示了每种思维技巧如何直接关联考试得分点。在伪代码答案中要始终清晰标注模块。


    2. Programming Paradigms: Imperative, Procedural and Object-Oriented | 编程范式:命令式、过程式与面向对象

    Edexcel questions may ask you to compare imperative, procedural, object-oriented and declarative paradigms. You must link each paradigm to code structure rather than just define it.

    Edexcel 题目可能要求比较命令式、过程式、面向对象和声明式范式。你必须将每种范式与代码结构联系起来,而不只是给出定义。

    Imperative code changes program state step by step. Procedural code organises those steps into subroutines. Object-oriented code groups data and behaviour into classes, while declarative code describes what the result should be rather than how to compute it.

    命令式代码逐步改变程序状态。过程式代码将这些步骤组织成子程序。面向对象代码将数据和行为封装到类中,而声明式代码描述结果是什么,而不是如何计算。

    Paradigm Key feature Typical use
    Imperative Instructions change state step by step Simple scripts, control flow
    Procedural Organised into subroutines and functions Structured programs, modular design
    Object-oriented Classes, objects, encapsulation, inheritance Large systems, simulations
    Declarative Describes what the result should be, not how SQL, functional logic

    For exam answers, choose one paradigm as your main structure and state why it fits the problem. Avoid mixing unrelated paradigm language without explanation.

    考试作答时,选择一种范式作为主要结构,并说明为什么它适合该问题。避免没有解释地混用不同范式的术语。


    3. Variables, Constants and Data Types | 变量、常量与数据类型

    Choose data types carefully: integer, real/float, Boolean, character, string, and date/time are common in pseudocode. Constants should be declared once and used to avoid magic numbers.

    仔细选择数据类型:整数、实数/浮点、布尔、字符、字符串和日期/时间在伪代码中很常见。常量应只声明一次,用于避免魔法数字。

    A magic number is a hard-coded value such as 0.2 or 100 that appears without explanation. Replacing it with a named constant, for example VAT_RATE ← 0.2, improves readability and maintenance.

    魔法数字是指没有解释就硬编码的值,例如 0.2 或 100。用命名常量替换它,例如 VAT_RATE ← 0.2,可以提高可读性和可维护性。

    Data type Example Use
    Integer 17, -4 Counts, indexes
    Real/float 3.14, -0.5 Measurements, money
    Boolean TRUE, FALSE Flags, comparisons
    Character ‘A’, ‘7’ Single symbol handling
    String “TutorHao” Text, names, IDs

    In pseudocode, declare constants at the top and use meaningful identifiers. This shows examiners that you understand scope and maintainability.

    在伪代码中,在开头声明常量并使用有意义的标识符。这向考官展示你理解作用域和可维护性。


    4. Control Structures: Sequence, Selection and Iteration | 控制结构:顺序、选择与迭代

    Sequence, selection and iteration form the foundation of any algorithm. Use selection for decisions and iteration for repetition.

    顺序、选择和迭代构成任何算法的基础。决策使用选择结构,重复使用迭代结构。

    Selection includes IF-THEN, IF-THEN-ELSE and CASE statements. Iteration includes count-controlled FOR loops and condition-controlled WHILE or REPEAT-UNTIL loops.

    选择结构包括 IF-THEN、IF-THEN-ELSE 和 CASE 语句。迭代结构包括计数控制的 FOR 循环和条件控制的 WHILE 或 REPEAT-UNTIL 循环。

    IF score ≥ 70 THEN grade ← ‘A’ ELSE IF score ≥ 50 THEN grade ← ‘B’ ELSE grade ← ‘C’ END IF

    The above pseudocode shows nested selection. When tracing, update the condition outcome before assigning the result, because Edexcel mark schemes reward correct logic flow.

    上面的伪代码展示了嵌套选择。跟踪时,先更新条件结果再赋值,因为 Edexcel 评分标准奖励正确的逻辑流。

    For iteration, choose a FOR loop when the number of repetitions is known in advance. Use a WHILE loop when the repetition depends on a condition that may change inside the loop.

    当重复次数事先已知时,使用 FOR 循环。当重复依赖循环内可能变化的条件时,使用 WHILE 循环。


    5. Subroutines, Parameters and Return Values | 子程序、参数与返回值

    A subroutine is a named block of code that can be called. Functions return a value; procedures do not. Parameters can be passed by value or by reference.

    子程序是可调用的命名代码块。函数返回值;过程不返回值。参数可以按值或按引用传递。

    Pass by value copies the argument into the parameter, so changes inside the subroutine do not affect the original variable. Pass by reference gives the subroutine access to the original memory location, so changes are reflected outside.

    按值传递将实参复制到形参,因此子程序内部的更改不会影响原变量。按引用传递让子程序访问原始内存位置,因此更改会反映到外部。

    FUNCTION CalculateArea(r) RETURN 3.14159 × r² END FUNCTION

    This function takes one parameter r and returns a real value. The identifier is clear, and the calculation is isolated, making the code reusable and testable.

    该函数接受一个参数 r 并返回一个实数值。标识符清晰,计算被隔离,使代码可重用且可测试。

    In pseudocode answers, you should show the FUNCTION or PROCEDURE header, parameter list and return type where relevant. This is often required for top-band marks.

    在伪代码答案中,你应写出 FUNCTION 或 PROCEDURE 头、参数列表以及相关的返回类型。这通常是获得高分档所必需的。


    6. Recursion and the Call Stack | 递归与调用栈

    Recursion is a function calling itself with a smaller problem. Each call is placed on the call stack until a base case is reached.

    递归是函数调用自身处理更小的子问题。每次调用都被压入调用栈,直到达到基准情形。

    A recursive algorithm must have at least one base case to stop the chain. If the base case is missing or unreachable, the recursion will cause stack overflow.

    递归算法必须至少有一个基准情形来停止调用链。如果基准情形缺失或不可达,递归将导致栈溢出。

    F(n) = F(n−1) + F(n−2) where F(0) = 0, F(1) = 1

    This Fibonacci recurrence shows how a large problem depends on smaller subproblems. Tracing recursion requires you to record each call and its return value in a call-stack table.

    这个斐波那契递推式展示了较大的问题如何依赖较小的子问题。跟踪递归需要在调用栈表中记录每次调用及其返回值。

    Recursion is elegant but not always efficient. Repeated Fibonacci calls recalculate the same values, so an iterative solution or memoisation may be better for large n.

    递归很优雅,但不一定高效。斐波那契的重复调用会重新计算相同的值,因此对于较大的 n,迭代解或记忆化可能更好。


    7. Data Structures: Arrays, Lists, Stacks and Queues | 数据结构:数组、列表、栈与队列

    Know the operations and typical uses of static arrays, dynamic arrays, linked lists, stacks (LIFO) and queues (FIFO). Edexcel often asks about stack frames and queue scheduling.

    掌握静态数组、动态数组、链表、栈(后进先出)和队列(先进先出)的操作和典型用途。Edexcel 常考栈帧和队列调度。

    Arrays provide O(1) indexed access but fixed size. Dynamic lists allow append operations, while linked lists support efficient insertion at known positions but require O(n) search.

    数组提供 O(1) 的索引访问,但大小固定。动态列表允许追加操作,而链表在已知位置插入时效率很高,但查找需要 O(n)。

    Data structure Key operations Typical use
    Static array Indexed read/write O(1), fixed size Lookup tables
    Dynamic listPublished by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Edexcel A-Level Programming: Core Constructs and Paradigms | 爱德思A-Level编程:核心结构与编程范式

    📚 Edexcel A-Level Programming: Core Constructs and Paradigms | 爱德思A-Level编程:核心结构与编程范式

    This revision guide covers the essential programming concepts required for the Edexcel A-Level Computer Science specification. It explains core constructs, data structures, paradigms and exam technique using clear pseudocode conventions. Master these topics to write accurate algorithms, trace code confidently and justify your programming choices under timed conditions.

    本复习指南涵盖爱德思A-Level计算机科学规范所要求的基本编程概念。它使用清晰的伪代码约定解释核心结构、数据结构、编程范式和考试技巧。掌握这些主题,你就能写出准确的算法、自信地追踪代码,并在限时条件下证明你的编程选择是正确的。


    1. Variables, Constants and Data Types | 变量、常量与数据类型

    A variable is a named storage location whose value can change during program execution. In contrast, a constant is a named value that cannot be modified after it is set. Edexcel questions often ask you to choose the correct data type for a given scenario, so you should be confident with integer, real/float, Boolean, character and string types.

    变量是一个命名的存储单元,其值在程序执行期间可以改变。相反,常量是一个一旦设定就不能修改的命名值。爱德思考试题经常要求你为给定场景选择正确的数据类型,因此你应熟练掌握整型、实数/浮点型、布尔型、字符型和字符串型。

    Data types determine the operations that can be performed and the amount of memory used. For example, an integer occupies a fixed number of bytes and supports arithmetic operations, while a string is a sequence of characters and supports concatenation and sub-string methods. Implicit and explicit type conversion, often called casting, is essential when calculating with mixed types.

    数据类型决定了可以执行的操作以及占用的内存大小。例如,整型占据固定字节数并支持算术运算,而字符串是字符序列并支持连接和子串方法。隐式和显式类型转换(通常称为强制转换)在混合类型计算时至关重要。

    Data Type Example Common Operations
    Integer 42 +, −, ×, DIV, MOD
    Real/Float 3.14 +, −, ×, ÷
    Boolean True / False AND, OR, NOT
    Character ‘A’ ordinal, comparison
    String “TutorHao” concatenation, length, sub-string

    2. Sequence, Selection and Iteration | 顺序、选择与迭代

    Every algorithm in the Edexcel specification is built from three fundamental control structures: sequence, selection and iteration. Sequence means statements are executed one after another. Selection allows a program to choose between different paths using conditions, typically through IF, ELSE IF and ELSE statements or a SWITCH/CASE structure.

    爱德思规范中的每个算法都由三种基本控制结构构成:顺序、选择和迭代。顺序意味着语句一条接一条地执行。选择允许程序使用条件在不同路径之间进行选择,通常通过 IF、ELSE IF 和 ELSE 语句或 SWITCH/CASE 结构实现。

    Iteration repeats a block of code either a fixed number of times or until a condition is met. Count-controlled loops such as FOR are useful when the number of repetitions is known in advance, while condition-controlled loops such as WHILE and DO…WHILE are suitable when the repetition depends on a runtime condition. You must be able to trace loop counters and boundary values in dry runs.

    迭代重复执行一段代码,重复次数可以是固定的,也可以由条件决定。计数控制循环(如 FOR)在重复次数预先已知时很有用,而条件控制循环(如 WHILE 和 DO…WHILE)适合重复取决于运行时条件

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Programming Fundamentals and Computational Thinking: Edexcel A-Level CS Revision | 编程基础与计算思维:Edexcel A-Level 计算机科学复习指南

    📚 Programming Fundamentals and Computational Thinking: Edexcel A-Level CS Revision | 编程基础与计算思维:Edexcel A-Level 计算机科学复习指南

    This guide brings together the core programming techniques tested in Edexcel A-Level Computer Science papers, focusing on practical tracing, algorithm design, data structures, and object-oriented principles. It is designed for quick revision and exam-style application.

    本指南汇集了 Edexcel A-Level 计算机科学试卷中考查的核心编程技术,重点包括实际代码追踪、算法设计、数据结构与面向对象原则,适合快速复习与考试应用。


    1. Data Types and Variables | 数据类型与变量

    Every program stores and manipulates data using typed variables. Edexcel questions often test your ability to identify type mismatches and predict outputs after casting.

    每个程序都通过带类型的变量存储和处理数据。Edexcel 考题常考查识别类型不匹配以及类型转换后输出的能力。

    Common primitive types include integer, real/float, Boolean, character, and string. You should know how each is represented and how operations behave when types are mixed.

    常见原始类型包括整型、实型/浮点型、布尔型、字符型和字符串型。应了解每种类型的表示方式,以及类型混合时运算如何表现。

    • Integer: whole numbers, e.g. 42 | 整型:整数,如 42
    • Real/Float: decimal values, e.g. 3.14 | 实型/浮点型:小数值,如 3.14
    • Boolean: TRUE or FALSE only | 布尔型:仅为 TRUE 或 FALSE
    • Character: a single symbol, e.g. ‘A’ | 字符型:单个符号,如 ‘A’
    • String: a sequence of characters, e.g. “Hello” | 字符串型:字符序列,如 “Hello”

    Implicit conversion may happen in expressions such as 10 / 4, which can produce 2.5 if real division is used, or 2 if integer division is used. Always check the language specification assumed by the paper.

    隐式转换可能发生在表达式中,例如 10 / 4,若使用实数除法结果为 2.5,若使用整除结果为 2。务必以试卷假设的语言规范为准。


    2. Sequence, Selection and Iteration | 顺序、选择与迭代

    The three building blocks of structured programming are sequence, selection, and iteration. Exam questions frequently provide pseudocode containing IF, CASE, FOR, WHILE, and REPEAT loops.

    结构化编程的三大基本结构是顺序、选择和迭代。试题常给出包含 IF、CASE、FOR、WHILE 与 REPEAT 循环的伪代码。

    Selection allows branching based on a condition. A CASE statement is useful when there are several distinct values to compare against one variable.

    选择结构根据条件进行分支。当需要将同一变量与多个不同值进行比较时,CASE 语句非常有用。

    Iteration can be count-controlled or condition-controlled. In a FOR loop, the number of iterations is known in advance; in a WHILE loop, the condition is tested before each iteration and the loop may never execute.

    迭代可分为计数控制与条件控制。FOR 循环的执行次数预先已知;WHILE 循环在每次迭代前测试条件,可能一次也不执行。

    You should be able to trace nested loops and calculate the total number of inner statements executed. For a nested loop with outer count n and inner count m, the total is n × m.

    应能追踪嵌套循环并计算内层语句的执行总数。外层执行 n 次、内层执行 m 次的嵌套循环,总执行次数为 n × m。


    3. Subroutines and Scope | 子程序与作用域

    Subroutines are named blocks of code that can be called repeatedly. Procedures perform actions, while functions return a value. Edexcel papers expect you to distinguish between parameters, arguments, and return values.

    子程序是可重复调用的命名代码块。过程执行操作,函数返回一个值。Edexcel 试卷要求区分参数、实参与返回值。

    Parameters can be passed by value or by reference. Pass by value copies the data, so changes inside the subroutine do not affect the original variable; pass by reference allows the subroutine to modify the original memory location.

    参数可按值传递或按引用传递。按值传递会复制数据,因此子程序内的修改不会影响原变量;按引用传递则允许子程序修改原始内存位置。

    Local variables are declared inside a subroutine and exist only during its execution. Global variables are declared outside all subroutines and remain accessible throughout the program, but overuse can make debugging difficult.

    局部变量在子程序内部声明,仅在执行期间存在。全局变量在所有子程序之外声明,整个程序运行期间均可访问,但过度使用会增加调试难度。

    Scope is the region of code where a variable is visible. Trace questions often ask you to state the final value of a variable when both local and global versions share the same name.

    作用域是变量可见的代码区域。追踪题常要求给出当局部与全局变量同名时变量的最终值。


    4. Arrays and 2D Arrays | 数组与二维数组

    An array is a data structure that stores elements of the same data type in contiguous memory locations. Each element is accessed by an index, usually starting at 0 or 1 depending on the pseudocode convention.

    数组是将相同数据类型的元素存储在连续内存位置的数据结构。每个元素通过索引访问,索引通常从 0 或 1 开始,取决于伪代码约定。

    One-dimensional arrays are suitable for lists; two-dimensional arrays model tables or grids. Common operations include traversal, insertion, deletion, and searching for the maximum or minimum value.

    一维数组适用于列表,二维数组用于建模表格或网格。常见操作包括遍历、插入、删除以及查找最大值或最小值。

    Be careful with bounds checking. Accessing an index outside the valid range causes an error; questions may ask you to identify the error or correct the index expression.

    注意边界检查。访问超出有效范围的索引会引发错误;考题可能要求识别错误或修正索引表达式。

    A typical trace might set A ← [3, 5, 7, 9] and then ask for A[2] + A[3]. If indexing starts at 0, this is 7 + 9 = 16; if it starts at 1, it is 5 + 7 = 12.

    典型追踪示例:设 A ← [3, 5, 7, 9],求 A[2] + A[3]。若索引从 0 开始,结果为 7 + 9 = 16;若从 1 开始,结果为 5 + 7 = 12。


    5. File Handling and Exception Management | 文件处理与异常管理

    Programs often read from and write to text files. The standard pattern is to open the file, process its contents line by line, and close the file. Failure to close files can lead to data loss.

    程序经常需要读取和写入文本文件。标准模式是打开文件、逐行处理内容、然后关闭文件。不关闭文件可能导致数据丢失。

    When reading files, you may iterate until end-of-file. Be ready to trace pseudocode that reads all lines into an array or uses a loop with

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)

  • Essential Programming Principles for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学核心编程原理

    📚 Essential Programming Principles for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学核心编程原理

    This revision guide explains the key programming concepts required for Edexcel A-Level Computer Science, including paradigms, data types, control structures, subprograms, recursion, data structures, algorithms, complexity and testing. Understanding these principles is essential for writing efficient, maintainable and correct programs.

    本复习指南解释 Edexcel A-Level 计算机科学所需的关键编程概念,包括编程范式、数据类型、控制结构、子程序、递归、数据结构、算法、复杂度和测试。掌握这些原理对于编写高效、可维护且正确的程序至关重要。

    1. Programming Paradigms | 编程范式

    Edexcel requires you to understand that programs can be written using different paradigms. The main paradigms covered are procedural, object-oriented and event-driven programming.

    Edexcel 要求你理解程序可以用不同的范式编写。主要涉及的范式包括过程式、面向对象和事件驱动编程。

    Procedural programming organises code into procedures or functions that operate on data. It uses sequence, selection and iteration as the fundamental building blocks, and most A-Level pseudocode is procedural.

    过程式编程将代码组织成对数据进行操作的过程或函数。它使用顺序、选择和迭代作为基本构建块,大多数 A-Level 伪代码都属于过程式风格。

    Object-oriented programming groups data and behaviour into classes and objects. It introduces encapsulation, inheritance and polymorphism, which help manage complex systems.

    面向对象编程将数据和行为组合成类和对象。它引入封装、继承和多态性,有助于管理复杂系统。

    Event-driven programming responds to events such as button clicks, key presses or sensor inputs. It is commonly used in graphical user interfaces and embedded systems, where a main loop waits for events and calls event handlers.

    事件驱动编程响应按钮点击、按键或传感器输入等事件。它常用于图形用户界面和嵌入式系统中,主循环等待事件并调用事件处理程序。


    2. Data Types and Variables | 数据类型与变量

    A variable is a named storage location that can hold a value. Common data types include integer, real/float, Boolean, character and string.

    变量是命名的存储位置,可以保存值。常见数据类型包括整数、实数/浮点数、布尔值、字符和字符串。

    Edexcel expects you to choose suitable data types for given problems. For example, use an integer for an age, a real for a height, and a string for a name.

    Edexcel 期望你为给定问题选择合适的数据类型。例如,年龄使用整数,身高使用实数,姓名使用字符串。

    Constants are values that do not change during execution. They improve readability and reduce errors because their value cannot be accidentally modified.

    常量是在执行过程中不改变的值。它们可以提高可读性并减少错误,因为常量的值不能被意外修改。

    Type conversion, or casting, changes a value from one data type to another, such as converting the string ’42’ to the integer 42. You should also understand variable scope: local variables are accessible only inside a subprogram, whereas global variables are accessible throughout the program.

    类型转换或强制转换将值从一种数据类型更改为另一种类型,例如把字符串 ’42’ 转换为整数 42。你还应理解变量作用域:局部变量只能在子程序内部访问,而全局变量可以在整个程序中访问。


    3. Control Structures | 控制结构

    Sequence means statements are executed one after another in the order they appear. This is the default flow of control in a program.

    顺序意味着语句按照出现的顺序一条接一条执行。这是程序默认的控制流程。

    Selection uses IF, ELSE IF and ELSE statements to choose between different blocks of code. You may also see CASE or SWITCH statements for multi-way selection.

    选择使用 IF、ELSE IF 和 ELSE

    Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

    更多咨询请联系16621398022(同微信)