Skip to content
BENIBIX Learn

Bubble Sort

Development🧮 Algorithms & Data StructuresSorting Algorithms

Also known as Sinking Sort

A simple sort that swaps neighbours until the list is in order. It is slow.

Think of it like

Think of it like bubbles in a glass. The biggest ones float up to the top, one at a time.

Example

Jack's class sorts five cards with bubble sort by hand. It takes four passes, and the 9 moves one place right each time.

Why it matters

It is the first sort most people learn. It shows why speed matters.

Definition

Bubble sort walks through a list again and again. It swaps any two neighbours that are in the wrong order. After each pass, the largest item left has bubbled to the end. It stops when a full pass makes no swaps. It takes O(n²) steps, so a list of 10,000 items needs about 100 million comparisons. It is mostly used to teach how sorting works.

Common mistake

Using it on real data. A built-in sort is thousands of times faster on a big list.

Key takeaways

  1. 1
    Swap neighbours. When out of order.
  2. 2
    Pass after pass. Until no swaps.
  3. 3
    O(n²). For teaching, not work.