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
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(n) | O(n²) | O(n²) |
| Space | O(1) | ||
Visualization
64
34
25
12
22
11
90
Implementation
Output
Click "Run Code" to see output...