OCR A Level Computer Science revision can be varied while keeping the thinking demanding. Change what you produce: an explanation, a trace, a diagram, a tested program or a reasoned comparison. This guide uses recursive binary search to connect several of those activities, then shows how to build them into a manageable revision session.
Try five free practice activities with hints and worked feedback →
Give each activity a clear purpose
The Cambridge OCR H446 specification includes recursion, standard algorithms and analysis of their suitability, time and space requirements. The example below develops those selected ideas. Keep your full specification checklist alongside it: one worked algorithm does not cover the whole course.
Before running any code, predict its behaviour. Use numbered cards to represent the list, or sketch the remaining search interval after each comparison. Then explain which values can be excluded and why. This makes the activity practical while keeping the reasoning visible.
Worked example: recursive binary search
The list must be sorted in ascending order. The initial bounds are zero and the last index. The function returns a matching index, or -1 when the target is absent.
def binary_search(values, target, low, high):
if low > high:
return -1
middle = (low + high) // 2
if values[middle] == target:
return middle
if values[middle] < target:
return binary_search(values, target, middle + 1, high)
return binary_search(values, target, low, middle - 1)
numbers = [3, 8, 12, 17, 23, 31, 42, 56]
print(binary_search(numbers, 42, 0, len(numbers) - 1))
Trace the calls before running the program
- First call: low = 0 and high = 7. The middle index is 3, containing 17. Since 42 is larger, continue with indexes 4 to 7.
- Second call: low = 4 and high = 7. The middle index is 5, containing 31. Continue with indexes 6 to 7.
- Third call: low = 6 and high = 7. The middle index is 6, containing 42. Return 6.
The result travels back through the waiting calls and the program prints 6, the index of the seventh item. Each return binary_search(...) passes the recursive result back to its caller. Simply calling a function does not automatically return its value. A Python function that reaches its end without returning a value produces None.
Explain why the recursion terminates
There are two stopping outcomes. A matching middle item returns its index immediately. If the search interval becomes empty, low > high returns -1 before any list item is accessed.
Every unsuccessful comparison excludes the middle item and one side of the interval. The + 1 and - 1 therefore matter: the remaining interval gets smaller. Sorting is essential because it lets us justify excluding those values; the code does not check or sort the list for the caller.
Practise an absent target and a boundary
- Trace a search for 24 in the same list. Record the bounds of every call.
- Predict the result for target 3.
- What happens with an empty list and initial bounds 0 and -1?
Show the worked answers
- The bounds are (0, 7), (4, 7), (4, 4), (5, 4). The middle values checked are 17, 31 and 23. The final call has an empty interval and returns -1.
- The middle indexes are 3, 1 and 0. The function finds 3 at index 0 and returns zero successfully.
- The first call meets
low > highand returns -1. No list item is accessed.
Run each case after predicting it. Add a duplicate value and investigate which matching index is returned. This implementation finds a match; it does not promise the first occurrence.
Compare time and space with care
For a sorted list of n items, repeatedly reducing the interval by roughly half gives logarithmic worst-case search time, O(log n), assuming constant-time indexing and comparisons. A match at the first middle position is the constant-time best case.
The recursive version also needs O(log n) additional stack space in the worst case because calls wait for their results. An iterative version can update the two bounds in a loop using O(1) auxiliary space. Neither statement includes the memory already used to store the input list.
Passing bounds avoids creating list slices. If you rewrite the algorithm using slices, copying those slices changes its resource costs. Likewise, sorting an unsorted list is extra work: whether that preparation is worthwhile depends on the data and how many searches will follow.
Make the next session active and varied
Choose one small topic and spend a few minutes reconstructing it without notes. Next, draw or trace it. Run a short experiment, compare the result with your prediction and finish with a written explanation. Keep one corrected misconception as evidence of progress.
Use the same pattern for a queue, a processor operation, a Boolean expression or a database design. When evaluating a choice, connect the mechanism to its consequence in the scenario. A precise statement about memory, speed or maintainability is more useful than simply calling an approach “better”.
Continue with EduKate’s OCR A Level Computer Science course. Revisit the GCSE search-tracing guide for linear-search foundations, or use the computing study and evidence guide for additional practice organising technical work.
Five original practice activities
Try four short activities, then apply the idea in a fresh variation. Use a hint if you need one and compare your reasoning with the worked guidance. These are original exam-style practice activities, not official exam questions or a mock examination.
Your answers stay on this page and are not submitted or saved. Copy any writing you want to keep before leaving or refreshing.
Choose one useful next step
Explain the assumptions behind an algorithm’s cost, then test a found, absent and boundary case. Use the full worked binary-search example above to connect the code to the changing bounds.
Try a learning game · Run a free Python challenge · Build a CV with the free employability tools
