← SortingBubble Sort
Repeatedly swaps adjacent elements that are out of order.
Step 1 of 49
Starting Bubble Sort. Repeatedly swap adjacent elements that are out of order.
▶Algorithm
BubbleSort(arr):
for i = 0 to n−2:
for j = 0 to n−2−i:
if arr[j] > arr[j+1]:
swap arr[j], arr[j+1]
// sorted
Legend
Comparing
Swapping
Sorted
Unsorted
1 / 49Speed