Algorithm Complexity Visualizer

500ms
8
Time Complexity
O(n²)
Operations
0
Time Elapsed
0.00s

Array Visualization

Current Step

Click Start to begin visualization

Recent Operations

No operations yet...

Bubble Sort

Repeatedly swaps adjacent elements if they are in wrong order
1function bubbleSort(arr) {
2 for (let i = 0; i < arr.length; i++) {
3 for (let j = 0; j < arr.length - i - 1; j++) {
4 if (arr[j] > arr[j + 1]) {
5 swap(arr, j, j + 1);
6 }
7 }
8 }
9 return arr;
10}

Understanding the Visualization

Unsorted
Not yet processed
Comparing
Being compared
Swapping
Positions swapping
Sorted
In final position

Pro Tips

šŸ’”Compare Mode: See algorithms race side-by-side with same input
⚔Operations: Lower count = more efficient algorithm
šŸ“ŠArray Size: Increase size to see complexity differences amplify
šŸŽÆBig O: Theoretical complexity - watch it play out visually!