Codacoda
Back to Academy

sorting

Bubble Sort

Bubble Sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. It gets its name because smaller elements 'bubble' to the top of the list.

Use Cases

  • Educational purposes - understanding basic sorting
  • Small datasets where simplicity is preferred
  • Nearly sorted data (with early termination optimization)

Complexity Analysis

MetricBestAverageWorst
TimeO(n)O(n²)O(n²)
SpaceO(1)

Visualization

64
34
25
12
22
11
90
Speed:1x
Initial arrayStep 1 / 37

Implementation

Output

Click "Run Code" to see output...