Bubble Sort Animation & Pseudocode Walkthrough
Bubble sort works by repeatedly stepping through the list, comparing adjacent elements and swapping them when they are out of order. Each pass pushes the largest remaining value to its final position, much like a bubble rising to the surface. This visualizer lets you follow the algorithm line-by-line, highlighting the pseudocode, tracking comparisons and swaps, and updating the animation as you step through the process.
Pseudocode
- set swapped to true
- while swapped is true:
- set swapped to false
- for i from 0 to n - 2:
- if array[i] > array[i + 1]:
- swap array[i] with array[i + 1]
- set swapped to true
Array Animation
comparing
swapping
sorted
Press Play or Step Forward to begin.