Sorting Algorithms - Bubble

Other algorithms: Bubble | Insertion | Selection | Merge | Quick

Description

Compare each adjacent pair, with the highest values bubbling to the top.

Detailed Instructions

  1. Put the 6 boxes in order (1 to 6) in the answer spaces

  2. Compare the box in answer space 1 and answer space 2.
    Put the lighter box in answer space 1 and the heavier in answer space 2 (i.e. swap if necessary).

  3. Compare spaces 2 and 3, swapping if necessary.
    Keep going right through the list.
    The last item will now be the heaviest.

  4. Repeat steps 2 and 3, but you don't need to check the last box.

  5. Repeat steps 2 and 3, but don't check the last two boxes.

  6. Keep repeating until all the boxes are fixed in place.

  7. And finally, once you've completed the exercise, try to work out the maximum number of comparisons you would need to solve the problem with different numbers of boxes.
Number of boxes Maximum number of comparisons
2
1
3
4
5
6

Creative Commons License
Sorting Algorithms by Mark Clarkson is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.