Searching, Sorting and Recursion – OCR A Level Computer Science lessons (H446)
Fifteen Year 12 lessons on linear and binary search, bubble, insertion, merge and quick sort, and recursion, plus Bebras practice.
Students write, trace and compare the standard searching and sorting algorithms in code and pseudocode. Recursion arrives before merge sort and quick sort so that divide and conquer makes sense, and the unit ends by judging which algorithm suits a given data set.
Unit 12.4 is taught in Year 12, Autumn 2, and answers one big question: Why do programmers need more than one way to search and sort?
What happens in each lesson:
Lesson 1, Bebras practice: How do you tackle a puzzle you have never seen before? By the end, students can apply problem-solving strategies to unfamiliar Bebras tasks and explain the reasoning behind each answer.
Lesson 2, Bebras Challenge: How well can you reason under time pressure? By the end, students can sit the UK Bebras Computational Thinking Challenge, managing their time and checking answers against the task's rules.
Lesson 3, Linear search: How does a computer find an item in an unsorted list? Main task: write a function linearSearch(uploads, title) in Python and OCR pseudocode that returns the index of a track title in Tidewave Audio's unsorted list of today's uploads, or -1 if it is not there (5 marks).
Lesson 4, Binary search: Why is binary search so fast, and what does it need? Main task: write an iterative binary search in Python and OCR pseudocode that finds a track ID in Tidewave Audio's sorted catalogue of 4 000 000 IDs, and state the maximum number of comparisons it makes (6 marks).
Lesson 5, Bubble sort: How does bubble sort put a list in order? Main task: write a bubble sort in Python and OCR pseudocode that sorts Tidewave Audio's daily play counts into descending order, using a temporary variable for each swap and a flag to stop when a pass makes no swaps (6 marks).
Lesson 6, Insertion sort: How does insertion sort place each item in order? Main task: write an insertion sort in Python and OCR pseudocode that puts the track lengths (in seconds) of a Tidewave Audio playlist into ascending order (6 marks).
Lesson 7, Recursion: How can a subroutine solve a problem by calling itself? Main task: write a recursive function totalLength(tracks, n) in Python and OCR pseudocode that returns the total length in seconds of the first n tracks of a Tidewave Audio playlist, and identify its base case and general case (5 marks).
Lesson 8, Recursion compared with iteration: When is recursion better than a loop, and when is it worse? Main task: compare recursive and iterative versions of Tidewave Audio's totalLength function in terms of memory use, risk of failure and how easy each is to follow (6 marks).
Lesson 9, Divide and conquer: How does splitting a problem in half make it easier to solve? Main task: explain how binary search uses divide and conquer to find a track ID in Tidewave Audio's sorted catalogue, and why this makes it more efficient than linear search on the same data (6 marks).
Lesson 10, Merge sort: How does merge sort use divide and conquer to sort? Main task: trace how merge sort sorts Tidewave Audio's eight newest tracks by play count, [52, 17, 88, 31, 64, 9, 40, 75], writing the sublists after each split and after each merge (6 marks).
Lesson 11, Quick sort: How does quick sort put each pivot in its final place? Main task: trace how quick sort sorts Tidewave Audio's list of track lengths [210, 185, 240, 160, 300, 195], using the first item of each sublist as the pivot and writing the list after each partition (6 marks).
Lesson 12, Recursive binary search: How do you write binary search recursively, and check it stops? Main task: write a recursive binary search function in Python and OCR pseudocode that returns the position of an artist ID in Tidewave Audio's sorted artist list, or -1 if it is absent (6 marks).
Lesson 13, Choosing an algorithm for a data set: Which algorithm should you choose for this data? Main task: discuss which searching and sorting algorithms Tidewave Audio should use for its catalogue search, its nightly sort of 2 million play counts and its nearly sorted weekly chart, considering execution time and memory (9 marks, levels-marked 7–9 / 4–6 / 1–3).
Lesson 14, Programming practice: searching and sorting: Can you write and trace searches and sorts fluently? Main task: write a program for Tidewave Audio that sorts a list of track titles alphabetically with insertion sort, then uses binary search to report whether a requested title is in the list and at which position (8 marks).
Lesson 15, Progress Check: 33 multiple-choice questions (homework or the start of the lesson) + a 40-mark written paper in the lesson (45 minutes)
- Misconceptions it tackles include
- “Linear search only works on sorted data”; “Binary search works on any list”; “Two items can be swapped with a = b then b = a”. Each is planned into a hinge question before the main task or an exit question, so you find out who still holds it.
- OCR H446 specification coverage
- 2.2.1 (b), recursion: how it can be used, and how it compares with an iterative approach; 2.3.1 (a), (b), (f), analysis and design of algorithms for a given situation; the suitability of algorithms for a task and data set in terms of execution time and space; the standard algorithms bubble sort, insertion sort, merge sort, quick sort, linear search and binary search (Dijkstra's and A* follow in 13.4); 2.2.2 (d), use of divide and conquer as a computational method.
It builds on 12.2 Programming Foundations (selection, count- and condition-controlled loops, arrays, functions, parameters and trace tables in Python and OCR pseudocode) and GCSE 2.1 (linear, binary, bubble, insertion and merge sort by hand). 12.3 Data Representation comes just before; nothing in it is needed here. It leads on to 12.8 Data Structures (the call stack is a stack; tree traversals and binary search trees are recursive), 12.10 Computational Methods and the Year 12 exams, 13.2 Big O (the growth rates met informally here), 13.4 Dijkstra's and A* and the programming project, where students choose and justify algorithms.
- Adapting it for your school
- Lessons 1 and 2 must fall in the UK Bebras Challenge window (November): register the school and book a computer room in advance. If the dates do not fit, move lesson 2 (the flex lesson) and teach lesson 3 first. Tidewave Audio is a fictional music-streaming service. Swap it for any organisation with a large data set your students know; every Build keeps its structure. Lesson 14 is the second flex lesson: if time is short, set its Build as homework. Programming lessons need Python 3 with an editor such as IDLE or Thonny; every one has a paper version.
An independent resource written for OCR A Level Computer Science (H446). It is not endorsed by OCR or Cambridge University Press & Assessment. Programming project (NEA) lessons teach general skills on a made-up example project and give supervised time, within JCQ's rules on the help a centre may give.
What's included
- 15 lesson slide decks (PowerPoint)
- 15 lesson plans (Word)
- 15 worksheets, plus 12 support versions with scaffolds (Word)
- 1 exam-style paper with mark scheme (Word)
- Medium term plan with intent, key words, misconceptions and adaptive teaching notes (Word)
- Progress Check lesson to assess the unit
- Programming practice - searching and sorting - Quiz Quiz Trade Cards
- Department licence: every teacher in your department can use and adapt it
In this bundle
Worth £60 bought separately at £4 a lesson. The bundle saves you 25%.
More for A Level Computer Science
See allFifteen Year 12 lessons on registers, buses, the fetch–decode–execute cycle, performance, pipelining, CISC and RISC, GPUs and storage.
Free sample lessonSixteen Year 12 lessons on programming foundations: variables, selection, iteration, subroutines, parameters, files and computational thinking.
Free sample lessonThirteen Year 12 lessons on binary and hex, sign and magnitude, two's complement, shifts, bitwise masks, character sets and logic gates.
Free sample lessonWritten for the specifications named. Not endorsed by or affiliated with any exam board.