logo
SEE ALGORITHMS
    Bubble Sort
    Insertion Sort
    Selection Sort
    Heap Sort
    Merge Sort
    Quick Sort
    Radix 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:  

Curious to Learn More?

Hand-picked resources to deepen your understanding

Beginner Friendly
Grokking Algorithms

A friendly, fully illustrated guide. The best starting point for visual learners.

Practical Guide
A Common-Sense Guide to Data Structures and Algorithms

A practical guide with clear explanations and real-world examples.

Deep Dive
Introduction to Algorithms

The definitive guide (CLRS). Comprehensive and rigorous, perfect for deep diving into theory.

As an Amazon Associate, I earn from qualifying purchases. This helps support the site at no extra cost to you.

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