CPKit
v1.6.1

Bubble Sort

SortingEasy

Repeatedly swap adjacent elements if they are in the wrong order.

Alt+Shift+B

Configuration Panel

Pass / Swapping Trace Visualizer

23
0
8
1
56
2
12
3
38
4
5
5
72
6
16
7
Step: 1 / 1

Time Complexity

O(N^2) average/worst, O(N) best case optimized

Space Complexity

O(1) auxiliary memory
Conceptual Overview

Bubble Sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. This pass is repeated until the list is sorted.

Algorithm Idea

Run nested loops. Compare adjacent cells: if left > right, swap. After each inner loop pass, the largest unsorted element bubbles up to the end.

Stable Sorting

Stable (adjacent equal values do not swap)

In-place Memory

In-place (no auxiliary array required)

Source: CP-Algorithms search & sorting reference