logo
SEE ALGORITHMS
    Bubble Sort
    Insertion Sort
    Selection Sort
    Radix Sort
    Heap Sort
    Merge Sort
    Quick Sort

Bubble Sort

Bubble Sort is a simple sorting algorithm that works by repeatedly swapping adjacent elements if they are in the wrong order. This process continues until the list is fully sorted. While it’s easy to understand, Bubble Sort is not very efficient for large datasets due to its quadratic time complexity. It’s often used for educational purposes or as a baseline for comparison with other sorting algorithms.

Things to Observe

  • Bubbling Up: In each pass through the list, notice how the largest unsorted element gradually"bubbles up" to its correct position at the end of the array. This is why the sorted portion of the array grows from right to left.
  • Early Termination: This visualization uses an optimized version of Bubble Sort. If a full pass is completed with no swaps, the algorithm knows the list is already sorted and stops early. Try a nearly-sorted list to see this in action!
for i = 1 to (n - 1):
    swapped = false
    for j = 1 to (n - i):
        if arr[j] < arr[j + 1]:
            swap(j, j + 1)
            swapped = true
    if not swapped: break
Select number of elements:  

© 2025 SEE Algorithms. Code licensed under MIT, content under CC BY-NC 4.0.