42
0
17
1
88
2
33
3
71
4
9
5
56
6
25
7
64
8
12
9
AlgoPlus//sorting / bubble sort
Read the theory

Bubble Sort · Fluid Ecosystem

Pressure swaps ripple through the array like rising bubbles.

Stability
Stable
In-Place
Yes
Space Complexity
O(1)
Avg Time
O(n²)
Size10
Legend
Comparing
Swapping / moving
Tracked (min / key)
Pivot
Sorted / found
Out of focus
AI Tutor Workspace
In a nutshell
Bubble sort walks the list comparing each pair of neighbours and swapping them if they're out of order. Each full pass floats the next-largest value to its place at the end, so after enough passes everything is sorted. It's the simplest sort to picture but one of the slowest, since it only ever moves items one step at a time.
Ready
Press play to begin the cinematic walkthrough.
Imagine bubbles rising in liquid — heavier values sink, lighter ones float up to the surface.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Bubble Sort · Fluid Ecosystem.
Code Simulator
1
def bubble_sort(arr):
2
    n = len(arr)
3
    for i in range(n):
4
        for j in range(0, n - i - 1):
5
            if arr[j] > arr[j + 1]:
6
                arr[j], arr[j+1] = arr[j+1], arr[j]
Why Python? · Readable first, fast second

Dynamically typed and interpreted — every comparison and swap is dispatched by the interpreter at run time, so tight loops run roughly 10–100× slower than compiled C/C++. Unbeatable for learning the idea with the least code; not what you reach for when the inner loop is the bottleneck.