A-Level Edexcel Programming: Core Constructs, Data Structures and Algorithms | A-Level Edexcel编程:核心构造、数据结构与算法

📚 A-Level Edexcel Programming: Core Constructs, Data Structures and Algorithms | A-Level Edexcel编程:核心构造、数据结构与算法

This revision guide covers the programming topics examined in Edexcel A-Level Computer Science, including data types, control structures, subprograms, recursion, data structures, searching, sorting, algorithm efficiency, object-oriented programming, error handling and the use of IDEs.

本复习指南涵盖Edexcel A-Level计算机科学中考查的编程主题,包括数据类型、控制结构、子程序、递归、数据结构、查找、排序、算法效率、面向对象编程、错误处理以及集成开发环境的使用。


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

Data types determine how a value is stored and what operations are allowed. Edexcel questions expect candidates to identify integer, real/float, Boolean, character and string types.

数据类型决定值的存储方式以及允许的操作。Edexcel题目要求考生识别整数、实数/浮点、布尔、字符和字符串类型。

An integer stores a whole number such as 5 or -12. A real or float stores a number with a fractional part, such as 3.14 or -0.001.

整数存储整数,例如5或-12。实数或浮点数存储带有小数部分的数,例如3.14或-0.001。

A Boolean holds only True or False, while a character holds a single symbol such as ‘A’ or ‘9’. A string is a sequence of characters such as “hello”.

布尔值只能保存 True 或 False,而字符保存单个符号,如 ‘A’ 或 ‘9’。字符串是字符序列,如 “hello”。

A variable can change during program execution, but a constant is assigned once and cannot be modified. Constants make programs easier to understand and maintain.

变量在程序执行期间可以改变,但常量只能在赋值后保持不变。常量使程序更易于理解和维护。

Implicit or explicit type casting may be needed when different data types are combined in calculations or assignments.

当不同数据类型在计算或赋值中组合时,可能需要进行隐式或显式类型转换。


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

Arithmetic operators in Edexcel pseudocode include +, -, *, /, MOD and DIV. The MOD operator gives the remainder, while DIV gives the integer quotient.

Edexcel伪代码中的算术运算符包括 +、-、*、/、MOD 和 DIV。MOD 给出余数,DIV 给出整数商。

Relational operators compare values: =, ≠, <, >, ≤ and ≥. The result of a comparison is always a Boolean value.

关系运算符用于比较值:=、≠、<、>、≤ 和 ≥。比较的结果总是布尔值。

Boolean operators AND, OR and NOT combine logical expressions. AND is true only when both operands are true; OR is true when at least one operand is true; NOT reverses the Boolean value.

布尔运算符 AND、OR 和 NOT 用于组合逻辑表达式。AND 仅在两个操作数都为真时为真;OR 在至少一个操作数为真时为真;NOT 反转布尔值。

Operator precedence matters: NOT is evaluated before AND, and AND before OR. Brackets can be used to force a different order.

运算符优先级很重要:NOT 先于 AND 计算,AND 先于 OR 计算。括号可用来强制改变计算顺序。

String expressions often use concatenation, joining two strings into one, for example “rain” + “bow” produces “rainbow”.

字符串表达式通常使用拼接运算,将两个字符串连接为一个,例如 “rain” + “bow” 得到 “rainbow”。


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

Sequence means statements are executed one after another in the order written. It is the default flow of control.

顺序结构表示语句按书写顺序逐条执行,这是默认的控制流程。

Selection allows the program to choose between branches using IF … THEN … ELSE … ENDIF or a CASE statement for multiple options.

选择结构允许程序使用 IF … THEN … ELSE … ENDIF 或 CASE 语句在多个选项之间进行分支。

An IF condition can be nested inside another IF to model complex decisions. Indentation makes nested logic easier to read.

IF 条件可以嵌套在另一个 IF 中,以建立复杂决策。缩进使嵌套逻辑更易阅读。

Iteration repeats a block of code. A FOR loop is definite because the number of repetitions is known in advance, while a WHILE loop repeats as long as a condition is true.

迭代结构重复执行一段代码。FOR 循环是确定循环,因为重复次数事先已知;而 WHILE 循环在条件为真时反复执行。

A REPEAT … UNTIL loop checks the condition after the loop body, so it always runs at least once.

REPEAT … UNTIL 循环在循环体之后检查条件,因此至少会执行一次。


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

A function returns a value and can be used inside an expression, whereas a procedure performs an action but does not return a value.

函数返回一个值,可用于表达式中;而过程执行一个动作但不返回值。

Parameters allow data to be passed into subprograms. Passing by value gives the subprogram a copy, so changes inside do not affect the original variable. Passing by reference uses the original memory location, so changes are visible outside.

参数允许将数据传入子程序。按值传递时,子程序获得副本,内部修改不会影响原变量;按引用传递则使用原内存位置,修改会在外部可见。

Local variables are declared inside a subprogram and are accessible only there, while global variables are available throughout the program. Overuse of global variables can make debugging harder.

