Sorting Visualizer

Bubble Sort

Speed 100ms
Size 20
Step Progress 0 / 0
Comparisons 0
Swaps / Shifts 0
Status Ready
Default
Comparing
Swapping
Pivot / Min
Sorted
Held key (ghost)
Step Explanation

Click 'Play' or 'Step Forward' to begin visualization.

Bubble Sort • Time: O(n²) • Space: O(1)
Pseudocode
        
History

Select an algorithm to see its history.

Algorithms & Data Structures

Elementary (2/5) ~varies per algorithm Sorting Big-O Notation Divide & Conquer Comparison Sorts Non-Comparison Sorts
Quick Reference

Bubble Sort

Bubble Sort is a foundational comparison sort that repeatedly steps through an array, compares adjacent pairs, and swaps them if out of order. Larger values continuously bubble up to the end of the array.

Difficulty: Beginner (1/5) Stablesorting

Complexity

Best Time
O(n)
Average Time
O(n²)
Worst Time
O(n²)
Space
O(1)

When to Use

Best suited for small datasets, educational visual demonstrations, or arrays that are already known to be nearly sorted.

Pros

  • In-place algorithm requiring O(1) auxiliary space
  • Stable: preserves the relative order of duplicate elements
  • Adaptive: achieves O(n) best-case time when array is already sorted

Cons

  • Poor performance on large datasets (O(n²) comparisons and swaps)
  • High number of redundant data swap operations

History

Bubble Sort was first analyzed in the early 1950s. The term "bubble sort" was popularized by Kenneth E. Iverson in his 1962 book A Programming Language.

Algorithms & Data Structures

This topic links to the interactive sorting algorithms visualizer. Explore 10 classic and modern sorting algorithms with real-time step-by-step animation, element comparisons, swaps, step counts, and Big-O efficiency metrics.

Jump to Interactive Studio →