Intermediate 25 min

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:

  1. Comparisons: Adjacent elements are highlighted when compared
  2. Swaps: Elements change color when swapped
  3. Bubbling: Larger values move right (bubble up)
  4. Sorted elements: Elements turn green when in final position
  5. 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.