Interactive Visualization
Watch bubble sort work in real-time. The visualizer shows each comparison and swap.
Bubble Sort Visualization
1x
What to Observe
As you watch the visualization, notice:
- Comparisons: Adjacent elements are highlighted when compared
- Swaps: Elements change color when swapped
- Bubbling: Larger values move right (bubble up)
- Sorted elements: Elements turn green when in final position
- Passes: Each complete pass through the array
Try Different Arrays
The visualizer starts with [10, 50, 30, 20, 40]. Try modifying the code to sort different arrays:
- Small array: [3, 1, 2]
- Reverse order: [5, 4, 3, 2, 1]
- Already sorted: [1, 2, 3, 4, 5]
- With duplicates: [5, 2, 5, 1, 2]
Understanding the Colors
- Blue: Elements being compared
- Red/Orange: Elements being swapped
- Green: Elements in their final sorted position
- Default: Unsorted elements
Speed Control
Use the speed slider to:
- Slow: See each step clearly
- Fast: See the overall pattern
- Pause: Stop and analyze the current state
What’s Next?
Now that you’ve seen it work, let’s implement bubble sort in code.
Progress 43%
Page 3 of 7
← Previous
→ Next