EduKate by CECS robot logoEduKateby Cass Education & Careers Services
FREE OCR H446 REVISION GUIDE

Active OCR A Level Computer Science revision: trace, code and explain

Make revision varied and purposeful by connecting a practical algorithm trace to recursion, tested Python and reasoned comparisons.

Written by Kate CassOCR A Level Computer Science H446Original CECS guide

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

  1. First call: low = 0 and high = 7. The middle index is 3, containing 17. Since 42 is larger, continue with indexes 4 to 7.
  2. Second call: low = 4 and high = 7. The middle index is 5, containing 31. Continue with indexes 6 to 7.
  3. 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

  1. Trace a search for 24 in the same list. Record the bounds of every call.
  2. Predict the result for target 3.
  3. What happens with an empty list and initial bounds 0 and -1?
Show the worked answers
  1. 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.
  2. The middle indexes are 3, 1 and 0. The function finds 3 at index 0 and returns zero successfully.
  3. The first call meets low > high and 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.

1 Follow recursive calls and returns

Assume n is a non-negative integer. What value does total_to(4) return?

def total_to(n):
    if n == 0:
        return 0
    return n + total_to(n - 1)

Enter a number, without a unit symbol. For example, write 6.5 for six and a half.

Need a hint?

Expand the calls until the base case: 4 + total_to(3), then 4 + 3 + total_to(2). Work back out after total_to(0) returns.

Show the worked answer and explanation

Answer: 10. The returned value is 4 + 3 + 2 + 1 + 0. There are five calls, including the base-case call. Do not confuse the number of calls with the value returned.

For a negative n, this particular base case would never be reached by repeatedly subtracting 1. The stated input assumption matters.

2 Trace the indexes in binary search

Search for 30 in [2, 6, 10, 14, 18, 22, 26, 30, 34]. Start with low = 0 and high = 8. Use middle = (low + high) // 2, excluding the middle after an unsuccessful comparison. Which indexes are checked?

Need a hint?

The first middle index is 4. After finding that its value is too small, update low to 5 before calculating the next middle.

Show the worked answer and explanation

Answer: 4, 6, 7. At bounds (0, 8), index 4 contains 18. At bounds (5, 8), index 6 contains 26. At bounds (7, 8), index 7 contains 30 and the search stops.

The sequence 18, 26, 30 lists values, not indexes. A trace should label which quantity each column records.

3 Compare auxiliary space

Compare the recursive binary search in this guide with an iterative version that updates two bounds. Both use an already stored list and avoid slicing it. Which describes their worst-case auxiliary space?

Need a hint?

Count the additional state used during the search, including waiting calls. Do not count the input list itself as additional space.

Show the worked answer and explanation

Answer: recursive O(log n); iterative O(1). The recursive implementation keeps a stack of waiting calls whose depth is logarithmic in the worst case. The iterative implementation reuses a fixed number of variables.

These costs assume constant-sized indexes and comparisons. Creating slices would introduce copying costs and would require a separate analysis.

4 Recommend an algorithm with a qualification

A service repeatedly searches a large, sorted array by an ordered key. New entries must occasionally be inserted while keeping the array sorted. Recommend a search method and explain one maintenance cost the service should also consider. Write a short paragraph.

Use fictional details. Compare your work with the guidance; this activity does not award an automatic writing mark.

Need a hint?

Separate the cost of a search from the cost of maintaining the data structure. Explain why the sorted order helps, then consider what happens when an item is inserted in the middle.

Read a model response and review your writing

Model response: Binary search is suitable for repeated searches because the array is sorted and supports direct indexing. Each unsuccessful comparison excludes roughly half the remaining interval, giving O(log n) worst-case search time. However, inserting an item into a sorted array may require shifting later entries, which can take O(n) time. The service should consider the balance between searches and updates rather than treating the search cost as the cost of every operation.

A reasoned alternative may be appropriate if you state different data-structure or workload assumptions. The model describes the array stated in the question.

Review your own response:

5 Spot a recursive call that can repeat Fresh variation

A faulty search uses return search(values, target, low, middle) when the target is smaller than the middle value. Its only failed-search base case is low > high. If low = high = middle and the target is absent and smaller, what can happen?

Need a hint?

Substitute the same number for low, high and middle. Compare the next pair of bounds with the current pair.

Show the worked answer and explanation

Answer: the same bounds are passed again. The interval still contains the same non-matching item, so low > high stays false. Repeated calls eventually reach the runtime’s recursion limit instead of returning a normal failed-search result.

Excluding the already tested middle with middle - 1 makes the interval smaller and permits the empty-interval base case to be reached.

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

PUT THE ROUTINE INTO PRACTICE

Develop deeper explanations through further H446 practice

Explore the EduKate A Level course for technical explanations, algorithm activities, written-answer practice and programming tasks.

Explore the course subscription