📚 Edexcel A-Level Programming: Core Algorithms and Data Structures | Edexcel A-Level 编程:核心算法与数据结构
This revision guide covers the essential programming techniques assessed in the Edexcel A-Level Computer Science specification, including variables and data types, control flow, subroutines, recursion, arrays, stacks, queues, searching, sorting, object-oriented concepts and complexity analysis.
本复习指南涵盖 Edexcel A-Level 计算机科学考试大纲中的核心编程技术,包括变量与数据类型、控制流、子程序、递归、数组、栈、队列、搜索、排序、面向对象概念和复杂度分析。
1. Variables, Constants and Data Types | 变量、常量与数据类型
In Edexcel A-Level programming, understanding how data is stored and manipulated is fundamental. Variables are named memory locations whose values can change during execution, while constants hold values that cannot be modified after initialisation.
在 Edexcel A-Level 编程中,理解数据的存储和操作是基础。变量是可改变值的命名内存位置,而常量在初始化后不能被修改。
Common primitive data types include integer, real (or float), Boolean, character and string. When declaring variables, you must consider scope and lifetime. Local variables are accessible only within the subroutine where they are defined, whereas global variables can be accessed throughout the program. Constants improve code readability and reduce errors caused by magic numbers.
常见的原始数据类型包括整型、实数(或浮点型)、布尔型、字符和字符串。声明变量时,必须考虑作用域和生命周期。局部变量只能在定义它们的子程序内访问,而全局变量可以在整个程序中访问。常量提高代码可读性,并减少由魔法数字引起的错误。
2. Operators and Expressions | 运算符与表达式
Operators are symbols that perform operations on operands. Arithmetic operators include +, −, ×, ÷ and mod (modulo). Comparison operators such as =, ≠, , ≤ and ≥ return Boolean values. Logical operators AND, OR and NOT are used to combine Boolean expressions.
运算符是对操作数执行操作的符号。算术运算符包括 +、−、×、÷ 和 mod(取模)。比较运算符如 =、≠、、≤ 和 ≥ 返回布尔值。逻辑运算符 AND、OR 和 NOT 用于组合布尔表达式。
Operator precedence determines the order of evaluation. In most languages, arithmetic operations are evaluated before comparisons, and comparisons before logical operations. Parentheses can be used to override default precedence.
运算符优先级决定求值顺序。在大多数语言中,算术运算先于比较运算,比较运算先于逻辑运算。圆括号可用于覆盖默认优先级。
3. Selection and Iteration | 选择与迭代
Selection statements allow a program to make decisions. The IF…THEN…ELSE structure executes one block of code when a condition is true and another when it is false. Nested IF statements can handle multiple conditions, but a CASE or SWITCH statement is often clearer for multiple discrete values.
选择语句允许程序做出判断。IF…THEN…ELSE 结构在条件为真时执行一个代码块,为假时执行另一个。嵌套 IF 语句可以处理多个条件,但对于多个离散值,CASE 或 SWITCH 语句通常更清晰。
Iteration is achieved through definite loops such as FOR, which repeat a known number of times, and indefinite loops such as WHILE or REPEAT…UNTIL. WHILE checks the condition before each iteration; REPEAT…UNTIL checks after, so the loop body always executes at least once.
迭代通过确定循环(如 FOR,已知重复次数)和不确定循环(如 WHILE 或 REPEAT…UNTIL)实现。WHILE 在每次迭代前检查条件;REPEAT…UNTIL 在迭代后检查,因此循环体至少执行一次。
4. Functions, Procedures and Parameter Passing | 函数、过程与参数传递
Subroutines are named blocks of code that can be reused. A function returns a value, whereas a procedure performs a task without returning a value. Parameters allow data to be passed into subroutines, making them more general-purpose.
子程序是可重用的命名代码块。函数返回一个值,而过程执行任务但不返回值。参数允许将数据传入子程序,使其更通用。
There are two main parameter passing methods: by value and by reference. When passed by value, a copy of the argument is made; changes inside the subroutine do not affect the original variable. When passed by reference, the memory address is passed, so modifications 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, and a recursive case that reduces the problem towards the base case.
递归是一种子程序调用自身来解决同一问题较小实例的技术。每个递归例程必须有一个基本情况来停止递归,以及一个将问题缩小到基本情况的递归情况。
A classic example is the factorial function: n! = n × (n−1)! with the base case 0! = 1. Recursive solutions can be elegant but may use more memory because each call is placed on the call stack.
一个经典示例是阶乘函数:n! = n × (n−1)!,基本情况为 0! = 1。递归解法可能很优雅,但由于每次调用都放在调用栈上,可能使用更多内存。
n! = n × (n−1)! for n > 0; 0! = 1
6. Arrays and Lists | 数组与列表
Arrays are data structures that store multiple elements of the same data type in contiguous memory locations. Each element is accessed by an index, typically starting at 0 or 1 depending on the language. Arrays can be one-dimensional (a linear list) or multi-dimensional (such as a 2D grid).
数组是将多个相同数据类型元素存储在连续内存位置的数据结构。每个元素通过索引访问,根据语言不同,索引通常从 0 或 1 开始。数组可以是一维的(线性列表)或多维的(如二维网格)。
Lists are similar to arrays but are dynamic, meaning they can grow and shrink during execution. Operations such as append, insert, remove and search are common. Lists are often implemented using arrays or linked lists internally.
列表类似于数组,但是动态的,可以在执行期间增长和收缩。常见操作包括追加、插入、删除和搜索。列表通常在内部使用数组或链表实现。
7. Stacks and Queues | 栈与队列
A stack is a last-in-first-out (LIFO) data structure. The two core operations are push (add an item to the top) and pop (remove the top item). Stacks are used in recursion, undo functionality, and expression evaluation.
栈是一种后进先出(LIFO)的数据结构。两个核心操作是 push(将项添加到栈顶)和 pop(移除栈顶项)。栈用于递归、撤销功能和表达式求值。
A queue is a first-in-first-out (FIFO) data structure. Items are added at the rear (enqueue) and removed from the front (dequeue). Queues model real-world waiting lines and are used in breadth-first search and CPU scheduling.
队列是一种先进先出(FIFO)的数据结构。项在队尾添加(入队),在队首移除(出队)。队列模拟现实世界的等待队列,用于广度优先搜索和 CPU 调度。
8. Searching Algorithms | 搜索算法
Linear search checks each element in a list sequentially until the target is found or the end is reached. It works on unsorted lists and has a worst-case time complexity of O(n).
线性搜索按顺序检查列表中的每个元素,直到找到目标或到达末尾。它适用于未排序的列表,最坏情况时间复杂度为 O(n)。
Binary search is much faster but requires the list to be sorted. It repeatedly divides the search interval in half. If the target is less than the middle element, search the left half; otherwise search the right half. Its worst-case complexity is O(log n).
二分搜索快得多,但要求列表有序。它反复将搜索区间分成两半。如果目标小于中间元素,则搜索左半部分;否则搜索右半部分。其最坏情况复杂度为 O(log n)。
9. Sorting Algorithms | 排序算法
Bubble sort repeatedly passes through the list, comparing adjacent elements and swapping them if they are in the wrong order. It has O(n²) time complexity. Insertion sort builds a sorted portion one element at a time, also O(n²) but efficient for nearly sorted lists.
冒泡排序反复遍历列表,比较相邻元素,如果顺序错误则交换。其时间复杂度为 O(n²)。插入排序一次构建一个有序部分,时间复杂度也为 O(n²),但对于接近有序的列表效率较高。
Merge sort uses a divide-and-conquer strategy: split the list into halves, recursively sort each half, then merge the sorted halves. Its time complexity is O(n log n) in all cases, but it uses extra memory.
归并排序使用分治策略:将列表分成两半,递归地对每一半排序,然后合并有序的两半。它在所有情况下时间复杂度为 O(n log n),但需要额外内存。
10. Object-Oriented Programming Basics | 面向对象编程基础
Object-oriented programming (OOP) models real-world entities as objects that combine data (attributes) and behaviour (methods). A class is a blueprint from which objects are instantiated. Encapsulation hides internal state and only exposes methods to interact with the object.
面向对象编程(OOP)将现实世界实体建模为对象,这些对象结合了数据(属性)和行为(方法)。类是从中实例化对象的蓝图。封装隐藏内部状态,只暴露与对象交互的方法。
Inheritance allows a subclass to inherit attributes and methods from a superclass, promoting code reuse. Polymorphism lets objects of different classes respond to the same method call in their own way. These concepts are assessed in the Edexcel specification.
继承允许子类从超类继承属性和方法,促进代码重用。多态使不同类的对象以各自的方式响应同一方法调用。这些概念在 Edexcel 大纲中都有考查。
11. Big O Notation and Algorithm Efficiency | 大 O 表示法与算法效率
Big O notation is used to describe the upper bound of an algorithm’s time or space complexity as the input size n grows. Common classes include O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n), O(n²) quadratic and O(2ⁿ) exponential.
大 O 表示法用于描述随着输入规模 n 增大,算法时间或空间复杂度的上界。常见类别包括 O(1) 常数、O(log n) 对数、O(n) 线性、O(n log n)、O(n²) 平方和 O(2ⁿ) 指数。
When evaluating algorithms for the exam, you should be able to compare basic searching and sorting algorithms using Big O notation. For example, binary search O(log n) is more efficient than linear search O(n) for large sorted data.
在考试中评估算法时,你应该能够使用大 O 表示法比较基本的搜索和排序算法。例如,对于大型有序数据,二分搜索 O(log n) 比线性搜索 O(n) 更高效。
12. Debugging and Error Handling | 调试与错误处理
Programming errors fall into three main categories: syntax errors (incorrect grammar of the language), runtime errors (errors that occur during execution, such as division by zero or stack overflow), and logic errors (the program runs but produces incorrect results).
编程错误分为三大类:语法错误(语言语法错误)、运行时错误(执行期间发生的错误,如除以零或栈溢出)和逻辑错误(程序运行但产生不正确的结果)。
Effective debugging strategies include using breakpoints, tracing variable values, inserting print statements, and using test cases. Defensive programming techniques such as input validation and exception handling help make programs robust.
有效的调试策略包括使用断点、跟踪变量值、插入打印语句和使用测试用例。防御性编程技术,如输入验证和异常处理,有助于使程序更健壮。
Published by TutorHao | Programming Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)
屏轩国际教育cambridge primary/secondary checkpoint, cat4, ukiset,ukcat,igcse,alevel,PAT,STEP,MAT, ibdp,ap,ssat,sat,sat2课程辅导,国外大学本科硕士研究生博士课程论文辅导Cancel reply