Tag: 编程

  • Programming Techniques and Problem Solving for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学:编程技术与问题求解

    📚 Programming Techniques and Problem Solving for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学:编程技术与问题求解

    This article revises the core programming techniques required by the Edexcel A-Level Computer Science specification. It covers paradigms, data structures, control flow, subroutines, object-oriented concepts, algorithm efficiency, and testing strategies. The explanations use pseudocode and Python-style notation where appropriate, but the focus remains on transferable principles for examination questions.

    本文复习 Edexcel A-Level 计算机科学考试要求掌握的核心编程技术,涵盖编程范式、数据结构、控制流、子程序、面向对象概念、算法效率以及测试策略。解释使用伪代码和类 Python 表示法,但重点仍然是适用于考试问题的可迁移原理。


    1. Programming Paradigms | 编程范式

    A programming paradigm is a style or way of thinking about how a program is constructed. Edexcel A-Level Computer Science requires candidates to understand procedural, object-oriented, and some declarative paradigms. Procedural programming organises code into subroutines that operate on data, while object-oriented programming bundles data and the functions that act on it into classes and objects.

    编程范式是一种思考程序构建方式的风格或方法。Edexcel A-Level 计算机科学要求考生理解过程式、面向对象以及部分声明式范式。过程式编程将代码组织成对数据进行操作的子程序,而面向对象编程将数据和作用于数据的函数封装到类和对象中。

    The choice of paradigm affects readability, reusability, and maintainability. Procedural programs are often easier to understand for small tasks, but object-oriented designs scale better for large systems. Declarative languages such as SQL focus on what result is wanted rather than how to compute it.

    范式的选择会影响可读性、可重用性和可维护性。小任务中过程式程序通常更容易理解,但大型系统中面向对象设计的扩展性更好。SQL 等声明式语言侧重于描述想要的结果,而不是具体如何计算。

    In the Edexcel examination, you may be asked to compare paradigms, identify the most suitable one for a given scenario, or trace code written in a particular style. A clear understanding of state, side effects, and data abstraction is essential.

    在 Edexcel 考试中,可能会要求比较各种范式、为给定场景选择最合适的范式,或跟踪以特定风格编写的代码。清晰理解状态、副作用和数据抽象至关重要。


    2. Data Types and Structures | 数据类型与结构

    Programming languages provide primitive data types to represent integers, real numbers, Boolean values, characters, and strings. Edexcel pseudocode also uses records, arrays, lists, and dictionaries. Choosing the correct data type prevents invalid operations and improves memory efficiency.

    编程语言提供原始数据类型来表示整数、实数、布尔值、字符和字符串。Edexcel 伪代码还使用记录

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

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

  • Mastering A-Level Programming: Constructs, Data Structures and Algorithms | 掌握 A-Level 编程:结构、数据结构与算法

    📚 Mastering A-Level Programming: Constructs, Data Structures and Algorithms | 掌握 A-Level 编程:结构、数据结构与算法

    For Edexcel A-Level Computer Science, programming is not just about writing code; it is about using computational thinking to design, trace, compare, and evaluate algorithms. The specification expects you to read and write pseudocode, understand standard data structures, apply searching and sorting algorithms, and discuss programming paradigms with precision.

    对 Edexcel A-Level 计算机科学而言,编程不只是写代码,而是运用计算思维设计、跟踪、比较和评估算法。大纲要求你能够阅读和编写伪代码,理解标准数据结构,应用查找与排序算法,并准确讨论编程范式。

    1. Programming Constructs | 编程基本结构

    All structured programs are built from three fundamental constructs: sequence, selection, and iteration. Sequence means statements execute one after another in order. Selection allows a program to choose between alternative paths using IF, ELSE IF, ELSE, or multi-way SELECT/CASE statements.

    所有结构化程序都由三种基本结构组成:顺序、选择和迭代。顺序表示语句按先后依次执行。选择允许程序使用 IF、ELSE IF、ELSE 或多分支 SELECT/CASE 语句在不同路径之间做出选择。

    Iteration repeats a block of code. Count-controlled loops such as FOR run a definite number of times, while condition-controlled loops such as WHILE and REPEAT…UNTIL run until a Boolean condition changes. Edexcel pseudocode often asks you to trace these loops or convert between them.

    迭代会重复执行一段代码。计数控制循环(如 FOR)以确定的次数运行,而条件控制循环(如 WHILE 和 REPEAT…UNTIL)会一直执行到布尔条件发生变化。Edexcel 伪代码题经常要求你跟踪这些循环或在它们之间进行转换。


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

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

  • Edexcel A-Level Programming: Core Techniques | Edexcel A-Level 编程:核心技术

    📚 Edexcel A-Level Programming: Core Techniques | Edexcel A-Level 编程:核心技术

    Edexcel A-Level programming questions test more than just writing code; they require you to trace, analyse, evaluate and design solutions using standard techniques. A strong grasp of data types, control flow, data structures, common algorithms, object-oriented ideas and recursion is essential for both Paper 1 and the programming project.

    Edexcel A-Level 编程题目不仅考查编写代码,还要求你追踪、分析、评估并使用标准技术设计解决方案。掌握数据类型、控制流、数据结构、常见算法、面向对象思想和递归对 Paper 1 和编程项目都至关重要。


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

    A variable is a named storage location whose value can change while a program runs. A constant is similar but its value cannot be reassigned after it is set, which improves code reliability and readability.

    变量是一个命名的存储位置,其值在程序运行期间可以改变。常量类似,但其值在设置后不能重新赋值,这提高了代码的可靠性和可读性。

    Primitive data types include integer, real/float, Boolean and character. Composite types such as strings, arrays and records are built from these primitives and model more complex data.

    基本数据类型包括整数、实数/浮点数、布尔值和字符。字符串、数组和记录等复合类型由这些基本类型构建,用于建模更复杂的数据。

    Choosing the correct data type affects memory usage, numeric range and precision. Real numbers stored in floating-point form can suffer rounding errors, so equality tests on floats are often unsafe.

    选择正确的数据类型会影响内存使用、数值范围和精度。以浮点形式存储的实数可能会产生舍入误差,因此对浮点数进行相等性测试通常不安全。


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

    The three fundamental control structures are sequence, selection and iteration. Any algorithm can be expressed using combinations of these constructs.

    三种基本控制结构是顺序、选择和迭代。任何算法都可以用这些结构的组合来表达。

    Selection is implemented with IF…THEN…ELSE statements and switch/case statements. It allows a program to choose between alternative paths based on a Boolean condition.

    选择通过 IF…THEN…ELSE 语句和 switch/case 语句实现。它允许程序根据布尔条件在不同路径之间进行选择。

    Iteration uses FOR loops for count-controlled repetition and WHILE or REPEAT…UNTIL loops for condition-controlled repetition. Nested loops handle multi-dimensional data and patterns.

    迭代使用 FOR 循环进行计数控制重复,使用 WHILE 或 REPEAT…UNTIL 循环进行条件控制重复。嵌套循环用于处理多维数据和模式。


    3. Functions and Procedures | 函数与过程

    A function returns a single value and is normally called from within an expression. A procedure performs a task but does not return a value, although it can modify arguments passed by reference or change global state.

    函数返回单个值,通常在表达式中调用。过程执行任务但不返回值,尽管它可以通过引用传递参数修改实参或改变全局状态。

    Parameters may be passed by value or by reference. Pass-by-value creates a copy of the argument, so changes inside the routine do not affect the original. Pass-by-reference gives the routine access to the original data.

    参数可以按值传递或按引用传递。按值传递会创建实参的副本,因此例程内部的更改不会影响原始数据。按引用传递使例程能够访问原始数据。

    Using

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

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

  • Sorting and Searching Algorithms for A-Level Programming | A-Level 编程中的排序与搜索算法

    📚 Sorting and Searching Algorithms for A-Level Programming | A-Level 编程中的排序与搜索算法

    Algorithms are the heart of programming. At A-Level, you must be able to design, trace, and compare standard searching and sorting algorithms, and understand their efficiency using Big-O notation.

    算法是编程的核心。在 A-Level 阶段,你必须能够设计、追踪和比较标准的搜索与排序算法,并使用大 O 表示法理解它们的效率。


    1. Computational Thinking and Algorithm Design | 计算思维与算法设计

    Computational thinking involves breaking a problem into manageable parts, identifying patterns and abstractions, and designing a step-by-step algorithm to solve it. An algorithm is a precise sequence of instructions that terminates with a result.

    计算思维包括把问题分解为可处理的部分、识别模式与抽象,并设计逐步执行的算法来解决问题。算法是终止并产生结果的精确指令序列。

    Key stages of computational thinking include:

    计算思维的关键阶段包括:

    • Decomposition – breaking down a problem into smaller sub-problems – 分解 – 将问题拆分为更小的子问题
    • Pattern recognition – identifying similarities with known problems – 模式识别 – 识别与已知问题的相似性
    • Abstraction – filtering out irrelevant detail – 抽象 – 过滤掉无关细节
    • Algorithm design – writing the exact steps to solve the problem – 算法设计 – 编写解决问题的确切步骤

    2. Linear Search | 线性搜索

    A linear search checks each element of a list in turn until the target is found or the end is reached. It works on unsorted data but is slow for large lists.

    线性搜索逐个检查列表中的每个元素,直到找到目标或到达列表末尾。它适用于未排序的数据,但对大列表速度较慢。

    FOR i ← 0 TO n-1
    IF arr[i] = target THEN
      RETURN i
    END IF
    NEXT i
    RETURN -1

    The worst-case time complexity is O(n), because every element may need to be checked. The best case is O(1) when the target is the first element.

    最坏情况的时间复杂度是 O(n),因为可能需要检查每个元素。最佳情况是 O(1),当目标是第一个元素时。


    3. Binary Search | 二分搜索

    Binary search is a divide-and-conquer algorithm that repeatedly halves the search interval. It requires the list to be sorted before searching.

    二分搜索是一种分治算法,它不断将搜索区间减半。它要求列表在搜索前已经排序。

    low ← 0
    high ← n-1
    WHILE low ≤ high DO
      mid ← (low + high) DIV 2
      IF arr[mid] = target THEN RETURN mid
      ELSE IF arr[mid] < target THEN low ← mid + 1
      ELSE high ← mid – 1
    END WHILE
    RETURN -1

    Each comparison halves the search space, so the time complexity is O(log n). This makes binary search far more efficient than linear search for large sorted datasets.

    每次比较都会使搜索空间减半,因此时间复杂度为 O(log n)。这使得二分搜索在大规模已排序数据集上远比线性搜索高效。


    4. Bubble Sort | 冒泡排序

    Bubble sort repeatedly steps through a list, compares adjacent elements, and swaps them if they are in the wrong order. The largest unsorted element bubbles to its correct position after each pass.

    冒泡排序反复遍历列表,比较相邻元素,如果顺序错误则交换它们。每经过一轮,最大的未排序元素就会冒泡到正确的位置。

    FOR i ← 0 TO n-2
      FOR j ← 0 TO n-i-2
        IF arr[j] > arr[j+1] THEN
          SWAP arr[j], arr[j+1]
        END IF
      NEXT j
    NEXT i

    The average and worst-case complexity is O(n²) because of the nested loops. A small optimisation can stop early if no swaps are made, giving best case O(n).

    由于嵌套循环,平均和最坏情况复杂度为 O(n²)。如果增加优化,在没有交换时提前停止,最佳情况可达到 O(n)。


    5. Insertion Sort | 插入排序

    Insertion sort builds a sorted portion one element at a time. It takes each new element and inserts it into its correct position within the already sorted part of the list.

    插入排序一次一个元素地构建已排序部分。它取出每个新元素,并将其插入到列表中已排序部分的正确位置。

    FOR i ← 1 TO n-1
      key ← arr[i]
      j ← i – 1
      WHILE j ≥ 0 AND arr[j] > key DO
        arr[j+1] ← arr[j]
        j ← j – 1
      END WHILE
      arr[j+1] ← key
    NEXT i

    Insertion sort is O(n²) in the worst case but is particularly efficient for small or nearly sorted lists. It is stable and works well online, sorting items as they arrive.

    插入排序在最坏情况下为 O(n²),但对小型或接近排序的列表特别高效。它是稳定的,并且适合在线排序,即数据到达时立即处理。


    6. Merge Sort | 归并排序

    Merge sort is a classic divide-and-conquer algorithm. It splits the list into halves, recursively sorts each half, and then merges the two sorted halves back together.

    归并排序是一种经典的分治算法。它将列表分成两半,递归地对每一半排序,然后将两个已排序的部分合并在一起。

    FUNCTION mergeSort(arr)
      IF LEN(arr) ≤ 1 THEN RETURN arr
      mid ← LEN(arr) DIV 2
      left ← mergeSort(arr[0..mid-1])
      right ← mergeSort(arr[mid..LEN(arr)-1])
      RETURN merge(left, right)
    END FUNCTION

    Merge sort has a guaranteed time complexity of O(n log n) in all cases, making it very reliable for large datasets. However, it requires extra memory of O(n) for the merging process.

    归并排序在所有情况下都能保证 O(n log n) 的时间复杂度,这使得它对大型数据集非常可靠。然而,合并过程需要 O(n) 的额外内存。


    7. Big-O Notation and Efficiency | 大 O 表示法与效率

    Big-O notation describes how the running time or memory usage of an algorithm grows as the input size n increases. It focuses on the dominant term and ignores constant factors.

    大 O 表示法描述算法的运行时间或内存使用随输入规模 n 增长的情况。它关注主导项,并忽略常数因子。

    Complexity Name Example
    O(1) Constant Array index access
    O(log n) Logarithmic Binary search
    O(n) Linear Linear search
    O(n log n) Linearithmic Merge sort
    O(n²) Quadratic Bubble sort, insertion sort
    O(2ⁿ) Exponential Recursive Fibonacci without memoisation

    In Edexcel exams, you are expected to identify the best, worst, and average case complexities of standard algorithms and to compare their suitability for different data sizes.

    在 Edexcel 考试中,你需要识别标准算法的最佳、最坏和平均情况复杂度,并比较它们对不同数据规模的适用性。


    8. Recursion in Programming | 编程中的递归

    Recursion is a technique where a function calls itself to solve smaller instances of the same problem. Every recursive algorithm must have a base case to stop the recursion and a recursive step that reduces the problem size.

    递归是一种函数调用自身来解决更小规模同类问题的技术。每个递归算法必须有一个基准情形来停止递归,以及一个减少问题规模的递归步骤。

    The factorial function is a standard example:

    阶乘函数是一个标准示例:

    factorial(n) = 1                      IF n = 0
    factorial(n) = n × factorial(n-1)    IF n > 0

    Recursive solutions can be elegant but may use more memory because each call is stored on the call stack. Iterative solutions are often more efficient for simple problems.

    递归解决方案可能很优雅,但可能使用更多内存,因为每次调用都存储在调用栈中。对于简单问题,迭代解决方案通常更高效。


    9. Stacks and Queues in Algorithms | 算法中的栈与队列

    Stacks and queues are abstract data types that play a key role in implementing algorithms. A stack follows Last In, First Out (LIFO), while a queue follows First In, First Out (FIFO).

    栈和队列是抽象数据类型,在实现算法中起着关键作用。栈遵循后进先出(LIFO),而队列遵循先进先出(FIFO)。

    • Depth-first search uses a stack to remember the path – 深度优先搜索使用栈来记住路径
    • Breadth-first search uses a queue to explore level by level – 广度优先搜索使用队列逐层探索
    • Function calls in recursion are stored on the system stack – 递归中的函数调用存储在系统栈上
    • Operating systems use queues for scheduling tasks – 操作系统使用队列调度任务

    10. Exam Tips for Edexcel Programming Questions | Edexcel 编程题考试技巧

    When answering Edexcel programming questions, always show your working by using trace tables. Trace tables help you track variable values and prove that your algorithm works for a given input.

    在回答 Edexcel 编程题时,一定要通过使用追踪表展示你的推理过程。追踪表帮助你跟踪变量值,并证明你的算法对给定输入有效。

    Use the Edexcel pseudocode style consistently, with clear indentation and correct keywords such as FOR, WHILE, IF, THEN, ELSE, END IF, and RETURN. If you use a different language, state your language clearly.

    一致地使用 Edexcel 伪代码风格,具有清晰的缩进和正确的关键字,如 FOR、WHILE、IF、THEN、ELSE、END IF 和 RETURN。如果你使用其他语言,请清楚地说明你使用的语言。

    Always state the time complexity of your algorithm and justify it using the structure of the code. For example, a single loop gives O(n), while two nested loops give O(n²).

    始终陈述你的算法的时间复杂度,并使用代码结构进行论证。例如,单个循环得到 O(n),而两个嵌套循环得到 O(n²)。

    Finally, test your algorithm with boundary cases such as an empty list, a single-element list, and a list where the target is the first or last element.

    最后,使用边界情况测试你的算法,比如空列表、单元素列表以及目标在第一个或最后一个位置的情况。


    Published by TutorHao | Programming Revision Series | aleveler.com

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

  • Mastering Edexcel A-Level Programming: Data Structures, Algorithms and Computational Thinking | 精通爱德思A-Level编程:数据结构、算法与计算思维

    📚 Mastering Edexcel A-Level Programming: Data Structures, Algorithms and Computational Thinking | 精通爱德思A-Level编程:数据结构、算法与计算思维

    Programming is at the heart of the Edexcel A-Level Computer Science specification. This revision guide breaks down the key programming concepts that regularly appear in Paper 1 and Paper 2, from computational thinking and data structures to recursion and object-oriented design. Understanding these fundamentals will help you write clearer pseudocode, trace algorithms accurately, and tackle high-mark questions with confidence.

    编程是爱德思A-Level计算机科学考试的核心。本复习指南分解了试卷一和试卷二中经常出现的关键编程概念,从计算思维和数据结构到递归和面向对象设计。理解这些基础知识将帮助你写出更清晰的伪代码、准确地跟踪算法,并自信地应对高分题目。


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

    Computational thinking involves four main techniques: decomposition, pattern recognition, abstraction, and algorithm design. Decomposition means breaking a large problem into smaller, manageable sub-problems. For example, a chess game can be decomposed into move validation, board display, and score tracking modules.

    计算思维包括四种主要技术:分解、模式识别、抽象和算法设计。分解意味着将一个大问题拆分成更小、更易于管理的子问题。例如,一个国际象棋游戏可以分解为走棋验证、棋盘显示和计分跟踪等模块。

    Pattern recognition allows you to reuse solutions to similar problems, while abstraction removes unnecessary detail so you can focus on what matters. In Edexcel exams, you may be asked to describe how abstraction is used in a given scenario or to break down a problem into smaller functions.

    模式识别使你能够重复使用类似问题的解决方案,而抽象则去除不必要的细节,使你专注于重要内容。在爱德思考试中,你可能会被要求描述在给定场景中如何使用抽象,或将一个问题拆分为更小的函数。


    2. Programming Paradigms and Language Translators | 编程范式与语言翻译器

    Edexcel expects you to understand the difference between procedural programming, object-oriented programming (OOP), and declarative programming. Procedural programming uses a sequence of instructions and subroutines to manipulate data, while OOP organises code into classes and objects that combine state and behaviour.

    爱德思要求你理解过程式编程、面向对象编程(OOP)和声明式编程之间的区别。过程式编程使用一系列指令和子程序来操作数据,而OOP则将代码组织成结合状态和行为的类和对象。

    You also need to know how high-level code becomes machine code. A compiler translates the whole source code at once and produces an executable file, while an interpreter translates and executes line by line. An assembler converts assembly language into machine code. These differences affect debugging and performance.

    你还需要了解高级代码如何变成机器代码。编译器一次性翻译整个源代码并生成可执行文件,而解释器逐行翻译和执行。汇编器将汇编语言转换为机器代码。这些差异会影响调试和性能。


    3. Data Types and Arithmetic Operations | 数据类型与算术运算

    Common primitive data types include integer, real/float, Boolean, character, and string. You must choose the most appropriate type for a variable to avoid unnecessary memory use and to ensure correct behaviour. For example, storing a person’s age as an integer is sensible, but storing a price as an integer would lose decimal values.

    常见的原始数据类型包括整数、实数/浮点数、布尔值、字符和字符串。你必须为变量选择最合适的类型,以避免不必要的内存使用并确保正确的行为。例如,将人的年龄存储为整数是合理的,但将价格存储为整数会丢失小数值。

    Arithmetic operations include addition, subtraction, multiplication, real division, integer division (DIV), modulus (MOD), and exponentiation. Integer division returns only the whole-number quotient, while modulus returns the remainder. For example, 17 DIV 5 = 3 and 17 MOD 5 = 2. Type casting can convert data from one type to another, such as converting a string ‘123’ to the integer 123.

    算术运算包括加法、减法、乘法、实数除法、整数除法(DIV)、模运算(MOD)和幂运算。整数除法只返回商的整数部分,而模运算返回余数。例如,17 DIV 5 = 3,17 MOD 5 = 2。类型转换可以将数据从一种类型转换为另一种类型,例如将字符串 ‘123’ 转换为整数 123。


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

    All algorithms can be built from three control structures: sequence, selection, and iteration. Sequence simply means executing statements in order. Selection uses conditions to choose between different paths, typically with IF, ELSE IF, ELSE, or CASE statements.

    所有算法都可以由三种控制结构构建:顺序、选择和迭代。顺序意味着按顺序执行语句。选择使用条件在不同路径之间进行选择,通常使用 IF、ELSE IF、ELSE 或 CASE 语句。

    Iteration repeats a block of code. Count-controlled loops such as FOR run a fixed number of times, while condition-controlled loops such as WHILE and REPEAT…UNTIL continue until a condition changes. In Edexcel pseudocode, WHILE checks the condition before each iteration, while REPEAT…UNTIL checks it after at least one execution.

    迭代重复执行一段代码。计数控制循环(如 FOR)运行固定次数,而条件控制循环(如 WHILE 和 REPEAT…UNTIL)持续执行直到条件改变。在爱德思伪代码中,WHILE 在每次迭代前检查条件,而 REPEAT…UNTIL 在至少执行一次后检查条件。


    5. Subroutines, Parameters and Scope | 子程序、参数与作用域

    A subroutine is a named block of code that can be called from elsewhere. Functions return a value, while procedures do not. Using subroutines makes code modular, reusable, and easier to test. Parameters allow data to be passed into a subroutine, and arguments are the actual values supplied at call time.

    子程序是一段可以从其他地方调用的命名代码块。函数返回一个值,而过程不返回值。使用子程序使代码模块化、可重用且更易于测试。参数允许将数据传递给子程序,而实参是调用时提供的实际值。

    Parameter passing can be by value or by reference. Passing by value copies the data, so changes inside the subroutine do not affect the original variable. Passing by reference passes the memory address, so changes do affect the original. Scope determines where a variable can be accessed: local variables exist only inside a subroutine, while global variables are accessible throughout the program.

    参数传递可以按值或按引用进行。按值传递会复制数据,因此子程序内部的更改不会影响原始变量。按引用传递传递内存地址,因此更改会影响原始变量。作用域决定了变量可以在哪里访问:局部变量仅存在于子程序内部,而全局变量在整个程序中都可以访问。


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

    Recursion is a technique where a subroutine calls itself. Every recursive algorithm must have a base case that stops the recursion and a recursive case that moves closer to the base case. A classic example is the factorial function: n! = n × (n-1)! with

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

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

  • Core Programming Techniques for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学核心编程技术

    📚 Core Programming Techniques for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学核心编程技术

    This revision guide covers the core programming techniques required for the Edexcel A-Level Computer Science specification. It focuses on the practical and theoretical knowledge you need to tackle programming questions in Paper 1 and Paper 2, including paradigms, data structures, algorithms, recursion and complexity analysis.

    本复习指南涵盖 Edexcel A-Level 计算机科学大纲要求的核心编程技术。内容聚焦于应对 Paper 1 和 Paper 2 编程题所需的实践与理论知识,包括编程范式、数据结构、算法、递归和复杂度分析。

    1. Programming Paradigms | 编程范式

    A programming paradigm is a fundamental style or approach used to structure a program. Edexcel expects you to know three main paradigms: procedural, object-oriented and event-driven programming.

    编程范式是用于组织程序的基本风格或方法。Edexcel 要求你掌握三种主要范式:过程式编程、面向对象编程和事件驱动编程。

    In procedural programming, a program is written as a sequence of instructions. The code is broken into procedures or functions that operate on data, and the flow of control is determined by sequence, selection and iteration.

    在过程式编程中,程序被写成一系列指令。代码被分解为对数据进行操作的过程或函数,控制流由顺序、选择和迭代决定。

    Object-oriented programming groups data and the methods that act on that data into objects. Event-driven programming waits for user or system events, such as a button click or a timer tick, and then runs the corresponding handler.

    面向对象编程将数据以及操作这些数据的方法组合到对象中。事件驱动编程等待用户或系统事件(例如按钮点击或计时器触发),然后运行相应的处理程序。


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

    Variables store values that can change during program execution. In Edexcel pseudocode, the main primitive data types are INTEGER, REAL, BOOLEAN, CHAR and STRING.

    变量存储程序执行期间可以改变的值。在 Edexcel 伪代码中,主要的原始数据类型是 INTEGER、REAL、BOOLEAN、CHAR 和 STRING。

    It is important to declare variables with an appropriate data type before use. Strong typing helps prevent errors such as trying to add a string to an integer.

    在使用变量之前,必须用适当的数据类型声明变量。强类型有助于防止错误,例如尝试将字符串与整数相加。

    Type conversion or casting may be needed when moving between types, for example converting a REAL to an INTEGER. Constants can be declared with the CONSTANT keyword and cannot be changed after initial assignment.

    在类型之间转换时可能需要进行类型转换或强制转换,例如将 REAL 转换为 INTEGER。常量可以用 CONSTANT 关键字声明,并且在初始赋值后不能更改。


    3. Arrays and Records | 数组与记录

    An array is a fixed-size data structure that stores elements of the same data type in contiguous memory locations. Elements are accessed using an index, which may start at 0 or 1 depending on the language or pseudocode convention.

    数组是一种固定大小的数据结构,在连续的内存位置中存储相同数据类型的元素。通过索引访问元素,索引可以根据语言或伪代码约定从 0 或 1 开始。

    Two-dimensional arrays are commonly used to model grids, matrices and tables. A record is a composite data type that groups fields of potentially different types under one name, such as a Student record with name, age and grade.

    二维数组通常用于模拟网格、矩阵和表格。记录是一种复合数据类型,将可能不同类型的字段组合在一个名称下,例如包含姓名、年龄和成绩的 Student 记录。

    Unlike lists in many high-level languages

    Published by TutorHao | A-Level 编程 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 Edexcel A-Level Computer Science, especially in Paper 2: Thinking Logically and Algorithms. This article explains the key algorithms, traces their behaviour and compares their Big O complexity so you can answer exam questions confidently.

    搜索与排序算法是 Edexcel A-Level 计算机科学的核心内容,尤其是在 Paper 2:逻辑思维与算法中。本文解释关键算法、跟踪其行为并比较它们的大 O 复杂度,帮助你自信地应对考试题目。


    1. Algorithms and Computational Thinking | 算法与计算思维

    An algorithm is a finite sequence of well-defined instructions that produces a result for a given input. In Edexcel A-Level Programming, computational thinking includes abstraction, decomposition, pattern recognition and algorithmic reasoning.

    算法是有限且定义明确的指令序列,可针对给定输入产生结果。在 Edexcel A-Level 编程中,计算思维包括抽象、分解、模式识别和算法推理。

    Every algorithm must have clear inputs, outputs, processing steps and a terminating condition. Without these properties, a program may loop forever or produce incorrect results.

    每个算法都必须有清晰的输入、输出、处理步骤和终止条件。缺少这些性质,程序可能无限循环或产生错误结果。

    • Input: data provided to the algorithm before execution.
    • Output: the result produced after processing.
    • Definiteness: every step is clear and unambiguous.
    • Finiteness: the algorithm terminates after a finite number of steps.
    • Effectiveness: each step is basic enough to be carried out in practice.

    输入:执行前提供给算法的数据;输出:处理后产生的结果;确定性:每一步都清晰无歧义;有限性:算法在有限步后终止;有效性:每一步都足够基本,可以实际执行。


    2. Linear Search | 线性搜索

    Linear search checks each item in a list one by one until the target value is found or the end is reached. It works on both sorted and unsorted data, which makes it flexible but often slow for large lists.

    线性搜索逐一检查列表中的每个元素,直到找到目标值或到达列表末尾。它适用于已排序和未排序数据,因此灵活但在大列表中通常较慢。

    The algorithm begins at index 0 and compares the target with each element. If a match is found, it returns the index; otherwise, it continues to the next element.

    该算法从索引 0 开始,将目标与每个元素比较。如果找到匹配项,返回索引;否则继续检查下一个元素。

    In the worst case, the target is not present and every element must be examined. The time complexity is therefore O(n).

    在最坏情况下,目标不存在,必须检查每个元素。因此时间复杂度为 O(n)。

    • Best case: target found at position 0 — O(1)
    • Average case: target found near the middle — O(n/2), simplified to O(n)
    • Worst case: target not found — O(n)

    最好情况:目标在第 0 位找到 — O(1);平均情况:目标在中间附近找到 — O(n/2),简化为 O(n);最坏情况:目标不存在 — O(n)。


    3. Binary Search | 二分搜索

    Binary search repeatedly divides a sorted list in half. It compares the middle element with the target and discards the half that cannot contain the target.

    二分搜索反复将已排序列表分成两半。它比较中间元素与目标值,并舍弃不可能包含目标的那一半。

    The middle index is calculated using the low and high boundaries:

    中间索引使用下界和上界计算:

    mid = low + (high − low) ÷ 2

    This avoids integer overflow and gives the same result as (low + high) ÷ 2 in normal cases. Binary search runs in O(log₂ n) time.

    这避免了整数溢出,在正常情况下与 (low + high) ÷ 2 结果相同。二分搜索的时间复杂度为 O(log₂ n)。

    It is essential to remember that binary search only works on sorted data. Applying it to an unsorted list gives meaningless results.

    必须记住二分搜索只适用于已排序数据。对未排序列表使用二分搜索会得到无意义的结果。


    4. Comparing Search Algorithms | 搜索算法对比

    Linear search is simple and requires no ordering, but binary search is much faster when the data is sorted. The trade-off is the cost of sorting plus the need for random access.

    线性搜索简单且不需要排序,但数据已排序时二分搜索快得多。代价是排序成本以及需要随机访问。

    Criterion Linear Search Binary Search
    Precondition None Sorted data
    Worst-case time O(n) O(log₂ n)
    Space O(1) O(1)

    对于小数据集,线性搜索是可接受的;对于大数据集且已排序,二分搜索显著减少比较次数。


    5. Bubble Sort | 冒泡排序

    Bubble sort works by repeatedly comparing adjacent elements and swapping them if they are in the wrong order. After each pass, the largest unsorted element bubbles to its final position at the end.

    冒泡排序通过反复比较相邻元素并在顺序错误时交换来工作。每一轮后,最大的未排序元素“冒泡”到末尾的最终位置。

    If a full pass makes no swaps, the list is already sorted and the algorithm can stop early. This optimised version has best-case O(n).

    如果一整轮没有发生交换,说明列表已经有序,算法可以提前停止。这种优化版本的最好情况为 O(n)。

    • Worst-case time: O(n²)
    • Average-case time: O(n²)
    • Best-case time: O(n) with early exit
    • Space: O(1) — in-place

    最坏情况时间:O(n²);平均情况时间:O(n²);最好情况时间:O(n)(使用提前退出);空间:O(1) — 原地排序。


    6. Insertion Sort | 插入排序

    Insertion sort builds a sorted sublist one element at a time by inserting each new element into its correct position among the previously sorted items.

    插入排序通过将每个新元素插入已排序元素中的正确位置,一次构建一个有序子列表。

    It is stable and efficient for small or nearly sorted data, with best-case O(n) and worst-case O(n²).

    它是稳定的,适用于小规模或近乎有序的数据,最好情况 O(n),最坏情况 O(n²)。

    This algorithm is often used in practice as a finishing step for more complex sorts or when the list is already almost sorted.

    该算法在实践中常被用作更复杂排序的收尾步骤,或当列表已经几乎有序时使用。


    7. Merge Sort | 归并排序

    Merge sort is a divide-and-conquer algorithm. It recursively splits the list into halves until each sublist has length 1, then repeatedly merges sorted sublists to produce new sorted lists.

    归并排序是一种分治算法。它递归地将列表分成两半,直到每个子列表长度为 1,然后反复合并且已排序的子列表以产生新的有序列表。

    Merge sort guarantees O(n log₂ n) time in all cases, but it needs O(n) extra space for the temporary arrays used during merging.

    归并排序在所有情况下都保证 O(n log₂ n) 时间,但在合并过程中需要 O(n) 额外空间用于临时数组。

    Its stable nature and consistent performance make it a good choice when memory is not a major constraint.

    它的稳定性和一致的性能使其在内存不是主要限制时成为良好选择。


    8. Quick Sort | 快速排序

    Quick sort also uses divide and conquer. It selects a pivot, partitions the array so that elements smaller than the pivot come before it and larger elements after it, then recursively sorts the two partitions.

    快速排序也使用分治法。它选择一个基准值,对数组进行分区,使小于基准的元素在其前,大于基准的元素在其后,然后递归排序两个分区。

    Average-case time is O(n log₂ n), but the worst case is O(n²) when poor pivot choices lead to highly unbalanced partitions.

    平均情况时间为 O(n log₂ n),但当基准选择不当导致分区高度不平衡时,最坏情况为 O(n²)。

    Quick sort is often in-place and requires only O(log₂ n) average space for recursion, making it faster in many practical situations.

    快速排序通常是原地排序,平均仅需要 O(log₂ n) 递归空间,因此在许多实际情况下速度更快。


    9. Big O Notation and Complexity | 大 O 表示法与复杂度

    Big O notation describes an upper bound on the growth rate of an algorithm’s time or space requirements. It ignores constants and lower-order terms because they matter little for large n.

    大 O 表示法描述了算法时间或空间需求增长率的上界。它忽略常数和低阶项,因为当 n 很大时它们影响很小。

    Complexity Example
    O(1) Hash table lookup, direct array access
    O(log₂ n) Binary search
    O(n) Linear search
    O(n log₂ n) Merge sort, quick sort average case
    O(n²) Bubble sort, insertion sort worst case

    考试常要求根据代码或伪代码判断复杂度,并比较不同算法的可扩展性。


    10. Choosing the Right Algorithm | 选择正确的算法

    The best algorithm depends on data size, whether the data is sorted, memory limits, stability requirements and implementation effort. For example, binary search is only justified if sorting is already done or search frequency is high.

    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 article is a focused revision guide for Edexcel A-Level Computer Science, covering the programming fundamentals that appear regularly in Paper 1 and Paper 2. It brings together language paradigms, data representation, control flow, subroutines, recursion and object-oriented ideas in one place, with exam-style prompts and common mistakes highlighted along the way.

    本文是面向 Edexcel A-Level 计算机科学的重点复习指南,梳理 Paper 1 和 Paper 2 中经常出现的编程基础知识。文章将语言范式、数据表示、控制流程、子程序、递归以及面向对象思想整合在一起,并逐步标注考试题型与常见错误。


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

    Edexcel expects you to recognise that programming languages are grouped into paradigms such as procedural, object-oriented and functional. A procedural program is written as a sequence of instructions that change the program state, while an object-oriented program models the world as interacting objects that hold data and behaviour.

    Edexcel 要求你识别编程语言可按范式分类,例如过程式、面向对象和函数式。过程式程序写成一连串改变程序状态的指令,而面向对象程序则把世界建模为相互交互、包含数据与行为的对象。

    Compiled languages like C translate the whole source code before execution, which usually gives faster runtime but requires a separate compile step. Interpreted languages like Python translate and execute line by line, which helps debugging but can be slower.

    C 等编译型语言在执行前先将全部源代码翻译成机器码,通常运行速度更快,但需要单独的编译步骤。Python 等解释型语言逐行翻译执行,有助于调试,但速度可能较慢。

    • Procedural: focuses on procedures and step-by-step instructions.
    • Object-oriented: focuses on classes, objects, inheritance and encapsulation.
    • Functional: focuses on pure functions, recursion and immutable data.
    • 过程式:关注过程和逐步指令;面向对象:关注类、对象、继承和封装;函数式:关注纯函数、递归和不可变数据。

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

    A variable is a named storage location whose value can change during execution, whereas a constant is bound to a value that cannot be modified. In A-Level pseudocode, constants are often declared with the keyword CONSTANT or final, and variables with a data type such as INTEGER, REAL, BOOLEAN, CHAR or STRING.

    变量是命名的存储位置,其值在执行过程中可以改变;常量则绑定到一个不可修改的值。在 A-Level 伪代码中,常量常用 CONSTANT 或 final 声明,变量则使用 INTEGER、REAL、BOOLEAN、CHAR 或 STRING 等数据类型。

    Choosing the right data type affects accuracy and memory. For example, REAL is used for fractional values, but floating-point arithmetic can introduce rounding errors, while INTEGER arithmetic is exact within range.

    选择正确的数据类型会影响精度和内存。例如,REAL 用于带小数的值,但浮点运算可能引入舍入误差;INTEGER 运算在范围内则是精确的。

    Data type | 数据类型 Typical use | 典型用途
    INTEGER Whole numbers such as counts or indices
    REAL Measurements, currency, scientific values
    BOOLEAN True/false flags and conditions
    CHAR / STRING Single characters or text data

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

    Expressions combine values, variables and operators to produce a result. Arithmetic operators include +, −, ×, ÷ and MOD; comparison operators include =, ≠, <, >, ≤ and ≥; Boolean operators include AND, OR and NOT. Operator precedence determines the order of evaluation.

    表达式将值、变量和运算符组合起来产生结果。算术运算符包括 +、−、×、÷ 和 MOD;比较运算符包括 =、≠、<、>、≤ 和 ≥;布尔运算符包括 AND、OR 和 NOT。运算符优先级决定求值顺序。

    Integer division and MOD are common exam questions. In pseudocode, 17 DIV 5 gives 3, while 17 MOD 5 gives 2. Always check whether the language uses DIV/MOD or // and %.

    整除与取模是常见考试内容。在伪代码中,17 DIV 5 得 3,17 MOD 5 得 2。务必确认语言使用 DIV/MOD 还是 // 和 %。

    17 DIV 5 = 3 and 17 MOD 5 = 2


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

    All programming problems can be built from three control structures: sequence, selection and iteration. Sequence means instructions execute one after another; selection uses IF…THEN…ELSE…ENDIF or CASE statements to choose paths; iteration repeats code using FOR, WHILE or REPEAT…UNTIL loops.

    所有编程问题都可以由三种控制结构构建:顺序、选择和迭代。顺序指指令逐条执行;选择使用 IF…THEN…ELSE…ENDIF 或 CASE 语句选择路径;迭代使用 FOR、WHILE 或 REPEAT…UNTIL 循环重复代码。

    A common exam skill is converting a FOR loop into an equivalent WHILE loop. For example, FOR i ← 1 TO 10 can be rewritten as i ← 1; WHILE i ≤ 10 DO … i ← i + 1 ENDWHILE.

    常见的考试技能是把 FOR 循环改写成等价的 WHILE 循环。例如,FOR i ← 1 TO 10 可改写为 i ← 1;WHILE i ≤ 10 DO … i ← i + 1 ENDWHILE。

    FOR i ← 1 TO 10 ≡ i ← 1; WHILE i ≤ 10 DO … i ← i + 1 ENDWHILE


    5. Subroutines, Parameters and Return Values | 子程序、参数与返回值

    A subroutine is a named block of code that can be called from elsewhere. Procedures perform a task without returning a value, whereas functions return a single value. Parameters are values passed into the subroutine; they can be passed by value or by reference.

    子程序是可从别处调用的命名代码块。过程执行任务而不返回值,函数则返回一个值。参数是传入子程序的值;参数传递方式有按值传递和按引用传递。

    In exams, you must trace parameter passing accurately. If a parameter is passed by value, the subroutine works on a copy, so the original variable is unchanged. If passed by reference, changes affect the caller’s variable.

    考试中必须准确追踪参数传递。如果按值传递,子程序操作的是副本,原变量不会改变。若按引用传递,修改会影响调用者的变量。


    6. Local and Global Variables | 局部变量与全局变量

    A local variable is declared inside a subroutine and exists only while that subroutine is running. A global variable is declared outside subroutines and can be accessed throughout the program. Local variables make subroutines easier to test and reuse because their effect is contained.

    局部变量在子程序内部声明,仅在子程序运行期间存在。全局变量在子程序外部声明,可在整个程序中访问。局部变量使子程序更易于测试和复用,因为其影响是受限的。

    Excess use of global variables can lead to side effects and make debugging difficult. In tracing questions, draw a table showing the stack or scope of each variable, and update it line by line.

    过度使用全局变量可能导致副作用并使调试困难。在追踪题中,画出表格显示每个变量的栈或作用域,并逐行更新。


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

    Recursion occurs when a subroutine calls itself. A correct recursive definition must have at least one base case that stops the recursion and at least one recursive case that reduces the problem towards the base case. Each recursive call creates a new stack frame containing local variables and return address.

    递归发生在子程序调用自身时。正确的递归定义必须至少有一个停止递归的基例,以及至少一个将问题向基例缩小问题规模的递归例。每次递归调用都会创建一个新的栈帧,包含局部变量和返回地址。

    The classic factorial can be defined as factorial(n) = 1 when n = 0, otherwise n × factorial(n − 1). The call stack grows as n decreases; when n reaches 0, the frames are popped and the multiplications are completed in reverse order.

    经典阶乘可定义为:当 n = 0 时 factorial(n) = 1,否则为 n × factorial(n − 1)。调用栈随 n 减少而增长;当 n 到达 0 时,栈帧被弹出,乘法以相反顺序完成。

    Recursion can make code elegant, but it uses extra memory for stack frames. A missing base case causes infinite recursion and eventually a stack overflow error. Some problems, such as traversing tree structures, are naturally recursive.

    递归使代码简洁,但会为栈帧占用额外内存。缺少基例会导致无限递归,最终引发栈溢出错误。某些问题,如遍历树结构,天然适合递归。


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

    A class is a blueprint that defines the attributes and methods of a type. An object is an instance of a class. For example, a Car class might have attributes such as colour and fuelLevel, and methods such as startEngine() and accelerate().

    类是定义类型属性和方法的蓝图。对象是类的实例。例如,Car 类可以有 colour 和 fuelLevel 等属性,以及 startEngine() 和 accelerate() 等方法。

    Encapsulation means hiding the internal state of an object and exposing only necessary methods. In pseudocode, attributes are often declared as private and accessed through public get and set methods. This protects data integrity.

    封装意味着隐藏对象的内部状态,只公开必要的方法。在伪代码中,属性通常声明为私有,并通过公共的 get 和 set 方法访问。这样可以保护数据完整性。


    9. Inheritance, Encapsulation and Polymorphism | 继承、封装与多态

    Inheritance allows a child class to inherit attributes and methods from a parent class, using the keyword inherits or extends. The child class can add new members or override inherited methods to provide its own behaviour.

    继承允许子类从父类继承属性和方法,使用 inherits 或 extends

    Published by TutorHao | A-Level 编程 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 paradigm that models real-world entities as objects containing both data and behaviour. For Edexcel A-Level Computer Science, you need to understand how classes define templates for objects, and how encapsulation, inheritance and polymorphism make code more reusable, maintainable and secure.

    面向对象编程(OOP)是一种将现实世界实体建模为既包含数据又包含行为的对象的编程范式。对 Edexcel A-Level 计算机科学而言,你需要理解类如何定义对象的模板,以及封装、继承和多态如何使代码更具可重用性、可维护性和安全性。


    1. What is Object-Oriented Programming? | 什么是面向对象编程?

    OOP organises code around objects rather than functions and logic. Each object bundles state (fields) and behaviour (methods), which mirrors how we think about real-world things such as students, orders or bank accounts.

    OOP 围绕对象而不是函数与逻辑来组织代码。每个对象将状态(字段)和行为(方法)捆绑在一起,这符合我们对现实事物(如学生、订单或银行账户)的思考方式。

    A key benefit is that changes to one object type are less likely to cause unexpected side effects elsewhere, because the internal state is protected by the object’s own methods.

    一个关键好处是,对某一种对象类型的修改不太可能在其他地方引起意外的副作用,因为内部状态受对象自身方法的保护。

    Procedural approach Functions + shared data
    OOP approach Objects with encapsulated state + methods

    2. Classes and Objects | 类与对象

    A class is a blueprint or template that defines the attributes and methods common to all objects of that type. An object is a specific instance created from a class at runtime.

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

    For example, a Student class may define fields such as name and age, and methods such as enrol(). Each individual student is then an object of that class.

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

    Student s1 = new Student(“Alex”, 17)


    3. Attributes and Methods | 属性与方法

    Attributes describe the state of an object, while methods define the behaviours an object can perform. In many languages, attributes are implemented as fields or properties, and methods as functions defined inside the class.

    属性描述对象的状态,方法定义对象可以执行的行为。在许多语言中,属性实现为字段或属性(property),方法实现为类内部定义的函数。

    Well-designed classes keep related attributes and methods together, which is sometimes called cohesion. A class with high cohesion has one clear purpose and is easier to test and reuse.

    设计良好的类将相关属性和方法放在一起,这有时称为内聚性。具有高内聚性的类只有一个明确目的,因此更易于测试和重用。

    • Attribute example: callDuration, accountBalance, studentName
    • Method example: calculateInterest(), displayDetails(), enrolCourse()
    • 属性示例:callDuration、accountBalance、studentName
    • 方法示例:calculateInterest()、displayDetails()、enrolCourse()

    4. Encapsulation and Visibility | 封装与可见性

    Encapsulation means hiding the internal state of an object and only allowing access through public methods. This protects data from invalid changes and reduces coupling between classes.

    封装意味着隐藏对象的内部状态,只允许通过公共方法进行访问。这可以保护数据免受无效修改,并降低类之间的耦合。

    Access modifiers such as private, public and protected control visibility. A common pattern is to make fields private and provide public getter and setter methods that validate input before changing state.

    privatepublicprotected 等访问修饰符控制可见性。常见模式是将字段设为 private,并提供 public 的 getter 和 setter 方法,在更改状态前先验证输入。

    private Only accessible inside the same class
    public Accessible from any class
    protected Accessible in the class and its subclasses

    5. Constructors and Instantiation | 构造函数与实例化

    A constructor is a special method that runs automatically when a new object is created. It usually gives initial values to attributes and ensures the object starts in a valid state.

    构造函数是一种特殊方法,在创建新对象时自动运行。它通常为属性赋初值,并确保对象一开始就处于有效状态。

    Constructors often have the same name as the class and may be overloaded, meaning a class can provide several constructors with different parameter lists. If no constructor is written, many languages supply a default constructor with no arguments.

    构造函数通常与类同名,并且可以重载,即一个类可以提供多个具有不同参数列表的构造函数。如果没有编写构造函数,许多语言会提供一个无参数的默认构造函数。

    public Student(String n, int a) { name = n; age = a; }


    6. Inheritance and Superclasses | 继承与超类

    Inheritance allows a child class to reuse, extend or modify the attributes and methods of a parent class. The child is called a subclass, and the parent is called a superclass.

    继承允许子类重用、扩展或修改父类的属性和方法。子类称为 subclass,父类称为 superclass。

    For example, a PartTimeStudent class can inherit from Student and add a field for weekly hours. This avoids duplicating shared code and supports the is-a relationship: a part-time student is a student.

    例如,PartTimeStudent 类可以继承 Student 类,并增加每周课时字段。这避免了重复共享代码,并支持 is-a 关系:兼职学生是一名学生。

    • Superclass: Student
    • Subclass: PartTimeStudent
    • Inherited members: name, age, enrol()
    • New members: weeklyHours, calculateLoad()
    • 超类:Student
    • 子类:PartTimeStudent
    • 继承成员:name、age、enrol()
    • 新增成员:weeklyHours、calculateLoad()

    7. Polymorphism and Method Overriding | 多态与方法重写

    Polymorphism means many forms. In OOP it lets one interface be used for objects of different classes, so the correct method is chosen at runtime based on the actual object type.

    多态意味着多种形式。在 OOP 中,它允许一个接口用于不同类的对象,因此在运行时根据实际对象类型选择正确的方法。

    Method overriding occurs when a subclass provides its own version of a method already defined in the superclass. This lets a PartTimeStudent override calculateFees() while a FullTimeStudent provides a different implementation.

    方法重写发生在子类为超类中已定义的方法提供自己的版本时。这样可以让 PartTimeStudent 重写 calculateFees(),而 FullTimeStudent 提供不同的实现。

    Overloading is sometimes confused with overriding: overloading means multiple methods with the same name but different parameter lists within the same class, whereas overriding replaces an inherited method with the same signature.

    重载有时与重写混淆:重载是指同一个类中方法名相同但参数列表不同的多个方法,而重写是用相同签名替换继承的方法。


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

    An abstract class is a class that cannot be instantiated and may contain abstract methods without implementation. Subclasses must implement these abstract methods, which enforces a consistent design.

    抽象类是无法实例化的类,可能包含没有实现的抽象方法。子类必须实现这些抽象方法,从而强制实现一致的设计。

    An interface is similar but contains only method signatures and constants in many languages. A class can implement multiple interfaces, which is useful because many languages only allow single class inheritance.

    接口类似,但在许多语言中只包含方法签名和常量。一个类可以实现多个接口,这很有用,因为许多语言只允许单类继承。

    • Abstract class: can contain state and method bodies
    • Interface: specifies what a class must do, without saying how
    • 抽象类:可以包含状态和方法体
    • 接口:规定类必须做什么,而不规定如何做

    9. Association, Aggregation and Composition | 关联、聚合与组合

    Objects often work together. Association is a general relationship where one object uses or knows about another object. Aggregation and composition are stronger forms that represent whole-part relationships.

    对象经常协同工作。关联是一种一般关系,表示一个对象使用或了解另一个对象。聚合和组合是表示整体-部分关系的更强形式。

    Aggregation means the part can exist independently of the whole, such as a department containing lecturers. Composition means the part cannot exist without the whole, such as a house containing rooms: if the house is destroyed, the rooms are destroyed too.

    聚合意味着部分可以独立于整体存在,例如一个系包含讲师。组合意味着部分不能没有整体而存在,例如房子包含房间:如果房子被摧毁,房间也就被摧毁了。

    Association Uses or knows about another object
    Aggregation Part can exist independently of the whole
    Composition Part cannot exist without the whole

    10. Advantages and Exam Tips | 优势与考试提示

    OOP supports code reuse through inheritance, improves maintainability through encapsulation, and makes large systems easier to model because classes correspond to real-world concepts. Debugging is often easier because data and the code that changes it are kept together.

    OOP 通过继承支持代码重用,通过封装提高可维护性,并且由于类与现实世界概念对应,使大型系统更易于建模。调试通常也更容易,因为数据和修改数据的代码被放在一起。

    In Edexcel exam questions, be precise with terminology: a class is a template, an object is an instance. Use the correct terms superclass and subclass, not parent and child unless the question does. When asked to write a class diagram, show attributes, methods and visibility markers clearly.

    在 Edexcel 考试题中,术语要准确:类是模板,对象是实例。使用正确的术语 superclasssubclass,除非题目本身使用 parent 和 child。当要求绘制类图时,请清楚地标出属性、方法和可见性标记。

    • Identify classes from a scenario: nouns often suggest classes, verbs suggest methods
    • Show encapsulation by making fields private and using public getters/setters
    • Explain inheritance only where an ‘is-a’ relationship truly exists
    • Use method overriding to demonstrate polymorphic behaviour
    • 从场景中识别类:名词通常提示类,动词通常提示方法
    • 通过将字段设为 private 并使用 public getter/setter 来体现封装
    • 仅在真正存在 ‘is-a’ 关系时才使用继承
    • 通过方法重写展示多态行为

    Published by TutorHao | Programming Revision Series | aleveler.com

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

  • Edexcel A-Level Computer Science: Programming Techniques & Data Structures | 爱德思A-Level计算机科学:编程技巧与数据结构

    📚 Edexcel A-Level Computer Science: Programming Techniques & Data Structures | 爱德思A-Level计算机科学:编程技巧与数据结构

    For Edexcel A-Level Computer Science, programming questions test your ability to design, write, trace, and evaluate code using a range of techniques. This article covers the essential programming constructs, data structures, and algorithms you need to master for Paper 1 and the NEA.

    在爱德思 A-Level 计算机科学中,编程题考查你设计、编写、追踪和评估代码的能力,要求掌握多种技巧。本文涵盖你必须掌握的基本编程结构、数据结构与算法,适用于 Paper 1 和非考试评估(NEA)。


    1. Programming Paradigms Overview | 编程范式概览

    A programming paradigm is a fundamental style of programming. Edexcel expects you to compare procedural, object-oriented, and functional approaches, understanding where each is most appropriate.

    编程范式是一种基本的编程风格。爱德思要求你比较过程式、面向对象和函数式方法,并理解各自最适用的场景。

    Procedural programming uses step-by-step instructions and subroutines. Object-oriented programming organises code around objects that combine data and behaviour. Functional programming treats computation as the evaluation of mathematical functions and avoids changing state.

    过程式编程使用逐步指令和子程序。面向对象编程围绕将数据和行为结合在一起的对象来组织代码。函数式编程将计算视为数学函数的求值,并避免改变状态。


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

    Variables are named storage locations whose values can change during execution. Constants are fixed values that cannot be changed once assigned, reducing accidental modification.

    变量是有名称的存储位置,其值在执行过程中可以改变。常量是一旦赋值就不能改变的固定值,可以减少意外修改。

    Common data types include integer, real/float, Boolean, character, and string. Choosing the correct type affects memory usage and the operations that can be performed.

    常见数据类型包括整数、实数/浮点数、布尔型、字符和字符串。选择正确的类型会影响内存使用以及可以执行的操作。

    • Integer: whole numbers such as 3, -12, 0
    • Real/Float: numbers with fractional parts such as 3.14, -0.5
    • Boolean: TRUE or FALSE only
    • Character: a single symbol such as ‘A’, ‘7’, ‘#’
    • String: a sequence of characters such as “TutorHao”
    • 整数:如 3、-12、0 这样的整数
    • 实数/浮点数:带小数部分的数,如 3.14、-0.5
    • 布尔型:只有 TRUE 或 FALSE
    • 字符:单个符号,如 ‘A’、’7’、’#’
    • 字符串:字符序列,如 “TutorHao”

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

    All algorithms can be built from three control structures: sequence, selection, and iteration. Sequence means statements execute one after another in order.

    所有算法都可以由三种控制结构构建:顺序、选择和迭代。顺序意味着语句按顺序一条接一条执行。

    Selection allows the program to choose between different paths based on a condition. Common forms are IF…THEN…ELSE and CASE/SWITCH statements.

    选择允许程序根据条件在不同路径之间进行选择。常见形式是 IF…THEN…ELSE 和 CASE/SWITCH 语句。

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

    迭代重复一段代码。当重复次数已知时使用 FOR 循环,这是确定迭代;当重复取决于条件时使用 WHILE 或 REPEAT…UNTIL 循环,这是非确定迭代。


    4. Subroutines: Procedures and Functions | 子程序:过程与函数

    Subroutines are named blocks of code that can be called from elsewhere in a program. They make code modular, reusable, and easier to test.

    子程序是有名称的代码块,可以从程序的其他位置调用。它们使代码模块化、可重用且更易于测试。

    A procedure performs a task but does not return a value. A function performs a task and returns a value to the calling code.

    过程执行任务但不返回值。函数执行任务并向调用代码返回一个值。

    Parameters allow data to be passed into subroutines. Passing by value copies the data, while passing by reference passes the memory address so changes affect the original variable.

    参数允许将数据传入子程序。按值传递会复制数据,而按引用传递会传递内存地址,因此修改会影响原始变量。


    5. Recursion | 递归

    Recursion is a technique where a subroutine calls itself to solve a smaller instance of the same problem. Every recursive routine must have a base case to stop the recursion.

    递归是一种子程序调用自身来解决同一问题的更小实例的技术。每个递归例程都必须有一个基本情况来停止递归。

    A classic example is the factorial function. For n > 0, factorial(n) = n × factorial(n − 1), with factorial(0) = 1 as the base case.

    一个经典示例是阶乘函数。当 n > 0 时,factorial(n) = n × factorial(n − 1),并以 factorial(0) = 1 作为基本情况。

    factorial(n) = { 1 if n = 0; n × factorial(n − 1) if n > 0 }

    Recursion can be elegant but may use more memory because each call adds a new stack frame. Iterative solutions are often more memory-efficient.

    递归可以很优雅,但可能使用更多内存,因为每次调用都会添加一个新的栈帧。迭代解决方案通常更节省内存。


    6. Arrays and Records | 数组与记录

    An array is a fixed-size, indexed collection of elements of the same data type. Elements are accessed using an index, often starting at 0.

    数组是一种固定大小、带索引的同类型元素集合。元素使用索引访问,通常从 0 开始。

    For example, an array named scores[5] might store five integer test scores. The third element is accessed as scores[2].

    例如,名为 scores[5] 的数组可以存储五个整数测试分数。第三个元素可以通过 scores[2] 访问。

    A record is a data structure that groups related fields of possibly different data types. In Python, a dictionary or a class can represent a record.

    记录是一种将可能不同数据类型的相关字段组合在一起的数据结构。在 Python 中,字典或类可以表示记录。

    Field Data Type Example
    studentID integer 2401
    name string “Ada”
    grade character ‘A’

    7. Lists, Stacks, and Queues | 列表、栈与队列

    A list is a dynamic collection that can grow and shrink. Unlike arrays, lists do not require a fixed size and can hold elements of mixed types in some languages.

    列表是一种可以增长和收缩的动态集合。与数组不同,列表不需要固定大小,并且在某些语言中可以存储混合类型的元素。

    A stack is a last-in-first-out (LIFO) data structure. The main operations are push (add to top), pop (remove from top), and peek (view top element without removing).

    栈是一种后进先出(LIFO)的数据结构。主要操作有 push(压入顶部)、pop(弹出顶部)和 peek(查看顶部元素但不删除)。

    A queue is a first-in-first-out (FIFO) data structure. Elements are added at the rear and removed from the front, like a real queue of people.

    队列是一种先进先出(FIFO)的数据结构。元素在队尾加入,从队头移除,就像真实中排队的人一样。


    8. Searching Algorithms: Linear and Binary Search | 查找算法:线性查找与二分查找

    Linear search examines each element one by one until the target is found or the end is reached. It works on unsorted data and has time complexity O(n).

    线性查找逐个检查每个元素,直到找到目标或到达末尾。它适用于未排序数据,时间复杂度为 O(n)。

    Binary search works only on sorted data. It repeatedly compares the target with the middle element, discarding half the search space each time.

    二分查找只适用于已排序数据。它反复将目标与中间元素比较,每次丢弃一半的搜索空间。

    Binary search has time complexity O(log n), making it much faster than linear search on large datasets. However, the data must be sorted first.

    二分查找的时间复杂度为 O(log n),在大型数据集上比线性查找快得多。但是,数据必须先排序。


    9. Sorting Algorithms: Bubble, Insertion, Merge | 排序算法:冒泡、插入与归并排序

    Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. It has time complexity O(n²) in the worst case.

    冒泡排序反复比较相邻元素,如果顺序错误则交换它们。最坏情况下时间复杂度为 O(n²)。

    Insertion sort builds the sorted list one item at a time by inserting each new item into its correct position. It is efficient for small or nearly sorted lists.

    插入排序通过将每个新项插入到正确位置,一次一项地构建有序列表。它对于小型或接近有序的列表很高效。

    Merge sort is a divide-and-conquer algorithm that splits the list in half, sorts each half recursively, and then merges the sorted halves. It has time complexity O(n log n).

    归并排序是一种分治算法,将列表分成两半,递归地对每半排序,然后合并有序的两半。其时间复杂度为 O(n log n)。


    10. Big-O Notation and Efficiency | 大O表示法与效率

    Big-O notation describes how the running time or memory usage of an algorithm grows as the input size n increases. It focuses on the dominant term and ignores constants.

    大O表示法描述算法的运行时间或内存使用如何随输入规模 n 增长。它关注主导项并忽略常数。

    Common complexities from fastest to slowest include O(1), O(log n), O(n), O(n log n), O(n²), and O(2ⁿ). Constant time is independent of input size.

    从最快到最慢的常见复杂度包括 O(1)、O(log n)、O(n)、O(n log n)、O(n²) 和 O(2ⁿ)。常数时间与输入规模无关。

    For example, accessing an array element by index is O(1), while a nested loop over an n×n grid is O(n²). Choosing efficient algorithms matters for large data.

    例如,通过索引访问数组元素是 O(1),而对 n×n 网格使用嵌套循环是 O(n²)。对于大数据,选择高效算法非常重要。


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

    Object-oriented programming (OOP) models real-world entities as objects. A class is a blueprint, and an object is an instance of that class.

    面向对象编程(OOP)将现实世界实体建模为对象。类是一个蓝图,对象是该类的一个实例。

    Encapsulation bundles data (attributes) and methods that operate on that data into a single unit. It protects data by making attributes private and providing public getter and setter methods.

    封装将数据(属性)与操作这些数据的方法绑定到一个单元中。它通过将属性设为私有并提供公共 getter 和 setter 方法来保护数据。

    Inheritance allows a new class to derive properties and methods from an existing class. Polymorphism lets objects of different classes respond to the same method call in their own way.

    继承允许新类从现有类派生属性和方法。多态让不同类的对象以各自的方式响应同一个方法调用。


    12. Defensive Design and Testing | 防御式设计与测试

    Defensive design anticipates misuse and errors. Techniques include input validation, range checks, length checks, format checks, and presence checks.

    防御式设计预见到误用和错误。相关技术包括输入验证、范围检查、长度检查、格式检查和存在性检查。

    Testing should use normal data, boundary data, invalid data, and erroneous data. Boundary testing is especially important because many errors occur at the edges of valid ranges.

    测试应使用正常数据、边界数据、无效数据和错误数据。边界测试尤其重要,因为许多错误发生在有效范围边缘。

    Trace tables are used to track variable values line by line when checking an algorithm. They help identify logic errors in loops and conditionals.

    跟踪表用于在检查算法时逐行跟踪变量值。它们有助于发现循环和条件中的逻辑错误。

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

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

  • Mastering Searching and Sorting Algorithms | 掌握搜索与排序算法

    📚 Mastering Searching and Sorting Algorithms | 掌握搜索与排序算法

    Searching and sorting are fundamental programming techniques tested in the Edexcel A-Level Computer Science specification. Understanding how each algorithm works, its complexity, and when to use it is essential for both the practical programming unit and the written exam.

    搜索和排序是爱德思 A-Level 计算机科学大纲中的基础编程技术。了解每种算法的工作原理、复杂度以及何时使用,对实践编程单元和笔试都至关重要。


    1. Linear Search | 线性搜索

    Linear search examines each list element from the first to the last, comparing it with the target value. If a match is found, the index is returned; if the loop finishes without a match, the algorithm returns -1 or a ‘not found’ marker.

    线性搜索从第一个元素到最后一个元素依次检查每个列表元素,并与目标值比较。如果找到匹配项,则返回索引;如果循环结束后没有找到匹配项,则返回 -1 或“未找到”标记。

    It works on unsorted lists because it does not rely on any ordering property. It is easy to code, but for a list of n elements it may require up to n comparisons in the worst case.

    它适用于未排序的列表,因为它不依赖任何顺序特性。编码简单,但对于包含 n 个元素的列表,最坏情况可能需要最多 n 次比较。


    2. Binary Search | 二分搜索

    Binary search is a divide-and-conquer technique that requires the list to be sorted in ascending or descending order. It compares the target with the middle element and eliminates half of the search space each time.

    二分搜索是一种分治技术,要求列表按升序或降序排序。它比较目标值与中间元素,每次排除一半搜索空间。

    mid = (low + high) ÷ 2

    If the target equals the middle value, the search ends. If the target is smaller, the search continues in the left half; if larger, in the right half. The process repeats while low ≤ high.

    如果目标值等于中间值,搜索结束。如果目标值较小,则在左半区继续搜索;如果较大,则在右半区继续搜索。当 low ≤ high 时重复此过程。


    3. Comparing Search Algorithms | 比较搜索算法

    Linear search is the only option when the data cannot be sorted, but binary search is significantly faster for large n. The trade-off is the need to maintain sorted order or pay sorting cost first.

    当数据无法排序时,线性搜索是唯一选择;但对于大规模 n,二分搜索明显更快。代价是需要维护有序性,或先付出排序成本。

    Algorithm Data requirement Worst-case time Space
    Linear search Unsorted or sorted O(n) O(1)
    Binary search Sorted O(log n) O(1)

    In exam questions, you must state that binary search requires sorted data and that its O(log n) behaviour comes from repeatedly halving the problem.

    在考试题目中,你必须说明二分搜索需要有序数据,并且其 O(log n) 的行为来自问题的反复减半。


    4. Bubble Sort | 冒泡排序

    Bubble sort works by comparing adjacent pairs and swapping them if they are out of order. After each full pass, the next largest element is placed in its final position at the end of the list.

    冒泡排序通过比较相邻元素对并在顺序错误时交换它们来工作。每完成一次完整遍历,下一个最大元素就会被放到列表末尾的最终位置。

    The algorithm stops when a complete pass makes no swaps, meaning the list is sorted. Worst-case and average-case time complexity are both O(n²).

    当一趟完整遍历没有发生任何交换时,算法停止,这意味着列表已经有序。最坏情况和平均情况的时间复杂度都是 O(n²)。

    (n − 1) + (n − 2) + … + 1 = n(n − 1) ÷ 2

    This formula shows the number of comparisons in the worst case when every adjacent pair has to be compared on every pass.

    该公式显示了最坏情况下的比较次数,即每一趟都必须比较每一对相邻元素。


    5. Insertion Sort | 插入排序

    Insertion sort processes elements one by one, keeping the left side sorted. Each new element is compared with sorted elements from right to left, and larger elements are shifted right until the correct gap is found.

    插入排序逐个处理元素,保持左侧有序。每个新元素从右到左与已排序元素比较,较大的元素右移,直到找到正确位置。

    It is stable, uses O(1) extra space, and runs in O(n) time on an already sorted list. In the worst case, such as a reverse-sorted list, it degrades to O(n²).

    它是稳定的,使用 O(1) 额外空间,在已经有序的列表上运行时间为 O(n)。最坏情况(如逆序列表)会退化到 O(n²)。


    6. Merge Sort | 归并排序

    Merge sort is a recursive divide-and-conquer algorithm. It repeatedly splits the list into halves, sorts each half, and then merges the two sorted halves by comparing the front elements.

    归并排序是一种递归的分治算法。它反复将列表拆分为两半,分别排序,然后通过比较前部元素合并两个有序半区。

    Merge sort has O(n log n) time complexity in all cases and is stable, but it requires O(n) auxiliary space for the merging process.

    归并排序在所有情况下时间复杂度均为 O(n log n),而且是稳定的,但合并过程需要 O(n) 的辅助空间。

    T(n) = 2T(n ÷ 2) + O(n)


    7. Quick Sort | 快速排序

    Quick sort chooses a pivot and partitions the list into two parts: values less than the pivot and values greater than the pivot. The pivot is then in its final position, and the two partitions are sorted recursively.

    快速排序选择一个基准值,将列表划分为两部分:小于基准值的元素和大于基准值的元素。基准值此时处于最终位置,然后递归地对两个分区进行排序。

    The average time complexity is O(n log n), but poor pivot choices on already sorted data can cause O(n²) worst-case performance. It usually sorts in place using O(log n) stack space.

    平均时间复杂度为 O(n log n),但在已经有序的数据上选择较差的基准值可能导致 O(n²) 的最坏性能。它通常在原地排序,使用 O(log n) 栈空间。


    8. Algorithm Efficiency and Big O | 算法效率与大 O 表示法

    Big O notation gives an upper bound on the growth rate of an algorithm’s resource usage. Constants and lower-order terms are ignored because they matter less as n becomes large.

    大 O 表示法给出了算法资源使用增长速率的上界。常数和低阶项被忽略,因为当 n 很大时它们的影响较小。

    Class Example Growth behaviour
    O(1) Indexing an array Constant
    O(log n) Binary search Halving each step
    O(n) Linear search Linear
    O(n log n) Merge sort, quick sort average Linearithmic
    O(n²) Bubble sort, insertion sort worst case Quadratic

    In exam answers, always identify the dominant operation, such as comparisons or swaps, and explain how many times it executes as n grows.

    考试作答时,务必识别主导操作,例如比较或交换,并解释它随着 n 增长执行了多少次。


    9. Choosing the Right Algorithm | 选择合适的算法

    For small lists, simple algorithms such as linear search, bubble sort, and insertion sort are acceptable because their coding simplicity reduces mistakes. For large data, binary search after sorting or merge sort is often preferable.

    对于小列表,简单的算法如线性搜索、冒泡排序和插入排序是可接受的,因为它们编码简单、出错少。对于大规模数据,排序后二分搜索或归并排序通常更可取。

    If stability matters, use insertion sort or merge sort; if average speed and low memory matter, quick sort is a strong candidate. Binary search is only valid on sorted data.

    如果需要稳定性,使用插入排序或归并排序;如果平均速度和低内存更重要,快速排序是很强的候选。二分搜索只对有序数据有效。


    10. Exam-Style Tips | 考试技巧

    A-Level questions often ask you to trace an algorithm on a short list. Use a table with columns for index, values, comparisons, swaps, and pass number. Show every change clearly.

    A-Level 题目常要求对短列表追踪算法。使用包含索引、值、比较、交换和趟数列的表格。清楚地显示每一次变化。

    When explaining complexity, link the reasoning to the algorithm structure: binary search halves the search space, merge sort halves the problem and merges in linear time, bubble and insertion sorts use nested loops.

    解释复杂度时,将推理与算法结构联系起来:二分搜索将搜索空间减半;归并排序将问题减半并以线性时间合并;冒泡排序和插入排序使用嵌套循环。

    • State whether the data must be sorted
    • Identify best, worst, and average cases
    • Use Big O notation with n as the input size
    • Justify comparisons and swaps in your trace

    These habits will help you earn full marks for algorithm explanation and evaluation questions.

    这些习惯将帮助你在算法解释和评估题中获得满分。


    Published by TutorHao | Programming Revision Series | aleveler.com

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

  • Mastering Programming Fundamentals: Data Types, Variables and Operators | 掌握编程基础:数据类型、变量与运算符

    📚 Mastering Programming Fundamentals: Data Types, Variables and Operators | 掌握编程基础:数据类型、变量与运算符

    Programming is at the heart of A Level Computer Science. In the Edexcel specification, you are expected to write, trace and debug code using a high-level language. Understanding data types, variables, operators and expressions gives you the foundation for tackling algorithms, data structures and object-oriented programs.

    编程是 A Level 计算机科学的核心。在 Edexcel 考纲中,要求你使用高级语言编写、跟踪和调试代码。理解数据类型、变量、运算符和表达式,为你解决算法、数据结构和面向对象程序打下基础。

    1. Why Programming Fundamentals Matter | 为什么编程基础重要

    A strong grasp of basic programming concepts prevents errors and improves code readability. Examiners often test your ability to identify the correct data type or predict the result of an expression.

    扎实掌握基本编程概念可以避免错误并提高代码可读性。考官经常考查你识别正确数据类型或预测表达式结果的能力。

    In Edexcel papers, questions may present a short snippet of pseudocode and ask you to state the output, list variables, or explain why a type mismatch occurs. Without solid fundamentals, these questions become unnecessarily difficult.

    在 Edexcel 试卷中,题目可能会给出一小段伪代码,要求你说明输出、列出变量,或解释为什么会出现类型不匹配。如果没有扎实的基础,这些问题会变得异常困难。


    2. Variables and Identifiers | 变量与标识符

    An identifier is the name given to a variable, constant, subroutine or other program element. Most languages require identifiers to start with a letter or underscore, and they cannot be reserved words such as ‘if’, ‘while’ or ‘class’.

    标识符是给变量、常量、子程序或其他程序元素起的名字。大多数语言要求标识符以字母或下划线开头,且不能是保留字,如 ‘if’、’while’ 或 ‘class’。

    A variable is a storage location paired with a symbolic name. Its value can change during execution, whereas a constant cannot be changed after it is initialised.

    变量是与符号名配对的存储位置。它的值在运行期间可以改变,而常量在初始化后不能更改。

    • Choose meaningful names such as studentAge instead of x. 选择有意义的名称,如 studentAge 而不是 x。
    • Declare variables before use in strongly typed languages such as Java or C#. 在强类型语言(如 Java 或 C#)中,变量使用前必须先声明。
    • Follow naming conventions consistently, for example camelCase or snake_case. 始终遵循命名规范,例如 camelCase 或 snake_case。

    3. Primitive Data Types | 基本数据类型

    Primitive types are the built-in basic building blocks: integer, real/float, Boolean, character and string. Each type has a defined range and storage requirement.

    基本类型是内置的基础构件:整数、实数/浮点数、布尔型、字符和字符串。每种类型都有定义的范围和存储要求。

    Type 类型 Example 示例 Notes 备注
    Integer 整数 42 No fractional part 无小数部分
    Real/Float 实数/浮点 3.14 Stores decimal values 存储小数值
    Boolean 布尔型 true / false Used in conditions 用于条件判断
    Character 字符 ‘A’ Single Unicode symbol 单个 Unicode 符号
    String 字符串 “hello” Sequence of characters 字符序列

    4. Composite Data Types | 复合数据类型

    Composite types store multiple values. Arrays, lists, records and objects fall into this category. Arrays have fixed size and use an index that starts at 0 in many languages.

    复合类型存储多个值。数组、列表、记录和对象都属于这一类。数组有固定大小,在许多语言中索引从 0 开始。

    A record groups fields of different types under one name; an object adds methods and encapsulation. Choosing the right composite type affects memory usage and access speed.

    记录将不同类型的字段组合在一个名称下;对象则增加了方法和封装。选择正确的复合类型会影响内存使用和访问速度。

    • Use an array when the number of items is known and fixed. 当项目数量已知且固定时使用数组。
    • Use a list when the size may change dynamically. 当大小可能动态变化时使用列表。
    • Use a record or object when different data items belong together. 当不同数据项属于一个整体时使用记录或对象。

    5. Type Casting and Coercion | 类型转换与强制转换

    Type casting is an explicit conversion such as int(3.7), which truncates to 3. Coercion is an implicit conversion performed by the language, for example adding an integer to a real gives a real.

    类型转换是显式转换,例如 int(3.7) 会截断为 3。强制转换是语言执行的隐式转换,例如整数与实数相加会得到实数。

    Be careful with division: in many languages 7/2 gives 3 if both operands are integers, but 7.0/2 gives 3.5. This subtle difference is often tested in programming questions.

    注意除法:在许多语言中,如果两个操作数都是整数,7/2 结果为 3;而 7.0/2 得到 3.5。这种细微差别在编程题中经常出现。


    6. Arithmetic Operators | 算术运算符

    Standard arithmetic operators include +, -, *, / and modulus (MOD or %). Integer division yields a quotient without a remainder; modulus yields the remainder.

    标准算术运算符包括 +、-、*、/ 和取模(MOD 或 %)。整数除法产生不含余数的商;取模产生余数。

    remainder = a MOD b

    余数 = a MOD b

    Examples: 17 DIV 5 = 3, 17 MOD 5 = 2.

    示例:17 DIV 5 = 3,17 MOD 5 = 2。

    • Use integer division when counting whole groups. 在计算整组次数时使用整数除法。
    • Use modulus to check divisibility or extract digits. 使用取模检查整除性或提取数字。

    7. Relational and Boolean Operators | 关系与布尔运算符

    Relational operators compare values and return a Boolean: =, ≠, <, >, ≤, ≥. Boolean operators include AND, OR, NOT and XOR.

    关系运算符比较值并返回布尔值:=、≠、<、>、≤、≥。布尔运算符包括 AND、OR、NOT 和 XOR。

    A B A AND B A OR B NOT A A XOR B
    true true true true false false
    true false false true false true
    false true false true true true
    false false false false true false

    8. Operator Precedence | 运算符优先级

    Precedence determines the order of evaluation. In most languages, brackets first, then NOT, then multiply/divide/mod, then add/subtract, then relational, then AND, then OR.

    优先级决定求值顺序。大多数语言中,括号优先,然后 NOT,再乘/除/取模,再加减,再关系运算,再 AND,最后 OR。

    result = 2 + 3 × 4 = 14

    结果 = 2 + 3 × 4 = 14

    Use brackets to make intent clear: (2 + 3) × 4 = 20. When in doubt, add brackets even if they are not strictly required.

    使用括号明确意图:(2 + 3) × 4 = 20。如有疑问,即使括号并非严格必要,也建议加上。


    9. Input and Output in Programs | 程序的输入与输出

    Programs interact with users through input and output statements. In Python, input() returns a string; you must cast it to int or float for arithmetic.

    程序通过输入和输出语句与用户交互。在 Python 中,input() 返回字符串;必须将其转换为 int 或 float 才能进行算术。

    Output can be formatted using concatenation or placeholders. Always display prompts and labels so the user knows what is expected.

    输出可以使用拼接或占位符格式化。始终显示提示和标签,让用户知道需要输入什么。


    10. Common Errors and Debugging | 常见错误与调试

    Syntax errors occur when the code breaks grammar rules. Logic errors produce incorrect results but do not crash. Runtime errors happen during execution, such as division by zero or type mismatch.

    语法错误发生在代码违反语法规则时。逻辑错误产生错误结果但不会崩溃。运行时错误在执行期间发生,如除以零或类型不匹配。

    Trace tables help track variable values through each line and are often required in Edexcel exams. They show exactly where a value stops matching your expectation.

    跟踪表有助于逐行跟踪变量值,Edexcel 考试经常要求使用。跟踪表可以准确显示数值在哪一行开始与预期不符。


    11. Worked Example: Applying Operators and Types | 实例演练:应用运算符与类型

    Suppose a program reads two integers and calculates the average. If the sum is stored as an integer, the fractional part is lost. The result must use real division or cast before dividing.

    假设一个程序读取两个整数并计算平均值。如果和以整数存储,小数部分会丢失。结果必须使用实数除法或在除法前转换类型。

    total = a + b

    总和 = a + b

    average = total / 2.0

    平均值 = 总和 / 2.0

    For a = 7, b = 8, average = (7 + 8) / 2.0 = 7.5. If you wrote total / 2 instead, the result would be 7, which is incorrect for a mean.

    当 a = 7、b = 8 时,平均值 = (7 + 8) ÷ 2.0 = 7.5。如果你写成 total / 2,结果会是 7,这对于平均值来说是错误的。


    12. Exam Tips for Edexcel Programming | Edexcel 编程考试技巧

    Edexcel papers often ask you to identify suitable data types, write expressions using correct syntax, and trace code with variables and operators. Practice reading pseudocode and converting it into a chosen language.

    Edexcel 试卷经常要求你确定合适的数据类型,使用正确语法编写表达式,并用变量和运算符跟踪代码。练习阅读伪代码并将其转换为所选语言。

    Show working in trace tables and state the data type of every variable. Avoid ambiguous identifiers and check for integer division mistakes before finalising your answer.

    在跟踪表中展示过程,并说明每个变量的数据类型。避免含义模糊的标识符,并在确定答案前检查整数除法错误。

    Published by TutorHao | Programming Revision Series | aleveler.com

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

  • Mastering Programming for Edexcel A-Level Computer Science | 精通爱德思A-Level计算机科学编程

    📚 Mastering Programming for Edexcel A-Level Computer Science | 精通爱德思A-Level计算机科学编程

    This guide consolidates the programming and algorithmic content assessed in the Edexcel A-Level Computer Science specification. It focuses on core skills such as computational thinking, data structures, recursion, object-oriented programming, and algorithm analysis, with practical exam-style strategies.

    本指南整合了爱德思A-Level计算机科学大纲中考查的编程与算法内容。它聚焦核心技能,包括计算思维、数据结构、递归、面向对象编程和算法分析,并提供实用的考试策略。

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

    Computational thinking includes abstraction, decomposition, pattern recognition, and algorithmic design. These techniques allow programmers to model complex real-world problems and build structured solutions.

    计算思维包括抽象、分解、模式识别和算法设计。这些技术让程序员能够对复杂的现实问题进行建模,并构建结构化的解决方案。

    Decomposition means splitting a large task into smaller, manageable sub-tasks. Each sub-task can be implemented and tested independently before integration.

    分解是指将大任务拆分成更小、可管理的子任务。每个子任务可以在集成前独立实现和测试。

    Abstraction removes unnecessary detail and keeps only the features relevant to the problem. For example, a bank system may model a customer with name, account number, and balance, ignoring height or favourite colour.

    抽象去除不必要的细节,只保留与问题相关的特征。例如,银行系统可以只用姓名、账号和余额来建模客户,而忽略身高或最喜欢的颜色。

    Pattern recognition identifies similarities between problems so that known solutions can be reused. This reduces development time and improves reliability.

    模式识别找出问题之间的相似之处,从而可以复用已知的解决方案。这能减少开发时间并提高可靠性。


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

    Variables store data values that can change during program execution. Constants store values that do not change, improving readability and reducing errors.

    变量存储程序执行期间可以改变的数据值。常量存储不变的值,从而提高可读性并减少错误。

    Common primitive data types include integer, real/float, Boolean, and character. Edexcel pseudocode also uses string, date, and composite types such as records and arrays.

    常见的基本数据类型包括整数、实数/浮点数、布尔值和字符。爱德思伪代码还使用字符串、日期以及记录和数组等复合类型。

    Type conversion, or casting, changes data from one type to another, such as converting an integer to a real number. Programmers must be careful when dividing integers, because integer division truncates the fractional part.

    类型转换(casting)将数据从一种类型转换为另一种类型,例如将整数转换为实数。程序员在进行整数除法时必须小心,因为整数除法会截断小数部分。

    Using appropriate data types can prevent overflow and preserve precision. For instance, currency should be stored as a decimal type rather than a binary floating-point type where possible.

    使用合适的数据类型可以防止溢出并保持精度。例如,在可能的情况下,货币应使用十进制类型存储,而不是二进制浮点类型。


    3. Control Structures: Sequence, Selection, Iteration | 顺序、选择与迭代

    The three fundamental control structures are sequence, selection, and iteration. Every procedural program can be built from these building blocks.

    三种基本控制结构是顺序、选择与迭代。每一个过程式程序都可以由这些构建块构成。

    Sequence executes statements one after another in the order written. Selection uses IF, ELSE IF, ELSE, or CASE statements to choose between alternative paths.

    顺序按写入的顺序逐条执行语句。选择使用 IF、ELSE IF、ELSE 或 CASE 语句在不同路径之间进行选择。

    Iteration repeats a block of code. Count-controlled iteration uses FOR loops with a known number of repetitions, while condition-controlled iteration uses WHILE or REPEAT…UNTIL loops.

    迭代重复执行一段代码。计数控制迭代使用已知重复次数的 FOR 循环,而条件控制迭代使用 WHILE 或 REPEAT…UNTIL 循环。

    You may be asked to write pseudocode for validating input, calculating totals, or searching within a loop. Trace tables help track variable changes at each step.

    考试中可能要求编写伪代码来验证输入、计算总和或在循环中搜索。跟踪表有助于记录每一步变量的变化。


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

    A function returns a single value and is often used in expressions, such as length(name) or sqrt(x). A procedure performs a task and does not need to return a value, such as printMenu().

    函数返回一个值,通常用于表达式,如 length(name) 或 sqrt(x)。过程执行某个任务,不一定返回值,如 printMenu()。

    Parameters allow subroutines to accept input. 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 after the subroutine ends. In many programming languages, arrays and objects are passed by reference by default.

    按引用传递使子程序可以访问原始内存位置,因此更改在子程序结束后仍然保留。在许多编程语言中,数组和对象默认按引用传递。

    Using local variables rather than global variables improves modularity and reduces unintended side effects.

    使用局部变量而不是全局变量可以提高模块化程度并减少意外的副作用。


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

    Recursion is a programming technique in which a subroutine calls itself. A correct recursive solution must have a base case that stops recursion and a recursive case that moves towards the base case.

    递归是一种子程序调用自身的编程技术。正确的递归解决方案必须有一个停止递归的基准情形,以及一个向基准情形靠近的递归情形。

    For example, factorial(n) = n × factorial(n − 1), with factorial(0) = 1 as the base case. Without a base case, the recursion would be infinite and cause a stack overflow.

    例如,factorial(n) = n × factorial(n − 1),基准情形为 factorial(0) = 1。如果没有基准情形,递归将无限进行并导致栈溢出。

    Each recursive call creates a new stack frame containing local variables and the return address. The call stack grows with each call and unwinds as base cases are returned.

    每一次递归调用都会创建一个新的栈帧,其中包含局部变量和返回地址。调用栈随着每次调用而增长,并在基准情形返回时逐步展开。

    Recursion is elegant for tree traversal and divide-and-conquer algorithms, but iterative solutions can be more memory-efficient.

    递归在树遍历和分治算法中非常优雅,但迭代解决方案可能更节省内存。


    6. Linear Data Structures: Arrays, Lists, Stacks, Queues | 线性数据结构:数组、列表、栈、队列

    Arrays are static, fixed-size collections of elements of the same data type. Elements are accessed by index, usually starting at 0.

    数组是静态的、大小固定的同类型元素集合。元素通过索引访问,索引通常从 0 开始。

    Lists are dynamic structures that can grow and shrink. A linked list stores each element as a node containing data and a pointer to the next node.

    列表是可以动态扩展和收缩的结构。链表将每个元素存储为节点,节点包含数据和指向下一个节点的指针。

    A stack is a last-in, first-out (LIFO) structure. Common operations are push, pop, and peek. Stacks support recursion and undo features.

    栈是一种后进先出(LIFO)结构。常见操作有 push、pop 和 peek。栈支持递归和撤销功能。

    A queue is a first-in, first-out (FIFO) structure. Common operations are enqueue and dequeue. Queues model waiting lines and keyboard buffers.

    队列是一种先进先出(FIFO)结构。常见操作有 enqueue 和 dequeue。队列用于模拟排队和键盘缓冲区。

    Choose the right data structure based on access patterns. Arrays give O(1) indexed access; linked lists allow O(1) insertion if the node position is known.

    根据访问模式选择正确的数据结构。数组提供 O(1) 的索引访问;如果已知节点位置,链表允许 O(1) 插入。


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

    Linear search checks each element sequentially until the target is found or the end is reached. It works on unsorted data and has O(n) time complexity.

    线性搜索从头到尾依次检查每个元素,直到找到目标或到达末尾。它适用于未排序数据,时间复杂度为 O(n)。

    Binary search repeatedly divides a sorted list in half. It compares the middle element with the target and discards the half that cannot contain the target. Its time complexity is O(log n).

    二分搜索不断将已排序列表分成两半。它将中间元素与目标进行比较,并排除不可能包含目标的那一半。时间复杂度为 O(log n)。

    Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. After each pass, the largest unsorted element bubbles to the end.

    冒泡排序反复比较相邻元素,如果顺序错误就交换它们。每一趟之后,未排序部分的最大元素会“冒泡”到末尾。

    Insertion sort builds a sorted portion by inserting each new element into its correct position. Merge sort recursively splits the list and merges sorted halves; it is more efficient for large lists.

    插入排序通过将每个新元素插入到正确位置来构建有序区。归并排序递归地拆分列表并合并有序的两半;对于大型列表,它效率更高。

    For Edexcel questions, be

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

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

  • Mastering Edexcel A-Level Programming: Core Constructs, Algorithms and Exam Technique | 精通 Edexcel A-Level 编程:核心结构、算法与应试技巧

    📚 Mastering Edexcel A-Level Programming: Core Constructs, Algorithms and Exam Technique | 精通 Edexcel A-Level 编程:核心结构、算法与应试技巧

    In Edexcel A-Level Computer Science, programming is assessed both through written pseudocode and through practical project work. A strong grasp of core constructs, data structures and common algorithms is essential for Paper 1 and the non-exam assessment. This revision guide breaks down the high-yield topics with paired English-Chinese notes.

    在 Edexcel A-Level 计算机科学中,编程既通过书面伪代码考核,也通过实践项目评估。扎实掌握核心结构、数据结构和常见算法对 Paper 1 和课程作业至关重要。本复习指南以中英对照笔记拆解高频考点。


    1. Understanding the Edexcel Programming Paper | 了解 Edexcel 编程试卷

    Edexcel A-Level Computer Science Paper 1 (9CN0/01) uses an ‘Edexcel Pseudocode’ style, so you must trace code, correct errors and complete algorithms. Questions often ask you to dry-run loops, arrays and subroutines, so reading code is as important as writing it.

    Edexcel A-Level 计算机科学 Paper 1(9CN0/01)使用 ‘Edexcel 伪代码’ 风格,因此你必须能跟踪代码、纠正错误并补全算法。题目经常要求手工执行循环、数组和子程序,因此读代码与写代码同样重要。

    Key topics include data types, program flow, functions, file handling, recursion and SQL. The practical programming project is marked against coding style, robustness and problem decomposition.

    关键主题包括数据类型、程序流程、函数、文件处理、递归和 SQL。实践编程项目的评分依据包括代码风格、健壮性和问题分解。


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

    Use integer, real, Boolean, character and string types precisely. Python is dynamically typed but Edexcel pseudocode expects you to declare variables and choose suitable types, e.g. DECLARE age AS INTEGER.

    准确使用整数、实数、布尔值、字符和字符串类型。Python 是动态类型,但 Edexcel 伪代码要求你声明变量并选择合适类型,例如 DECLARE age AS INTEGER。

    Type conversions such as INT(), STR() and FLOAT() appear frequently; forgetting to convert input before arithmetic is a common error. Always initialise variables to avoid undefined-value errors in trace tables.

    类型转换如 INT()、STR() 和 FLOAT() 经常出现;在算术运算前忘记转换输入是一个常见错误。始终初始化变量,以避免跟踪表中出现未定义值的错误。


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

    The three basic constructs are sequence, selection (IF…ELSE, CASE) and iteration (FOR, WHILE, REPEAT…UNTIL). You must know when a WHILE loop can execute zero times and when a REPEAT loop always runs at least once.

    三种基本结构是顺序、选择(IF…ELSE、CASE)和迭代(FOR、WHILE、REPEAT…UNTIL)。你必须知道 WHILE 循环何时可能执行零次,以及 REPEAT 循环何时至少执行一次。

    Nested IF statements and loops are high-risk in trace-table questions, so indent clearly and check boundary conditions such as < versus <=. A single off-by-one error can make an algorithm fail hidden test data.

    嵌套 IF 语句和循环在跟踪表问题中风险很高,所以要清晰缩进并检查边界条件,例如 < 与 <= 的区别。一个差一错误就可能让算法在隐藏测试数据中失败。


    4. Subroutines and Parameter Passing | 子程序与参数传递

    Procedures and functions break code into reusable blocks. A function returns a value; a procedure does not. Parameters may be passed by value or by reference, which affects whether changes persist outside the subroutine.

    过程和函数将代码分解为可重用块。函数返回值,过程不返回值。参数可以按值或按引用传递,这会影响更改是否在子程序外持续存在。

    Be able to write a function header such as FUNCTION calcArea(radius AS REAL) RETURNS REAL and trace local versus global variables. Local variables are destroyed when the subroutine ends, while global variables retain their values.

    能够编写函数头,例如 FUNCTION calcArea(radius AS REAL) RETURNS REAL,并跟踪局部变量与全局变量。局部变量在子程序结束时销毁,而全局变量保留其值。


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

    Recursion means a subroutine calls itself. It needs a base case to stop and a recursive case that reduces the problem, such as factorial or Fibonacci. Each call creates a stack frame holding parameters and return address.

    递归意味着子程序调用自身。它需要一个停止的基准情况和一个缩小问题的递归情况,例如阶乘或斐波那契。每次调用创建一个栈帧,保存参数和返回地址。

    Stack overflow occurs if the base case is missing or never reached. You may be asked to trace recursive calls and show how values are returned back up the stack, so keep a separate column for the call stack in your trace table.

    如果缺少基准情况或永远无法达到基准情况,就会发生栈溢出。你可能会被要求跟踪递归调用并展示值如何沿栈返回,因此在跟踪表中为调用栈单独留一列。


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

    Arrays store multiple items under one identifier using indices. Edexcel pseudocode often uses square brackets: names[0] to names[4] for a five-element array. 2D arrays are useful for grids, tables and game boards, accessed as grid[row, column].

    数组使用一个标识符和索引存储多个项目。Edexcel 伪代码通常使用方括号:names[0] 到 names[4] 表示五元素数组。二维数组适用于网格、表格和棋盘,访问方式为 grid[row, column]。

    Know how to initialise arrays, find length, iterate through elements and avoid off-by-one errors when using 0-based indexing. Many exam questions ask you to complete an algorithm that searches, counts or totals values inside an array.

    知道如何初始化数组、求长度、遍历元素,并在使用从 0 开始的索引时避免差一错误。许多考题要求你补全在数组中查找、计数或求和的算法。


    7. String Handling and File I/O | 字符串处理与文件读写

    String operations include concatenation, substring extraction, length, character access and case conversion. Edexcel questions may ask you to extract initials, count vowels or reverse a string using pseudocode.

    字符串操作包括连接、提取子串、求长度、字符访问和大小写转换。Edexcel 题目可能要求你使用伪代码提取首字母、统计元音或反转字符串。

    File handling requires OPEN, READ, WRITE and CLOSE. You should be able to process a text file line by line, testing for EOF and handling invalid data safely. Use a loop with WHILE NOT EOF to read until the end of the file.

    文件处理需要 OPEN、READ、WRITE 和 CLOSE。你应该能逐行处理文本文件,测试 EOF 并安全处理无效数据。使用 WHILE NOT EOF 循环读取直到文件末尾。


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

    Linear search has O(n) time; binary search needs a sorted list and has O(log n). You must be able to write both and explain why binary search is faster for large data sets.

    线性查找的时间复杂度为 O(n);二分查找需要有序列表,时间复杂度为 O(log n)。你必须能编写这两种算法,并解释为什么二分查找对大数据集更快。

    Bubble sort, insertion sort and merge sort are common. Bubble sort compares adjacent items and swaps them; merge sort uses divide and conquer. Be ready to compare their efficiency and stability.

    冒泡排序、插入排序和归并排序是常见算法。冒泡排序比较相邻项并交换;归并排序使用分治法。准备好比较它们的效率和稳定性。

    Algorithm | 算法 Best | 最好 Worst | 最坏 Stable? | 稳定?
    Bubble Sort | 冒泡排序 O(n) O(n²) Yes | 是
    Insertion Sort | 插入排序 O(n) O(n²) Yes | 是
    Merge Sort | 归并排序 O(n log n) O(n log n) Yes | 是

    9. Trace Tables and Dry Runs | 跟踪表与手工执行

    A trace table records variable values, conditions and outputs as each line executes. Always add columns for key variables, loop counters and Boolean tests, then update row by row.

    跟踪表记录每行执行时的变量值、条件和输出。始终为关键变量、循环计数器和布尔测试添加列,然后逐行更新。

    When a question says ‘complete the trace table’, show values after each iteration, including values that do not change, and mark final output

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

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

  • Edexcel A-Level Programming: Algorithms, Paradigms and Data Structures | 爱德思A-Level编程:算法、范式与数据结构

    📚 Edexcel A-Level Programming: Algorithms, Paradigms and Data Structures | 爱德思A-Level编程:算法、范式与数据结构

    Programming is the heart of the Edexcel A-Level Computer Science specification. It requires you to combine computational thinking, precise algorithm design, data structures and clear pseudocode to solve problems. This article revises the core programming topics tested by Edexcel, with practical examples and exam-focused explanations.

    编程是爱德思A-Level计算机科学课程的核心。它要求你把计算思维、精确的算法设计、数据结构和清晰的伪代码结合起来解决问题。本文复习爱德思考纲重点考查的编程主题,并配以实例和应试导向的讲解。


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

    Computational thinking is the foundation of Edexcel A-Level Programming. It involves decomposition, pattern recognition, abstraction and algorithm design. Decomposition means breaking a complex problem into smaller, manageable sub-problems. For example, a chess game can be decomposed into move validation, board display, AI opponent and win detection. Pattern recognition identifies similarities between current and past problems, allowing reuse of solutions. Abstraction focuses on relevant details while ignoring unnecessary complexity, such as modelling a student record by name, ID and grades only. Algorithm design then expresses the solution as a precise sequence of steps.

    计算思维是爱德思A-Level编程的基础,包括分解、模式识别、抽象和算法设计。分解指把复杂问题拆分为更小、可控的子问题,例如国际象棋可分为走子验证、棋盘显示、AI对手和胜负判定。模式识别找出当前问题与过去问题的相似点,从而复用已有解法。抽象只关注相关细节并忽略无关复杂性,例如用姓名、学号和成绩来建模学生记录。算法设计则把解法表达为精确的步骤序列。

    In exam questions, you may be given a real-world scenario and asked to identify the key inputs, processes and outputs before writing pseudocode. A clear decomposition table often earns method marks even if the final algorithm is incomplete.

    在考试题目中,你可能会看到一个现实情景,并被要求在编写伪代码前识别关键输入、处理和输出。清晰的问题分解表往往能获得方法分,即使最终算法不完整。


    2. Algorithm Design and Pseudocode | 算法设计与伪代码

    Edexcel pseudocode uses keywords such as SET, IF … THEN … ELSE … END IF, WHILE … END WHILE, FOR … END FOR and PRINT. Variables are assigned with SET or the left arrow. Input is often shown as INPUT or RECEIVE. When writing pseudocode, keep indentation consistent and make the purpose of each block clear.

    爱德思伪代码使用 SET、IF … THEN … ELSE … END IF、WHILE … END WHILE、FOR … END FOR 和 PRINT 等关键字。变量用 SET 或左箭头赋值,输入常用 INPUT 或 RECEIVE。写伪代码时,要保持缩进一致,并让每个代码块的意图清晰。

    A simple pseudocode example that sums the integers from 1 to 10 is shown below. Notice how the loop variable is initialised and updated explicitly.

    下面是一个将 1 到 10 的整数相加的简单伪代码示例。注意循环变量是如何被显式初始化和更新的。

    SET total TO 0
    FOR i FROM 1 TO 10
      SET total TO total + i
    END FOR
    PRINT total

    Examiners value clarity over cleverness. Always name variables meaningfully, avoid infinite loops by updating loop counters, and use consistent indentation. If a function is required, include its parameters and a RETURN statement.

    考官重视清晰性胜过技巧性。变量命名要有意义,避免无限循环要更新循环计数器,并保持一致的缩进。如果题目要求写函数,要包含参数和 RETURN 语句。


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

    Procedural programming organises code into procedures or functions that operate on data. It follows a top-down design and uses sequence, selection and iteration. Object-oriented programming (OOP) models real-world entities as objects that combine state (attributes) and behaviour (methods). Key OOP concepts tested by Edexcel include encapsulation, inheritance, polymorphism and association.

    过程式编程把代码组织为对数据进行操作的过程或函数,采用自顶向下设计,使用顺序、选择和迭代。面向对象编程把现实世界实体建模为对象,对象把状态(属性)和行为(方法)结合。爱德思考纲考查的OOP关键概念包括封装、继承、多态和关联。

    Encapsulation hides internal state by making attributes private and exposing public methods. Inheritance allows a subclass to reuse and extend a superclass. Polymorphism enables one interface to behave differently depending on the object type. Association describes how objects interact, such as a Library class containing many Book objects.

    封装通过把属性设为私有、暴露公有方法来隐藏内部状态。继承允许子类复用并扩展父类。多态使同一接口能根据对象类型表现不同行为。关联描述对象如何交互,例如一个 Library 类包含多个 Book 对象。

    When comparing paradigms, state the benefits of OOP: code reuse through inheritance, easier maintenance through encapsulation, and more natural modelling of real-world systems. Procedural programming can be simpler for small programs and direct algorithmic tasks.

    在比较范式时,要说明OOP的好处:通过继承实现代码复用,通过封装使维护更容易,以及对现实系统进行更自然的建模。过程式编程对于小程序和直接算法任务可以更简单。


    4. Data Types and Core Data Structures | 数据类型与核心数据结构

    Edexcel expects knowledge of primitive data types: integer, real/float, Boolean, character and string. Composite data structures include arrays, lists, records, sets, stacks, queues, trees and hash tables. Arrays store fixed-size ordered elements of the same type and allow direct indexing. Lists are dynamic and allow insertion/deletion at any position. Records group related fields of possibly different types.

    爱德思考纲要求掌握基本数据类型:整数、实数/浮点数、布尔、字符和字符串。复合数据结构包括数组、列表、记录、集合、栈、队列、树和哈希表。数组存储固定大小、相同类型的有序元素,支持直接索引。列表是动态的,可在任意位置插入或删除。记录将可能不同类型的相关字段分组。

    Stacks follow Last In First Out (LIFO); queues follow First In First Out (FIFO). Trees, especially binary search trees, support efficient search, insertion and deletion. Hash tables provide average-case constant time lookup via a hash function, but can degrade when many collisions occur.

    栈遵循后进先出(LIFO);队列遵循先进先出(FIFO)。树,尤其是二叉搜索树,支持高效搜索、插入和删除。哈希表通过哈希函数提供平均情况下的常数时间查找,但当冲突很多时性能会下降。

    You must be able to choose an appropriate data structure for a scenario. For example, a printer queue should use a queue, an undo feature should use a stack, and a phone contact search should use a hash table or binary search tree.

    你必须能为情景选择合适的数据结构。例如,打印机队列应使用队列,撤销功能应使用栈,电话联系人搜索应使用哈希表或二叉搜索树。


    5. Searching Algorithms | 搜索算法

    Linear search checks each element in turn until the target is found or the list ends. It works on unsorted data and has O(n) time complexity. Binary search repeatedly halves a sorted list by comparing the middle element to the target. Its time complexity is O(log n), making it much faster on large sorted lists.

    线性搜索依次检查每个元素,直到找到目标或列表结束。它适用于未排序数据,时间复杂度为 O(n)。二分搜索通过将中间元素与目标比较,不断将有序列表折半,时间复杂度为 O(log n),在大型有序列表上快得多。

    In an exam, you must be able to trace both algorithms and state the condition under which each is appropriate. Binary search requires random access and a sorted array; linear search works on any list, including linked lists.

    考试中你必须能够跟踪两种算法,并说明各自适用的条件。二分搜索需要随机访问和有序数组;线性搜索适用于任何列表,包括链表。


    6. Sorting Algorithms | 排序算法

    Bubble sort repeatedly compares adjacent elements and swaps them if they are in the wrong order, pushing the largest element to the end on each pass. Insertion sort builds a sorted sublist by taking each new element and inserting it into its correct position. Merge sort is a divide-and-conquer algorithm that splits the list in half, recursively sorts each half and merges the two sorted halves.

    冒泡排序反复比较相邻元素并在顺序错误时交换,每一趟把最大元素推到末尾。插入排序通过取出每个新元素并插入正确位置来构建有序子表。归并排序是一种分治算法,将列表对半拆分,递归排序每一半,再合并两个有序半表。

    Edexcel questions often ask for a trace, the number of comparisons or swaps, and the time complexity of each algorithm. The table below summarises the common sorting algorithms and their complexities.

    爱德思题目常要求跟踪排序过程、给出比较或交换次数以及每种算法的时间复杂度。下表总结了常见排序算法及其复杂度。

    Algorithm Best Case Average Case Worst Case Space
    Bubble sort O(n) O(n²) O(n

    Published by TutorHao | A-Level 编程 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 core topic in the Edexcel A-Level Programming unit. Understanding classes, objects, inheritance and related concepts is essential for both exam questions and practical programming tasks.

    面向对象编程(OOP)是 Edexcel A-Level 编程单元的核心主题。理解类、对象、继承及相关概念对考试题和实际编程任务都至关重要。


    1. Introduction to Programming Paradigms | 编程范式概述

    A programming paradigm is a fundamental style of writing code. Edexcel candidates should be able to compare procedural programming, object-oriented programming, and event-driven programming. In OOP, code is organised around objects that combine data and behaviour, whereas procedural programming separates data and functions.

    编程范式是编写代码的基本风格。Edexcel 考生应能比较过程式编程、面向对象编程和事件驱动编程。在面向对象编程中,代码围绕结合数据与行为的对象组织,而过程式编程将数据与函数分离。


    2. Classes and Objects | 类与对象

    A class is a template that defines the common attributes and methods of a category of objects. An object is a concrete instance created from that template. For example, a class called Student might have attributes such as name and age, and methods such as enrol().

    类是定义某类对象共同属性和方法的模板。对象是根据该模板创建的具体实例。例如,名为 Student 的类可能具有 name 和 age 等属性,以及 enrol() 等方法。

    class Student:
        def __init__(self, name, age):
            self.name = name
            self.age = age
    
        def enrol(self):
            return self.name + " is enrolled"
    
    s1 = Student("Ali", 17)
    print(s1.enrol())
    

    The code above defines a Student class and creates an object s1. The constructor assigns values to instance attributes, and the method returns a message.

    上面的代码定义了一个 Student 类并创建了对象 s1。构造函数为实例属性赋值,方法返回一条消息。


    3. Attributes and Methods | 属性与方法

    Attributes represent the state of an object; methods represent its behaviour. Instance attributes are stored separately for each object, while class attributes are shared by all instances. In Edexcel pseudocode, attributes are often shown in class definitions with their data types.

    属性表示对象的状态;方法表示其行为。实例属性为每个对象单独存储,而类属性由所有实例共享。在 Edexcel 伪代码中,属性通常在类定义中与其数据类型一起显示。


    4. Encapsulation | 封装

    Encapsulation hides an object’s internal data and only exposes necessary methods. This protects data integrity and reduces unintended interference. In Python, a leading underscore indicates a protected member, and a double underscore activates name mangling for a private-like member.

    封装隐藏对象的内部数据,只公开必要的方法。这保护了数据完整性并减少意外干扰。在 Python 中,前导单下划线表示受保护成员,双下划线会触发名称改写,形成类似私有成员。


    5. Constructors and Instantiation | 构造函数与实例化

    A constructor is a special method that initialises a new object. In Python, the constructor is named __init__. The parameter self refers to the current instance being created. Instantiation is the process of allocating memory and calling the constructor.

    构造函数是初始化新对象的特殊方法。在 Python 中,构造函数名为 __init__。参数 self 指向正在创建的当前实例。实例化是分配内存并调用构造函数的过程。


    6. Inheritance | 继承

    Inheritance allows one class to acquire the attributes and methods of another class. The existing class is the parent or superclass; the new class is the child or subclass. The child can add new members or modify inherited members.

    继承允许一个类获得另一个类的属性和方法。已有的类是父类或超类;新类是子类。子类可以添加新成员或修改继承的成员。

    class Shape:
        def area(self):
            return 0
    
    class Rectangle(Shape):
        def __init__(self, width, height):
            self.width = width
            self.height = height
    
        def area(self):
            return self.width * self.height
    

    Here Rectangle inherits from Shape and overrides the area method to compute the correct result.

    此处 Rectangle 继承自 Shape,并重写 area 方法以计算正确结果。


    7. Polymorphism and Method Overriding | 多态与方法重写

    Polymorphism lets a single method name behave differently depending on the object that calls it. Method overriding is the key mechanism: a subclass provides its own version of a method defined in the superclass. This supports flexibility and cleaner code.

    多态允许同一个方法名根据调用它的对象表现出不同行为。方法重写是关键机制:子类为超类中定义的方法提供自己的版本。这支持了灵活性和更简洁的代码。


    8. Association, Aggregation and Composition | 关联、聚合与组合

    Class relationships are important in object-oriented design. Association is a general relationship such as a teacher and a student. Aggregation is a ‘has-a’ relationship in which the part can exist independently, such as a department and a teacher. Composition is stronger: the part cannot exist without the whole, such as a house and a room.

    类之间的关系在面向对象设计中很重要。关联是一般关系,如教师和学生。聚合是 ‘has-a’ 关系,其中部分可以独立存在,如部门和教师。组合更强:部分不能脱离整体存在,如房子和房间。


    9. Advantages and Disadvantages of OOP | 面向对象的优点与缺点

    Advantages include improved modularity, code reuse through inheritance, easier maintenance and better modelling of real-world systems. Disadvantages include a steeper learning curve, potential performance overhead, and unnecessary complexity for very small programs.

    优点包括改进的模块化、通过继承实现代码重用、更容易维护以及更好地对现实系统建模。缺点包括学习曲线更陡、潜在的性能开销,以及对非常小的程序可能带来不必要的复杂性。


    10. Design and Exam-Style Questions | 设计与考试题型

    Edexcel exam questions often ask you to identify classes, attributes, methods and relationships from a scenario, or to outline the advantages of OOP. You should practise drawing simple UML class diagrams and converting them into code.

    Edexcel 考试题目通常要求你从场景中识别类、属性、方法和关系,或概述面向对象的优点。你应练习绘制简单的 UML 类图并将其转换为代码。

    • Read the scenario carefully and underline nouns for potential classes.
    • Underline verbs for potential methods.
    • Check inheritance relationships for ‘is-a’ and aggregation for ‘has-a’.

    阅读场景并仔细标出名词作为潜在的类;标出动词作为潜在的方法;检查 ‘is-a’ 继承关系和 ‘has-a’ 聚合关系。


    11. Common Mistakes and Exam Tips | 常见错误与考试提示

    Many candidates confuse a class with an object. Remember: the class is the blueprint, and the object is the instance. Another common mistake is forgetting to use the constructor correctly or misunderstanding the difference between aggregation and composition.

    许多考生混淆类和对象。记住:类是蓝图,对象是实例。另一个常见错误是未能正确使用构造函数,或误解聚合与组合的区别。

    Tip: when writing inheritance, always ask whether the relationship is truly ‘is-a’. If not, use association or composition instead of inheritance.

    提示:在编写继承时,始终问自己关系是否真的是 ‘is-a’。如果不是,请使用关联或组合而不是继承。


    Published by TutorHao | Programming Revision Series | aleveler.com

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

  • A-Level Edexcel Programming: Operators, Control Structures and OOP | A-Level Edexcel 编程:运算符、控制结构与面向对象

    📚 A-Level Edexcel Programming: Operators, Control Structures and OOP | A-Level Edexcel 编程:运算符、控制结构与面向对象

    Programming forms the core of the Edexcel A-Level Computer Science specification. To succeed in Paper 2 you must be confident in using pseudocode to express data types, operators, selection, iteration, subroutines and object-oriented principles.

    编程是 Edexcel A-Level 计算机科学课程的核心。要想在 Paper 2 中取得好成绩,你必须熟练使用伪代码表达数据类型、运算符、选择结构、迭代结构、子程序以及面向对象原则。


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

    Every value in a program belongs to a data type. The most common primitive types tested by Edexcel are integer, real, Boolean, character and string.

    程序中的每个值都属于某种数据类型。Edexcel 考查的最常见原始类型包括整型、实数型、布尔型、字符型和字符串型。

    Variables are named storage locations. You should declare them with a name and type before use, for example DECLARE age AS INTEGER.

    变量是命名的存储位置。你应该在使用前用名称和类型声明它们,例如 DECLARE age AS INTEGER

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

    整型:如 -3、0、42 等整数;实数型

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

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

  • Edexcel A-Level Programming: Control Structures, Data Structures and Algorithm Efficiency | 爱德思A-Level编程:控制结构、数据结构与算法效率

    📚 Edexcel A-Level Programming: Control Structures, Data Structures and Algorithm Efficiency | 爱德思A-Level编程:控制结构、数据结构与算法效率

    In Edexcel A Level Computer Science, programming questions test both your ability to write clear pseudocode and your understanding of how data structures and algorithms behave under different conditions. A strong revision method is to learn the theory and then apply it through hand tracing, because examiners reward precise use of terminology and systematic problem solving.

    在爱德思A Level计算机科学中,编程题既考查你编写清晰伪代码的能力,也考查你对数据结构和算法在不同条件下表现的理解。有效的复习方法是先掌握理论,再通过手工跟踪来应用,因为考官会奖励准确使用术语和系统化解决问题的能力。


    1. Programming Constructs: Sequence, Selection and Iteration | 编程结构:顺序、选择和迭代

    All programs are built from three fundamental constructs: sequence, selection and iteration. Sequence means statements are executed one after another in the order written. Selection allows the program to choose between alternative paths using conditions, such as IF, ELSE IF and ELSE statements, or CASE/SWITCH for multiple exclusive branches.

    所有程序都由三种基本结构组成:顺序、选择和迭代。顺序指语句按照书写顺序一条接一条执行。选择使程序能够使用条件在多个路径之间进行选择,例如 IF、ELSE IF 和 ELSE 语句,或者使用 CASE/SWITCH 处理多个互斥分支。

    Iteration repeats a block of code. Definite iteration uses FOR loops when the number of repetitions is known in advance, while indefinite iteration uses WHILE or REPEAT…UNTIL loops when the loop must continue until a condition changes. Edexcel pseudocode expects you to identify which type is most appropriate for a given problem.

    迭代重复执行一段代码。当重复次数事先已知时,使用 FOR 循环进行确定迭代;当循环必须持续到某个条件改变时,使用 WHILE 或 REPEAT…UNTIL 循环进行非确定迭代。爱德思伪代码要求你能够识别对于给定问题哪种类型最合适。

    Loops can

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

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

  • Advanced Programming for Edexcel A-Level Computer Science | 高级编程 Edexcel A-Level 计算机科学

    📚 Advanced Programming for Edexcel A-Level Computer Science | 高级编程 Edexcel A-Level 计算机科学

    This revision guide covers the core programming concepts required for Edexcel A-Level Computer Science. It focuses on practical coding techniques, common data structures, algorithm analysis, and object-oriented principles that appear frequently in both written papers and the programming project. Each section gives concise explanations with examples to help you revise effectively.

    本复习指南涵盖 Edexcel A-Level 计算机科学所需的核心编程概念。重点介绍实用编码技巧、常见数据结构、算法分析以及面向对象原则,这些内容在笔试和编程项目中都经常出现。每个小节提供简明解释和示例,帮助你高效复习。

    1. Programming Paradigms | 编程范式

    Edexcel specifications expect students to understand different programming paradigms, including procedural, object-oriented, event-driven, and declarative. Procedural programming structures code into procedures or subroutines that operate on data; this is the foundation of languages like Pascal and C. Object-oriented programming organises code around objects that contain both data and behaviour. Event-driven programming responds to user actions such as button clicks, making it common in graphical user interfaces. Declarative programming focuses on describing what should be computed rather than how, as seen in SQL and functional languages.

    Edexcel 大纲要求学生理解不同的编程范式,包括过程式、面向对象、事件驱动和声明式。过程式编程将代码组织为对数据进行操作的过程或子程序,这是 Pascal 和 C 等语言的基础。面向对象编程围绕同时包含数据和行为的对象组织代码。事件驱动编程响应用户操作(如按钮点击),因此在图形用户界面中很常见。声明式编程侧重于描述要计算什么而不是如何计算,例如 SQL 和函数式语言。

    A key exam skill is identifying which paradigm suits a given problem. For example, a mobile app with buttons and sliders is naturally event-driven, while a bank account system benefits from object-oriented modelling because each account combines state and operations.

    一个关键的考试技能是判断哪种范式适合给定的问题。例如,带有按钮和滑块的移动应用天然是事件驱动的,而银行账户系统则适合面向对象建模,因为每个账户都同时包含状态和操作。


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

    Choosing the correct data type affects both memory usage and the range of values a program can handle. Edexcel questions often involve integer, real/float, Boolean, character, and string types. Variables can change during execution, whereas constants hold values fixed at compile time or runtime. Strong typing helps prevent errors by enforcing type compatibility, while some languages use dynamic typing where variables can change type.

    选择正确的数据类型会影响内存使用和程序可处理的值范围。Edexcel 考题经常涉及整数、实数/浮点数、布尔值、字符和字符串类型。变量在执行过程中可以改变,而常量在编译时或运行时保持固定值。强类型通过强制类型兼容来帮助防止错误,而有些语言使用动态类型,变量可以改变类型。

    In pseudocode, you might declare a constant as PI = 3.14159 and a variable as score = 0. The distinction matters when you trace an algorithm: constants always keep the same value, but variables need to be updated line by line.

    在伪代码中,你可以声明常量为 PI = 3.14159,变量为 score = 0。在追踪算法时,这一区别很重要:常量始终保持相同的值,而变量需要逐行更新。

    Data Type Example Typical Use
    Integer 42 Counting, indexing
    Real/Float 3.14 Measurements, calculations
    Boolean true / false Conditions, flags
    Character ‘A’ Letters, symbols
    String “Hello” Text, names

    3. Control Structures | 控制结构

    Sequence, selection, and iteration are the three fundamental control structures. Selection uses if, else if, and switch/case statements to choose among paths. Iteration includes definite loops such as for loops, which run a known number of times, and indefinite loops such as while and do-while loops, which continue until a condition changes. Nested control structures can model complex decision-making but should be kept readable.

    顺序、选择和迭代是三种基本控制结构。选择使用 if、else if 和 switch/case 语句在路径之间进行选择。迭代包括定次循环(如 for 循环,运行已知次数)和不定次循环(如 while 和 do-while 循环,持续到条件改变)。嵌套控制结构可以模拟复杂决策,但应保持可读性。

    When tracing iteration, record the values of loop counters and conditions at each step. Definite iteration is often clearer than indefinite iteration because the number of repetitions is fixed, but some problems cannot be solved without checking a condition each time.

    追踪迭代时,要在每一步记录循环计数器和条件的值。定次迭代通常比不定次迭代更清晰,因为重复次数是固定的,但有些问题必须每次检查条件才能解决。


    4. Functions and Procedures | 函数与过程

    Functions return a value, while procedures perform an action but do not return a value in many languages. Parameters can be passed by value or by reference; passing by value gives a copy, so changes do not affect the original, while passing by reference allows the original variable to be modified. Recursion and reuse are major benefits of breaking programs into functions.

    函数返回值,而过程在许多语言中执行操作但不返回值。参数可以按值传递或按引用传递;按值传递提供副本,因此更改不会影响原始变量,而按引用传递允许修改原始变量。递归和代码重用是将程序分解为函数的主要好处。

    In Edexcel pseudocode, a function might be written as FUNCTION add(a, b) RETURN a + b ENDFUNCTION. Procedures are called without expecting a return value, such as PROCEDURE display(message) OUTPUT message ENDPROCEDURE.

    在 Edexcel 伪代码中,函数可以写成 FUNCTION add(a, b) RETURN a + b ENDFUNCTION。过程在调用时不期望返回值,例如 PROCEDURE display(message) OUTPUT message ENDPROCEDURE


    5. Recursion | 递归

    Recursion occurs when a function calls itself. A recursive algorithm must have a base case to stop, plus a recursive case that reduces the problem size. For example, the factorial function can be defined as n! = n × (n−1)! with base case 0! = 1. Recursive solutions are elegant for problems such as tree traversal and binary search, but they consume stack memory, and poorly designed recursion can cause stack overflow.

    当函数调用自身时就会发生递归。递归算法必须具有停止的基本情况,以及减少问题规模的递归情况。例如,阶乘函数可以定义为 n! = n × (n−1)!,基本情况 0! = 1。递归解决方案对于树遍历和二分查找等问题非常优雅,但它们消耗栈内存,设计不当的递归可能导致栈溢出。

    n! = n × (n−1)! where 0! = 1

    Every recursive call adds a new frame to the call stack. When writing recursive solutions, always identify the base case first and then ensure each recursive call moves closer to that base case.

    每次递归调用都会向调用栈添加一个新的栈帧。编写递归解决方案时,一定要先确定基本情况,然后确保每次递归调用都更接近该基本情况。


    6. Data Structures: Arrays and Lists | 数据结构:数组与列表

    Arrays store elements of the same type in contiguous memory locations, allowing O(1) access by index. However, static arrays have fixed size. Dynamic lists can grow and shrink, providing more flexibility. In Edexcel pseudocode, arrays are often 1D or 2D, and students may be asked to trace or write algorithms that manipulate array contents. Two-dimensional arrays model grids, matrices, and game boards.

    数组在连续内存位置中存储相同类型的元素,允许按索引进行 O(1) 访问。但是,静态数组具有固定大小。动态列表可以增长和收缩,提供更大的灵活性。在 Edexcel 伪代码中,数组通常是一维或二维的,学生可能被要求追踪或编写操作数组内容的算法。二维数组可以模拟网格、矩阵和游戏棋盘。

    For example, a 2D array board[8][8] can represent a chessboard. Accessing an element uses two indices, such as board[2][5], and traversal normally requires nested loops: one for rows and one for columns.

    例如,二维数组 board[8][8] 可以表示棋盘。访问元素使用两个索引,例如 board[2][5],遍历通常需要嵌套循环:一个用于行,一个用于列。


    7. Stacks and Queues | 栈与队列

    A stack is a last-in, first-out (LIFO) structure with push and pop operations. Common applications include undo features, call stacks for recursion, and syntax parsing. A queue is a first-in, first-out (FIFO) structure with enqueue and dequeue operations, used in scheduling, buffering, and breadth-first search. Understanding their behaviour is essential for tracing algorithm execution.

    栈是一种后进先出(LIFO)结构,具有 push 和 pop 操作。常见应用包括撤销功能、递归调用栈和语法解析。队列是一种先进先出(FIFO)结构,具有 enqueue 和 dequeue 操作,用于调度、缓冲和广度优先搜索。理解它们的行为对于追踪算法执行至关重要。

    When implementing a stack, you need to check for overflow before pushing and underflow before popping. Similarly, a circular queue can be used to make efficient use of array space by wrapping the rear and front pointers.

    实现栈时,需要在推入前检查溢出,在弹出前检查下溢。同样,循环队列可以通过环绕 rear 和 front 指针来高效利用数组空间。


    8. Searching Algorithms | 查找算法

    Linear search checks each element in sequence until the target is found or the list ends. It works on unsorted data and has O(n) time complexity. Binary search requires a sorted list and repeatedly compares the target to the middle element, halving the search space each time; its time complexity is O(log n). For small datasets linear search is simple, but binary search is far more efficient for large sorted collections.

    线性搜索按顺序检查每个元素,直到找到目标或列表结束。它适用于未排序数据,时间复杂度为 O(n)。二分查找要求列表已排序,并反复将目标与中间元素比较,每次将搜索空间减半;其时间复杂度为 O(log n)。对于小型数据集,线性搜索简单,但二分查找对大型排序集合效率高得多。

    Linear Search: O(n) Binary Search: O(log n)

    Algorithm Requirement Time Complexity
    Linear Search 更多咨询请联系16621398022(同微信)

  • Operators, Expressions and Precedence in Edexcel A-Level Programming | Edexcel A-Level编程运算符、表达式与优先级

    📚 Operators, Expressions and Precedence in Edexcel A-Level Programming | Edexcel A-Level编程运算符、表达式与优先级

    In Edexcel A-Level Computer Science, programming questions reward precise use of operators, expressions and precedence. Whether you trace pseudocode or write Python, a single wrong operator can change the entire logic of an algorithm. This revision guide covers the operators and expression rules you need for the qualification.

    在Edexcel A-Level计算机科学中,编程题目会考查你对运算符、表达式和优先级的精确使用。无论你是在追踪伪代码还是编写Python,一个错误的运算符都可能改变整个算法的逻辑。本复习指南涵盖本资格认证所需的运算符和表达式规则。


    1. Why Operators Matter | 为什么运算符重要

    Operators are symbols that tell the computer to perform a specific operation on one or more operands. An expression is a combination of values, variables, operators and function calls that can be evaluated to produce a single result. Edexcel exams test both your ability to read expressions in pseudocode and your ability to write correct expressions in a high-level language such as Python.

    运算符是告诉计算机对一个或多个操作数执行特定操作的符号。表达式是由值、变量、运算符和函数调用组成的组合,可以被求值得到单一结果。Edexcel考试既考查你阅读伪代码中表达式的能力,也考查你使用Python等高级语言编写正确表达式的能力。


    2. Arithmetic Operators | 算术运算符

    The core arithmetic operators in Edexcel pseudocode are +, -, *, /, DIV, MOD and ^. You must recognise each one and know how it behaves with integer and real operands.

    Edexcel伪代码中的核心算术运算符是+、-、*、/、DIV、MOD和^。你必须认识每一个运算符,并知道它们在整数和实数操作数上的行为。

    Operator Meaning Pseudocode example Python equivalent
    + Addition | 加 3 + 2 = 5 3 + 2 = 5
    Subtraction | 减 7 – 4 = 3 7 – 4 = 3
    * Multiplication | 乘 6 * 4 = 24 6 * 4 = 24
    / Real division | 实数除法 7 / 2 = 3.5 7 / 2 = 3.5
    DIV Integer division | 整除 17 DIV 5 = 3 17 // 5 = 3
    MOD Remainder | 取余 17 MOD 5 = 2 17 % 5 = 2
    ^ Exponent | 幂 2^3 = 8 2 ** 3 = 8

    Notice that Edexcel pseudocode uses ^ for powers, while Python uses **. In both contexts, multiplication and division are evaluated before addition and subtraction unless parentheses change the order.

    请注意,Edexcel伪代码使用^表示幂,而Python使用**。在两种环境中,乘法和除法都先于加法和减法求值,除非括号改变顺序。


    3. DIV and MOD | 整除与取余

    DIV gives the whole-number quotient when one integer is divided by another, and MOD gives the remainder. These operations are extremely common in algorithm questions involving digits, cycles, calendars and validation rules.

    DIV给出一个整数除以另一个整数时的整数商,MOD给出余数。这些运算在涉及数字、周期、日历和验证规则的算法题中非常常见。

    17 DIV 5 = 3    17 MOD 5 = 2

    In Python the same results are produced by // and %: 17 // 5 gives 3 and 17 % 5 gives 2. For positive integers this is straightforward, and most exam examples use positive values.

    在Python中,同样的结果由//和%产生:17 // 5得到3,17 % 5得到2。对于正整数,这很简单,大多数考试示例都使用正值。


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

    Relational operators compare two values and return a Boolean result: TRUE or FALSE. They are used in IF statements, WHILE loops and validation checks.

    关系运算符比较两个值并返回布尔结果:TRUE或FALSE。它们用于IF语句、WHILE循环和验证检查中。

    Operator Meaning Example
    == Equal to | 等于 5 == 5 evaluates to TRUE
    != Not equal to | 不等于 5 != 4 evaluates to TRUE
    < Less than | 小于 3 < 8 evaluates to TRUE
    > Greater than | 大于 10 > 4 evaluates to TRUE
    <= Less than or equal to | 小于等于 6 <= 6 evaluates to TRUE
    >= Greater than or equal to | 大于等于 9 >= 8 evaluates to TRUE

    A key exam hazard is confusing = with ==. In Edexcel pseudocode and Python, a single = is assignment, while == is the comparison for equality. Using = where == is required will usually cause an error or unexpected behaviour.

    一个关键的考试易错点是将=和==混淆。在Edexcel伪代码和Python中,单个=用于赋值,而==用于比较相等。在需要==的地方使用=通常会导致错误或意外行为。


    5. Boolean and Logical Operators | 布尔与逻辑运算符

    Boolean operators AND, OR and NOT combine or invert Boolean conditions. They are essential for constructing compound conditions in IF, WHILE and REPEAT structures.

    布尔运算符AND、OR和NOT用于组合或反转布尔条件。它们在构建IF、WHILE和REPEAT结构中的复合条件时必不可少。

    A B A AND B A OR B NOT A
    TRUE TRUE TRUE TRUE FALSE
    TRUE FALSE FALSE TRUE FALSE
    FALSE TRUE FALSE TRUE TRUEPublished by TutorHao | A-Level 编程 Revision Series | aleveler.com

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