Interactive Sorting Algorithm Visualization
Bubble Sort: Compares adjacent elements and swaps them if in wrong order.
Bubble Sort is a simple sorting algorithm that 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.
The algorithm gets its name from the way smaller elements "bubble" to the top of the list. While it's simple to understand and implement, it's not efficient for large datasets with its average and worst-case time complexity of O(n²).
procedure bubbleSort(A : list of sortable items)
n := length(A)
repeat
swapped := false
for i := 1 to n-1 inclusive do
if A[i-1] > A[i] then
swap(A[i-1], A[i])
swapped := true
end if
end for
n := n - 1
until not swapped
end procedure