Sorting Visualizer

36
20
4
55
87
99
46
9
87
1
73
90
19
58
31
25
26
58
94
42
66
Comparisons: 0
Swaps: 0
Time: 0.00 seconds

Bubble Sort

Description: 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.

Time Complexity: O(n²)

Space Complexity: O(1)

Pseudocode:

procedure bubbleSort(A: list of sortable items)
            n = length(A)
            for i from 0 to n - 1 do
                for j from 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

Time Complexity

Implementation

def bubble_sort(arr):
    n = len(arr)
    for i in range(n):
        for j in range(0, n - i - 1):
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]

Practice Problems