Computer Science

Bubble Sort

Compare. Swap. Repeat.

Complete all 5 tasks, then screenshot your score for Teams.

Task 1 of 5 Pass 1 Pair 1 of 5 0 comparisons

Should these two numbers be swapped?

Hints are optional. You can sort the numbers without them.

Bubble Sort Challenge

5/5 correct

Accuracy 100%

How Bubble Sort works

Bubble Sort walks along the list and compares two neighbouring numbers. If the left number is larger, they swap, so the larger number moves one place to the right. If the left number is smaller, or the two numbers are equal, they stay where they are.

After each full pass, the next largest number has bubbled into its final place and is marked in place. The next pass stops before that position, so there are fewer comparisons. If a whole pass makes no swaps, the list is already sorted and the algorithm stops early.