2026-05-02
Written by: Juri Breslauer
Algorithm Notes
Bubble sort compares two neighboring values. If the left value is bigger, they swap places. After each pass, the largest unsorted value has moved to the right side.
Interactive demo
The animation uses exactly 15 bars. On every step, bubble sort looks at two neighbors:
Bubble sort is easy to understand, but it is not efficient for large inputs.
In the average and worst case it needs O(n²) comparisons. For 15 bars that is
fine for a visual demo. For thousands of items, a better sorting algorithm is
usually the right choice.
Here are examples of the same bubble sort algorithm in different programming languages.