Sorting Visualizer sort.srujanyamali.com

Watch classic sorting algorithms reorder an array in real-time.

Interactive demo
O(n² to n log n) Visual comparisons & swaps Stable vs. unstable
Comparisons: 0
Writes: 0
Status: idle
srujanyamali · sorting

Algorithm details

Bubble Sort

Bubble sort repeatedly walks through the array, comparing adjacent elements and swapping them if they are in the wrong order. Large values "bubble" to the end of the array on each pass.

bubbleSort(a): n = length(a) repeat swapped = false for i from 0 to n - 2: if a[i] > a[i+1]: swap a[i], a[i+1] swapped = true until not swapped

Tip: drag Size to the right for more bars or slide Speed to tune the animation.