Bubble Sort VisualizerO(N²) Stable

LeetCode #912
Comparisons0
Swaps0
Accesses0
Step 1 / 0
45
[0]
18
[1]
72
[2]
9
[3]
34
[4]
88
[5]
23
[6]
56
[7]
12
[8]
65
[9]
Code Execution

💡 Bubble Sort in Layman's Terms

Bubble Sort works like bubbles floating to the top of a soda glass! Larger numbers repeatedly swap with neighbors to "bubble up" to the end of the list.

How it Works Step-by-Step:
  • 1Compare Side-by-Side: Look at two neighboring numbers. If the left number is bigger than the right, swap them!
  • 2Bubble to the End: Keep swapping along the line until the biggest number reaches the far right.
  • 3Repeat & Finish: Repeat for the remaining numbers until a full pass completes with zero swaps!
🥤 Real-World Analogy: Air Bubbles Floating in Soda

Imagine a line of students standing in random order. The teacher walks down the line comparing two students at a time. If the student on the left is taller, they swap places. After one full pass, the tallest student is guaranteed to be at the very end!

State Variables
i0
j0
n10
swappedfalse
Time: O(N²)Space: O(1)
LeetCode #912