Algorithms

Bubble sort

A sorting algorithm that compares neighbors and swaps them if they're backwards; the largest rises to the end like a bubble. O(n²) and stable.

Example

[3, 9, 1] → 3 < 9 untouched, 9 > 1 swapped: [3, 1, 9]. 9 is already at the end.

Test yourself: Bubble sort

Bubble sort

After bubble sort's first pass, the ___ element ends up last.

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.