Bubble sort is named after bubbles rising in water. It compares two neighbouring items, swaps them if they are in the wrong order, and moves along the list. After one full run (a pass), the largest value has "bubbled up" to the end. It keeps making passes until the list is sorted.
This is the bubble sort flowchart. It uses two loops: i counts the passes and j moves along the list comparing neighbouring items.
This introduction covers Bubbles Rising to the Top within Bubble Sort for GCSE Computer Science. Revise Bubble Sort in 3.1 Fundamentals of Algorithms for GCSE Computer Science with 16 exam-style questions and 10 flashcards. This topic appears regularly enough that it should still be part of a steady revision cycle. It is section 1 of 7 in this topic. Use this introduction to connect the idea to the wider topic before moving on to questions and flashcards.
Practice questions for Bubble Sort
Which of the following best describes bubble sort?
Describe how bubble sort works. You should refer to what happens during each pass through the list. [3 marks]