AiTechWorlds
AiTechWorlds
Animate Bubble Sort step-by-step with live pseudocode highlighting, comparison/swap counters, and C++/Java/Python/JS code.
def bubble_sort(a):
n = len(a)
for i in range(n - 1):
for j in range(n - 1 - i):
if a[j] > a[j + 1]:
a[j], a[j + 1] = a[j + 1], a[j]Bubble Sort repeatedly compares adjacent elements and swaps them when out of order, letting the largest values "bubble" to the end on each pass.
| Best | O(n) |
| Average | O(n²) |
| Worst | O(n²) |
| Space | O(1) |
| Stable | Yes |
| In-place | Yes |
The Bubble Sort Visualizer animates how Bubble Sort works: it repeatedly compares adjacent elements and swaps them when they are out of order, letting the largest value 'bubble' to the end on each pass. Bubble Sort runs in O(n²) average and worst case, O(n) best case on already-sorted data, uses O(1) extra space, and is stable. Use Play, Step, and the timeline to follow every comparison and swap.
Generate an array
Click New Array or set the size slider to create a random dataset of bars.
Play the animation
Press Play to watch comparisons (yellow) and swaps (red); sorted bars turn green.
Step and scrub
Use Step Forward/Back or drag the timeline to inspect any individual step.
Read the synced code
The highlighted pseudocode line shows exactly what the algorithm is doing; switch language tabs for C++, Java, Python, or JavaScript.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.