Course Content
Paper 2 – Problem Solving Approach -Practical
0/102
Past Paper-2 May/June 2025
Past Paper-1 May/June 2025
Download Files
0/1
Olevel : Computer Science 2210 / IGCSE 0478 : Recorded

It is used to arrange data in ascending or descending order by repeatedly comparing adjacent values and swapping them if they are in the wrong order.

In bubble sort, the algorithm works in passes. During each pass, the program starts from the beginning of the list and compares the first two values. If the first value is greater than the second value, they are swapped. Then the second and third values are compared, followed by the third and fourth, and so on until the end of the list. By the end of one full pass, the largest value “bubbles up” to the last position in the list, which is why this method is called bubble sort.

The process is repeated again and again. With each new pass, one less comparison is needed because the largest values are already placed at the end of the list. The algorithm continues until all the values are in the correct order. Bubble sort uses a temporary variable to help swap values during comparison.

For example, if the list is 8, 9, 12, 2, 1, the algorithm will first compare 8 and 9, then 9 and 12, then 12 and 2 (which are swapped), and then 12 and 1 (which are swapped). After the first pass, the largest number is placed at the end. After several passes, the final sorted list becomes 1, 2, 8, 9, 12.

In exams, remember these key points: bubble sort compares adjacent elements only, uses nested loops, requires a temporary variable for swapping, and is easy to understand but not very efficient for large data sets.

You cannot copy content of this page