Bubble Sort

The Bubble Sort is a simple algorithm for ordering the values within an array. However, while it maybe simple, it is not as efficent as other algorithms unless the array it is being applies to meets specific conditions.

Here are the steps the algorithm takes:

  • Take the first two values in the array
    • Compare them (if value 1 is greater (>) than value 2)
    • If Value 1 is greater than value 2 - Swap them
    • Else If Value 1 is less than value 2 - Do nothing
  • Move into the next pair
  • Repeat until there are no more pairs to compare
  • Go back to the first two values in the array
  • Continue to repeat until you can go through the array without re-ordering any values

The number of passes required increase significantly with the number of items in the array. If the values are in reverse order (which is the worse case scenario) it would take n^2 comparisons. If you had 10 values in reverse order it would take 100 comparisons.


Included in the following specifications:
Edexcel GCSE Computer Science
OCR GCSE Computer Science