📚 Programming Fundamentals for Edexcel A-Level Computer Science | Edexcel A-Level 计算机科学编程基础
Programming is the core skill tested across Edexcel A-Level Computer Science, especially in the on-screen examination and the programming project. This guide brings together the fundamental techniques you need, including data representation, control flow, recursion, data structures, searching and sorting, object-oriented design, and algorithm analysis.
编程是 Edexcel A-Level 计算机科学中贯穿始终的核心技能,尤其在机考与编程项目中尤为重要。本指南汇集了你需要掌握的基础技术,包括数据表示、控制流、递归、数据结构、搜索与排序、面向对象设计以及算法分析。
The material below follows the order in which the topics usually appear in lessons: start with computational thinking, move through the way data is stored and manipulated, then build up programs with control flow, subprograms and recursion, before studying the data structures and algorithms that examiners expect you to select and justify. Each section ends with the vocabulary and the typical exam phrasing you should be able to recognise instantly.
下文按照课堂中常见的教学顺序展开:先讲计算思维,再讲数据的存储与运算方式,然后用控制流、子程序和递归搭建程序,最后学习数据结构与算法 —— 这些都是考官希望你能够选择并给出理由的内容。每一节最后都会点出你需要一眼认出的专业术语和典型考题措辞。
1. Computational Thinking and Problem Decomposition | 计算思维与问题分解
Computational thinking means approaching a problem in a way that a computer can execute. It involves abstraction, which removes unnecessary detail; decomposition, which breaks a large problem into manageable parts; pattern recognition, which identifies similarities; and algorithm design, which specifies step-by-step instructions.
计算思维意味着以计算机能够执行的方式来处理问题。它包括抽象(去除不必要的细节)、分解(把大问题拆成可管理的小块)、模式识别(找出相似之处)以及算法设计(给出逐步执行的指令)。
- Abstraction: keep only the features that matter for the solution, such as storing a student's name and mark but ignoring their address.
抽象:只保留对解题有意义的特征,例如只存学生的姓名和成绩,而不存地址。 - Decomposition: split a booking system into login, search, reserve and payment subprograms, each of which can be written and tested separately.
分解:把订票系统拆成登录、查询、预订、支付等子程序,每个都可以单独编写和测试。 - Pattern recognition: notice that searching a sorted list, looking up a username and finding a word in a dictionary all use the same halving strategy.
模式识别:发现有序表查找、用户名检索、词典查词其实都用了同样的"折半"策略。 - Algorithm design: express the solution as a finite, ordered and unambiguous sequence of instructions that always terminates.
算法设计:把解法表达为有限、有序、无歧义且必然终止的指令序列。
A well-formed algorithm has clearly defined inputs and outputs, uses only operations the computer can perform, and reaches the same output for the same input every time. When a question says 'state the inputs and outputs of your solution', it is testing whether you have abstracted the problem correctly rather than started writing code immediately.
一个规范的算法要有明确定义的输入与输出,只使用计算机能够执行的运算,并且对相同输入每次都得到相同输出。当题目要求"写出解法的输入和输出"时,它其实是在检验你是否正确地做了抽象,而不是急着开始写代码。
Inputs → Process(es) → Outputs (finite, unambiguous, correct, efficient)
2. Data Representation Inside a Program | 程序内部的数据表示
Every value a program manipulates is ultimately stored as binary, so you must move fluently between denary, binary and hexadecimal, handle signed integers with two's complement, and interpret floating-point values as a mantissa and an exponent. Character data uses character sets such as ASCII and Unicode, while Boolean values and bitwise operators underpin many low-level tasks.
程序处理的每一个值最终都以二进制存储,因此你必须能在十进制、二进制和十六进制之间流畅转换,用补码处理有符号整数,并把浮点数理解为一个尾数加一个指数。字符数据使用 ASCII、Unicode 之类的字符集,而布尔值与按位运算符则支撑着许多底层操作。
- Denary to binary: divide repeatedly by 2 and read the remainders upwards; hexadecimal groups four bits at a time.
十进制转二进制:不断除以 2 并自下而上读取余数;十六进制则每四位二进制为一组。 - Two's complement: invert the bits of the positive value and add 1 to obtain the negative equivalent.
补码:把正数的各位取反再加 1,即得到对应的负值。 - Overflow and precision: storing 300 in an 8-bit unsigned integer or 0.1 in a binary fraction both produce errors that a robust program must anticipate.
溢出与精度:把 300 存入 8 位无符号整数,或把 0.1 存成二进制小数,都会产生误差,健壮的程序必须预先考虑。 - Text and media: ASCII covers 7-bit codes, Unicode supports thousands of scripts, and Run-Length Encoding or Huffman coding compresses data losslessly.
文本与媒体:ASCII 使用 7 位编码,Unicode 支持数千种文字,行程编码或哈夫曼编码可实现无损压缩。
n-bit two's complement range: −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1
floating-point value = mantissa × 2^exponent
3. Control Flow: Sequence, Selection and Iteration | 控制流:顺序、选择与迭代
All programs are built from just three constructs: sequence, selection and iteration. Selection uses if, elseif and else statements or a switch/case block; iteration uses for loops when the number of repetitions is known in advance and while or do-while loops when it is not. Mastering nesting and loop control is what turns a novice solution into a full-mark solution.
所有程序都只由三种结构组成:顺序、选择和迭代。选择使用 if、elseif、else 语句或 switch/case 分支;迭代在循环次数已知时使用 for 循环,次数未知时使用 while 或 do-while 循环。掌握嵌套与循环控制,是新手解法与满分解法之间的差别。
- Sequence: statements execute in the order written, so a misplaced assignment changes the whole result.
顺序:语句按书写顺序执行,因此一个赋值语句放错位置就会改变整个结果。 - Selection: conditions must be mutually exclusive and exhaustive, otherwise unhandled cases produce wrong output.
选择:各分支条件必须互斥且穷尽,否则未被处理的情况会产生错误输出。 - Iteration: a for loop is a counted loop, a while loop is a pre-condition loop, and a do-while loop guarantees at least one execution.
迭代:for 是计数循环,while 是先判断后执行的循环,do-while 则保证循环体至少执行一次。 - Loop control: break exits immediately, continue skips to the next iteration, and infinite loops occur when the loop variable is never updated.
循环控制:break 立即退出,continue 跳到下一次迭代;当循环变量从不更新时就会出现死循环。 - Boolean logic: AND, OR and NOT combine conditions, and short-circuit evaluation stops testing as soon as the result is known.
布尔逻辑:AND、OR、NOT 用来组合条件,短路求值在结果确定后立即停止判断。
while (index < length) AND (list[index] ≠ target) do index ← index + 1 endwhile
4. Subprograms, Parameters and Scope | 子程序、参数与作用域
Subprograms make a program modular: a procedure performs an action without returning a value, while a function returns a single value. Data passes into them through parameters, which may be passed by value (a copy is used) or by reference (the original variable is used and can be modified). Understanding scope prevents the most common debugging headaches.
子程序让程序模块化:过程执行某个动作但不返回值,函数则返回一个值。数据通过参数传入,参数可以按值传递(使用副本)或按引用传递(使用原变量并且可以被修改)。理解作用域能避免最常见的调试困扰。
- Parameters by value: changes inside the subprogram do not affect the caller's variable.
按值传递:子程序内部的修改不会影响调用方的变量。 - Parameters by reference: the subprogram receives the address of the variable, so updates are visible outside.
按引用传递:子程序收到变量的地址,因此更新在外部可见。 - Local variables exist only while the subprogram runs; global variables exist for the whole program and create hidden dependencies.
局部变量只在子程序运行时存在;全局变量在整个程序中存在,会造成隐藏的依赖关系。 - Pure functions produce the same output for the same arguments and cause no side effects, which makes them easy to test.
纯函数对相同实参总是产生相同输出且没有副作用,因此非常容易测试。 - Overloading lets two subprograms share a name if their parameter lists differ, improving readability.
重载允许两个参数列表不同的子程序使用同一名称,从而提高可读性。
5. Recursion and Divide-and-Conquer | 递归与分治
Recursion is a technique in which a subprogram calls itself with a smaller version of the same problem. Every recursive solution needs a base case that stops the recursion and a general case that moves the problem closer to that base case. Without a base case the call stack grows until a stack overflow occurs.
递归是一种子程序用同一问题的更小版本来调用自身的技术。每个递归解法都需要一个停止递归的基本情况(base case)和一个让问题更接近该基本情况的通用情况。没有基本情况时,调用栈会不断增长,最终导致栈溢出。
Recursion is elegant and often shorter than the equivalent iterative solution, but each call consumes memory on the call stack and the repeated work can be inefficient. Iteration is usually faster and uses constant memory, so examiners frequently ask you to compare the two.
递归优雅且往往比等价的迭代解法更简短,但每次调用都会占用调用栈内存,重复计算也可能导致效率低下。迭代通常更快且只使用常量内存,因此考官经常要求你比较这两种方式。
factorial(n) = n × factorial(n − 1), with factorial(0) = 1
- Classic examples: factorial, Fibonacci numbers, Towers of Hanoi (2ⁿ − 1 moves) and tree traversal.
经典例子:阶乘、斐波那契数列、汉诺塔(2ⁿ − 1 步)以及树的遍历。 - Divide-and-conquer: binary search halves a sorted list, merge sort splits then merges, and quicksort partitions around a pivot.
分治:二分查找把有序表折半,归并排序先拆分再合并,快速排序围绕枢轴进行分区。 - Tail recursion: a recursive call that is the last operation can be optimised into a loop by some compilers.
尾递归:若递归调用是最后一步操作,某些编译器可以把它优化成循环。 - Risks: deep recursion on large inputs causes stack overflow, and careless memoisation losses make exponential algorithms unusable.
风险:在大输入上过深的递归会导致栈溢出,而缺少记忆化会让指数级算法无法实用。
6. Data Structures and Their Operations | 数据结构及其操作
Choosing the right data structure is often worth more marks than writing clever code. Static arrays have fixed size and constant-time access by index; dynamic lists can grow; stacks and queues restrict access in ways that match real problems; hash tables, trees and graphs support fast searching and modelling of relationships.
选择正确的数据结构往往比写出"聪明"的代码更能得分。静态数组大小固定,按索引访问是常数时间;动态列表可以增长;栈和队列用受限的访问方式匹配真实问题;哈希表、树和图则支持快速查找和对关系的建模。
| Structure | Key operations | Typical cost |
| Array / list | read, write, append, insert | read O(1), insert O(n) |
| Stack (LIFO) | push, pop, peek | O(1) |
| Queue (FIFO) | enqueue, dequeue | O(1) |
| Linked list | insert, delete, traverse | insert O(1), search O(n) |
| Hash table | insert, lookup, delete | O(1) average |
| Binary search tree | insert, search, traverse | O(log n) if balanced |
- Static versus dynamic: a fixed array wastes memory when underused and fails when full, whereas a dynamic list reallocates as needed.
静态与动态:固定数组在闲置时浪费内存、满时又无法写入,而动态列表可按需重新分配。 - Records: a record groups related fields of different types, such as a student record with a name string and a mark integer.
记录:记录把不同类型但相关的字段组合起来,例如含有姓名字符串广告 / Sponsored现货 Cambridge International AS & ALevel IT Coursebook剑桥国际IGC…计算机 备考教辅 · 正版现货 · 与本文内容相关查看详情 / View on Taobao参考价 ¥467.0更多咨询请联系16621398022(同微信)
备考资讯每日更新,关注不错过考纲变化 · 科目分析 · 学习方法
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图公众号:tutorhao