Sorting Algorithm Visualizer

Watch different sorting algorithms in action and understand how they work

Speed:
Unsorted
Comparing
Swapping
Sorted
0
Comparisons
0
Swaps
0.00
Time (ms)

Bubble Sort

Repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted.

Best: O(n)
Average: O(n²)
Worst: O(n²)
Space: O(1)

Pseudocode

procedure bubbleSort(A: list)
    n = length(A)
    for i = 0 to n-1 do
        for j = 0 to n-i-1 do
            if A[j] > A[j+1] then
                swap(A[j], A[j+1])
            end if
        end for
    end for
end procedure