Bubble Sort

1/0
1.0x

Bubble Sort

O(n²)Space: O(1)

Pseudocode

1procedure bubbleSort(A: list)
2 n ← length(A)
3 for i ← 0 to n-1 do
4 swapped ← false
5 for j ← 0 to n-i-2 do
6 if A[j] > A[j+1] then
7 swap(A[j], A[j+1])
8 swapped ← true
9 if not swapped then
10 break
11 return A