Bubble Sort — O(n²)

Compare elementos adjacentes, troque se fora de ordem. Repita.

Tempo: O(n²) pior/medio, O(n) melhor (ja ordenado)
Espaco: O(1) in-place
Estavel: Sim
Python
def bubble_sort(arr):
n = len(arr)
Python
    for i in range(n):
        for j in range(n - i - 1):
            if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
Python
    return arr