局部变量在子程序内部声明,仅在该子程序内可访问;全局变量在整个程序中可用。过度使用全局变量会使调试更加困难。

Modular programming breaks a problem into small, reusable subprograms. This improves readability, testing and team development.

模块化编程将问题分解为小型、可复用的子程序。这提高了可读性、可测试性和团队开发效率。


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

A recursive subprogram calls itself to solve a smaller instance of the same problem. Every recursion must have a base case that stops the chain.

递归子程序调用自身来解决同一问题的较小实例。每个递归必须有一个基准情形来终止调用链。

Without a correct base case, recursion continues until the call stack overflows, causing a runtime error. The base case is usually the simplest possible input.

如果没有正确的基准情形,递归会一直持续到调用栈溢出,导致运行时错误。基准情形通常是最简单的输入。

A classic example is factorial, defined recursively as shown below.

一个经典示例是阶乘,其递归定义如下所示。

n! = n × (n – 1)! for n > 1, 1! = 1

Each recursive call is pushed onto the call stack, and the stack unwinds when the base case returns. Recursion can be elegant, but iterative solutions may use less memory.

每次递归调用都被压入调用栈,当基准情形返回时栈会展开。递归可以很简洁,但迭代解法可能使用更少内存。


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

An array is a static, indexed collection of elements of the same data type. A one-dimensional array stores a single list, while a two-dimensional array can represent a table or matrix.

数组是静态的、按索引访问且元素类型相同的集合。一维数组存储单个列表,二维数组可以表示表格或矩阵。

Indexing in Edexcel pseudocode may start at 0 or 1 depending on the question, so always read the question carefully before writing algorithms.

Edexcel伪代码中的索引可能从0或1开始,具体取决于题目,因此编写算法前必须仔细读题。

A list is a dynamic data structure that can grow or shrink after creation. Unlike static arrays, lists allow insertion and deletion without re-declaring the whole structure.

列表是一种动态数据结构,可以在创建后增长或收缩。与静态数组不同,列表允许插入和删除元素而无需重新声明整个结构。

A record stores related fields of different data types under one name, similar to a row in a database. For example, a Student record could hold name, age and grade.

记录将不同数据类型的相关字段存储在一个名称下,类似于数据库中的一行。例如,Student 记录可以包含姓名、年龄和成绩。


7. Searching Algorithms | 查找算法

Linear search examines each element in turn until the target is found or the end is reached. It works on unsorted data and has worst-case time complexity O(n).

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

Binary search repeatedly halves a sorted list by comparing the target with the middle element, giving average and worst-case complexity O(log n).

二分查找通过将目标与中间元素比较,不断将有序列表对半分,平均和最坏时间复杂度为 O(log n)。

The list must be sorted before a binary search can be used; otherwise the result is unreliable. Binary search is much faster than linear search on large data sets.

使用二分查找前,列表必须已排序;否则结果不可靠。在大型数据集上,二分查找比线性查找快得多。

The table below summarises the two searching methods.

下表总结了两种查找方法。

Algorithm (算法) Requirement (前提) Worst-case (最坏情况)
Linear search (线性查找) None (无需排序) O(n)
Binary search (二分查找) Sorted list (有序列表) O(log n)

8. Sorting Algorithms | 排序算法

Bubble sort compares adjacent pairs and swaps them if they are in the wrong order, repeating passes until no swaps are needed. Its worst-case time complexity is O(n²).

冒泡排序比较相邻元素并在顺序错误时交换,重复多趟直到不再需要交换。其最坏时间复杂度为 O(n²)。

Insertion sort builds a sorted prefix by inserting each new element into its correct position within that prefix. It is efficient for small or nearly sorted data sets.

插入排序通过将每个新元素插入有序前缀中的正确位置来构建有序序列。它对于小规模或近似有序的数据集效率较高。

Merge sort splits the list recursively into halves, sorts each half, and merges the sorted halves. It has O(n log n) time complexity but requires additional memory for merging.

归并排序递归地将列表分成两半,分别排序,再合并有序的两半。其时间复杂度为 O(n log n),但合并时需要额外内存。

Edexcel questions often ask candidates to trace one pass of a sort or compare the efficiency of two sorting algorithms.

Edexcel题目经常要求考生跟踪排序的一趟过程,或比较两种排序算法的效率。


9. Algorithm Efficiency and Big O Notation | 算法效率与Big O记号

Big O notation describes the upper bound of how time or space grows as the input size n increases. It focuses on the dominant term and ignores constant factors.

Big O记号描述随着输入规模 n 增大,时间或空间增长的上界。它关注主导项并忽略常数因子。

Common complexities and their meanings are shown in the table below.

常见复杂度及其含义如下表所示。

Complexity (复杂度) 更多咨询请联系16621398022(同微信)

Comments

屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from aleveler.com

Subscribe now to keep reading and get access to the full archive.

Continue reading