Revise Computing
Revision notesQuestionsFor schools
Log inStart revising free
Revision notesQuestionsFor schoolsLog in
GCSE Computer Science/Paper 2/Searching and sorting algorithms

Bubble sort

Standard sorting algorithms: Bubble sort

2.1.3 Searching and sorting algorithms

Practise exam questions

Searching and sorting algorithms — Note 3 of 5

Understand the main steps of each algorithm, Understand any pre-requisites of an algorithm, Apply the algorithm to a data set, Identify an algorithm if given the code or pseudocode for it

What you need to know

Bubble sort is a simple sorting algorithm that repeatedly goes through a list, comparing adjacent pairs of items and swapping them if they are in the wrong order. Each full pass through the list 'bubbles' the largest unsorted item to its correct position. The algorithm continues making passes until no swaps are needed, meaning the list is sorted.

What to know

  • Compare each pair of ADJACENT items and swap them if they are in the wrong order.
  • After each pass, the largest unsorted item 'bubbles up' to its correct position at the END of the list.
  • The sorted section builds from the RIGHT (end) of the array.
  • Each new pass requires one fewer comparison because the end of the list is already sorted.
  • The algorithm makes a FINAL pass with no swaps to confirm the list is sorted, then stops.
  • Needs MULTIPLE PASSES through the data — a value may be repeatedly swapped until it reaches its correct position.
  • Simple to understand and implement, but inefficient for large or heavily unsorted datasets.
  • Similarities with Insertion Sort: both sort in place, both use loops/iteration, both compare pairs of values, both swap values, both use a temporary variable, both build a sorted list one item at a time.
  • Differences from Insertion Sort: bubble sort builds sorted section from the END; insertion sort builds it from the START. Insertion sort is generally more efficient on average.

Code examples

Bubble sort in Python
python
def bubble_sort(data):
    n = len(data)
    for i in range(n - 1):
        for j in range(n - 1 - i):
            if data[j] > data[j + 1]:
                data[j], data[j + 1] = data[j + 1], data[j]
    return data

print(bubble_sort([3, 2, 9, 10, 7]))
# Output: [2, 3, 7, 9, 10]

Ready to test yourself?

Practise 2.1.3 questions
← Previous noteLinear search2.1.3 Searching and sorting algorithmsNext note →Merge sort2.1.3 Searching and sorting algorithms

Back to Searching and sorting algorithms

Revise another OCR GCSE topic: Designing, creating and refining algorithms

Searching and sorting algorithms

Note 3 of 5

  1. 1Binary search
  2. 2Linear search
  3. 3Bubble sort
  4. 4Merge sort
  5. 5Insertion sort
Topic overview

© 2026 Revise Computing · revisecomputing.co.uk

Privacy noticeTermsContact

Revise Computing is an independent revision resource. It is not affiliated with, or endorsed by, OCR (Oxford Cambridge and RSA Examinations).