OCR GCSE计算机 算法 流程图 伪代码 排序
OCR GCSE Computer Science 的 J277 课程把算法放在 Paper 2 的核心位置,计算思维、伪代码、流程图、排序与查找几乎每年必考。很多同学能背出冒泡排序的代码,却在"用伪代码写一个算法"这类题上丢分,原因不是不会编程,而是没有把算法当成一套可以拆解、可以描述的思考流程。本文用中英双语梳理 OCR GCSE 算法模块的全部考点,从计算思维的定义到三种基础排序、两种查找算法的逐步演示,再到考场答题技巧与复习计划,帮你把这一块从看得懂变成写得出、拿满分。
Paper 2 in the OCR J277 course puts algorithms at the centre of the exam. Computational thinking, pseudo-code, flowcharts, sorting and searching appear almost every year. Many students can recite bubble sort code but lose marks on questions that ask them to write an algorithm in pseudo-code. The problem is not programming ability, it is that they never treat an algorithm as a describable process. This bilingual guide covers the whole algorithm topic, from the definition of computational thinking to three sorting algorithms, two searching algorithms, exam technique and a revision plan.
1. 计算思维与算法基础 What Is an Algorithm
算法(algorithm)是一组有限、有序、无歧义的指令,用来解决某个问题。OCR 考纲强调算法思维伴随的三个概念:抽象(abstraction)、分解(decomposition)与算法思维(algorithmic thinking)。抽象是忽略不相关的细节,只保留解决问题需要的特征;分解是把大问题拆成若干个可以独立解决的小问题;算法思维则是把解决步骤表达成一系列清晰、可执行的指令。考试里最常见的问法是请你给出一个抽象化的具体例子,标准答案往往落在"地铁图只画线路与车站,不画建筑物""游戏只保留玩家的位置与速度"这类真实场景上,而不是重复定义。此外还要记住算法的五个特征:输入、输出、有限性、确定性、有效性。有限性指算法必须在有限步内结束,确定性指每一步的结果唯一可预测,这两点常作为判断题出现。
An algorithm is a finite, ordered and unambiguous set of instructions that solves a problem. The OCR specification links algorithms with three ideas: abstraction, decomposition and algorithmic thinking. Abstraction means removing irrelevant detail and keeping only the features that matter. Decomposition means breaking a large problem into smaller problems that can be solved separately. Algorithmic thinking means expressing the solution as clear, executable steps. Exam questions usually ask for a concrete example of abstraction rather than a definition, so learn one: a subway map shows lines and stations but omits buildings and distances. Also memorise the five properties of an algorithm: input, output, finiteness, definiteness and effectiveness. Finiteness means the algorithm stops after a limited number of steps, and definiteness means every step has exactly one predictable result.
2. 伪代码与流程图 Pseudocode and Flowcharts
OCR 使用一种接近 Python 的伪代码,但要求手写在答题线上时保持结构清晰。三个基本结构必须能默写:顺序(sequence)、选择(selection)、迭代(iteration)。选择写成 if ... then ... elseif ... else ... endif;迭代写成 while ... endwhile,或者 for i = 1 to 10 ... next i。缩进不是装饰,它帮助阅卷老师确认你的分支嵌套层级,建议每层缩进两个空格。流程图(flowchart)考的是符号规范:圆角矩形表示开始与结束,平行四边形表示输入与输出,矩形表示处理过程,菱形表示判断,箭头表示流向。画流程图时最容易失分的地方是判断框只写一个出口标签,必须同时写出 True 与 False 两条分支。转换题常要求把流程图改写成伪代码,或者把伪代码画成流程图,两个方向都要练。
OCR uses a pseudo-code that looks like Python but is written by hand under exam conditions. Three control structures must be reproduced from memory: sequence, selection and iteration. Selection uses if ... then ... elseif ... else ... endif and iteration uses while ... endwhile or for i = 1 to 10 ... next i. Indentation is not decoration, it shows the examiner how your branches nest, so use two spaces per level. Flowchart questions test symbol conventions: a rounded rectangle means start or end, a parallelogram means input or output, a rectangle means a process, a diamond means a decision and arrows show the direction of flow. The most common lost mark is a decision box with only one exit label, when both True and False branches are required. Expect conversion tasks in both directions, from flowchart to pseudo-code and from pseudo-code to flowchart.
3. 排序算法 Sorting Algorithms
OCR 要求掌握冒泡排序(bubble sort)与插入排序(insertion sort),部分教材还会提到归并排序(merge sort)。冒泡排序重复比较相邻的两个元素,顺序错误就交换,每一轮把当前最大的元素冒到数组末尾。对 n 个元素,最多需要 n-1 轮,而且每轮的比较次数递减。冒泡排序在最坏情况下的比较次数是 n(n-1)/2,时间复杂度为 O(n^2)。插入排序把数组分成已排序与未排序两部分,每次取未排序部分的第一个元素,在已排序部分从后向前找到合适位置插入。数据接近有序时插入排序非常快,这是它与冒泡排序最重要的差别。归并排序采用分治(divide and conquer),把数组不断对半拆分直到每个子数组只剩一个元素,再两两合并且保持顺序。归并排序的时间复杂度是 O(n log n),但需要额外的存储空间。考试中常见的题型是给出一个数组,写出第一轮冒泡排序后的结果,或者比较两种排序在已经有序的数据上的表现。
OCR requires bubble sort and insertion sort, and many textbooks also cover merge sort. Bubble sort repeatedly compares adjacent items and swaps them when they are in the wrong order, so after each pass the largest remaining value has moved to the end of the list. For n items you need at most n-1 passes, and the number of comparisons in each pass decreases. In the worst case bubble sort makes n(n-1)/2 comparisons, giving a time complexity of O(n^2). Insertion sort divides the list into a sorted part and an unsorted part, takes the first item of the unsorted part and inserts it into the correct position by scanning backwards through the sorted part. It is very fast on nearly sorted data, and that is the key difference from bubble sort. Merge sort uses divide and conquer: split the list in half until every sublist holds one item, then merge the pairs back together in order. Merge sort runs in O(n log n) time but needs extra memory for the merged lists. Typical exam tasks give you a list of values and ask for the result after the first pass of bubble sort, or ask you to compare how the two algorithms behave on data that is already sorted.
4. 查找算法 Searching Algorithms
线性查找(linear search)从第一个元素开始逐个比较,直到找到目标或者检查完所有元素。它不要求数据有序,平均需要检查一半元素,最坏情况检查 n 个,时间复杂度为 O(n)。二分查找(binary search)要求数据已经按升序或降序排列,每次把查找区间缩小一半:先取中间元素,若等于目标则结束,若目标更小则在左半部分继续,否则在右半部分继续。对 n 个元素,最多需要约 log2(n) 次比较,因此 1000 个元素只需约 10 次比较,而线性查找可能要 1000 次。考试最常挖的坑是二分查找能不能用在无序数据上,答案是不能,必须先排序,而排序本身也有成本。写伪代码时要写清 low、high、mid 三个变量的更新,尤其是循环条件要用 low <= high 而不是 low < high,否则区间只剩一个元素时会被漏查。
A linear search starts at the first item and compares each item in turn until the target is found or the list ends. It does not need sorted data, it examines about half the items on average and all n items in the worst case, so it runs in O(n) time. A binary search requires the data to be sorted. It halves the search range on every step: look at the middle item, stop if it matches, continue in the left half if the target is smaller, otherwise continue in the right half. For n items it needs about log2(n) comparisons, so 1000 items take roughly 10 comparisons while a linear search may take 1000. The classic exam trap is whether a binary search works on unsorted data. It does not, the data must be sorted first, and sorting has its own cost. In pseudo-code, be careful to update low, high and mid correctly, and use the loop condition low <= high rather than low < high, otherwise the final single item is skipped.
5. 算法效率与常见陷阱 Efficiency and Common Traps
效率(efficiency)在 OCR 里既指时间,也指空间。大 O 记号用来说明算法运行时间随数据规模增长的趋势:O(1) 是常数时间,例如直接访问数组中的某个下标;O(n) 是线性时间,例如线性查找;O(n^2) 是平方时间,例如冒泡排序;O(n log n) 是归并排序的级别。需要注意大 O 描述的是增长趋势而不是精确秒数,所以不要写冒泡排序需要 0.5 秒这样的答案。三个高频失分点:第一,把变量写成 a1、a2、a3 而不是用数组与下标,导致算法无法处理任意长度的数据;第二,忘记初始化计数器,例如交换次数 count = 0,程序在第一次累加时就会出错;第三,在 while 循环里漏掉让条件最终为假的语句,造成死循环(infinite loop)。检查算法是否正确的实用方法是桌面检查(dry run):取一个只有 3 到 4 个元素的小数组,逐步记录每个变量的值,结果与手算答案一致才算通过。
Efficiency covers both time and space. Big O notation describes how the running time grows as the amount of data grows: O(1) is constant time, such as reading a value at a known index; O(n) is linear, such as a linear search; O(n^2) is quadratic, such as bubble sort; O(n log n) is the level of merge sort. Remember that Big O describes a trend, not a number of seconds, so never answer that bubble sort takes half a second. Three frequently lost marks: first, naming variables a1, a2, a3 instead of using one array with an index, so the algorithm cannot handle lists of any length; second, forgetting to initialise a counter such as count = 0 before it is incremented, so the first addition fails; third, leaving out the statement that eventually makes a while condition false, which creates an infinite loop. A practical way to check your algorithm is a dry run: take a small list of three or four values, trace every variable step by step, and accept the answer only when it matches the result you worked out by hand.
6. 答题技巧与六周复习计划 Exam Technique and Revision Plan
OCR 算法题的分数分布通常是理解占 1 分,应用占 3 到 6 分。拿满分的策略是把题目里的数据逐个回填:如果题目给出数组 7、3、5,就要在答案中明确写出每次比较和交换的元素,而不是只写最终顺序。遇到描述一个算法的题目,按输入、处理、输出三段来写,每段一到两句话,比写一大段散文更容易得分。六周复习计划可以这样安排:第一周专攻伪代码语法与流程图符号;第二周手写冒泡排序并做三轮桌面检查;第三周练插入排序以及接近有序数据的比较题;第四周练二分查找的区间更新与比较次数计算;第五周把近五年 Paper 2 的算法题重做一遍并统计失分类型;第六周限时模拟,每道算法题控制在 6 分钟内完成。每天 20 分钟手写伪代码的效果远好于反复阅读代码,因为 OCR 考的是你能否独立写出算法,而不是能否看懂算法。
Marks in OCR algorithm questions usually follow the pattern of one mark for understanding plus three to six marks for application. The way to secure full marks is to answer with the actual data from the question: if the list is 7, 3, 5, state which two items are compared and swapped at each step instead of only writing the final order. When asked to describe an algorithm, structure the answer as input, process and output with one or two sentences each, which scores more reliably than one long paragraph. A six week revision plan works well: week one for pseudo-code syntax and flowchart symbols; week two for writing bubble sort by hand with three dry runs; week three for insertion sort and comparisons on nearly sorted data; week four for updating the binary search range and counting comparisons; week five for redoing the algorithm questions from the last five years of Paper 2 and listing the types of marks you lost; week six for timed practice with six minutes per algorithm question. Twenty minutes of hand written pseudo-code a day beats rereading code, because OCR tests whether you can produce an algorithm, not whether you can recognise one.
把六个部分连起来看,OCR GCSE Computer Science 的算法模块其实只有一条主线:用抽象与分解理解问题,用伪代码或流程图表达解法,用排序与查找完成典型任务,再用效率分析与桌面检查验证结果。考试时先写结构,再填细节,分数就会稳定下来。
Put together, the algorithm topic in OCR GCSE Computer Science follows a single thread: understand the problem through abstraction and decomposition, express the solution in pseudo-code or a flowchart, use sorting and searching for typical tasks, then check the result with efficiency analysis and a dry run. Write the structure first and fill in the detail afterwards, and your marks will become consistent.
戴睿(dere)Neo优选系列 创意双触摸屏高性能笔记本电脑大学生AI学习商务办公设计炒股娱乐手提轻薄本32/1TB¥4586.0📱 去京东购买京东精选
需要一对一辅导?Need One-on-One Tutoring?
A-Level / GCSE / IB / KS2-KS3 全科辅导
16621398022 同微信
Visit aleveler.com
或截图后用「扫一扫 → 相册」选择本图