DevSupporter
DevSupporter

Welcome back

Please enter your details to sign in to your account

Forgot password?
Sign in

Sorting Visualizer

Bubble SortBeginner

Watch sorting algorithms come to life. Compare speed, swaps, and comparisons in real time.

BestAverageWorstSpaceStable
O(n)O(nยฒ)O(nยฒ)O(1)Yes
40
3
๐Ÿ”„ Comparisons
0
๐Ÿ”€ Swaps
0
โฑ Time (ms)
0
๐Ÿ“Š Array Accesses
0

  • Select a sorting algorithm from the tabs above
  • Adjust Array Size and Speed with the sliders
  • Click Shuffle to generate a new random array
  • Click Sort to start the visualization
  • Use Pause/Resume to control playback
  • Watch the color indicators: ๐Ÿ”ต Blue: unsorted ๐ŸŸก Yellow: comparing ๐Ÿ”ด Red: swapping ๐ŸŸข Green: sorted ๐ŸŸฃ Purple: pivot ๐ŸŸ  Orange: insertion position

1. Generator Pattern

All sorting algorithms are implemented as JavaScript Generator functions. Each step yields a snapshot of the array state with highlighted indices. The visualizer consumes one step at a time with a configurable delay, making it easy to pause, resume, or change speed mid-sort.

// Generator yields each comparison/swap as a step
function* bubbleSort(arr: number[]): SortGenerator {
  // ...
  yield { array: [...arr], comparing: [j, j+1], swapping: [] };
  // ...
}

// Visualizer consumes one step at a time
const { value, done } = generator.next();
setState(value);
await sleep(delay);
2. Time Complexity Comparison

O(nยฒ) algorithms (Bubble, Selection, Insertion) slow down dramatically with large arrays. O(n log n) algorithms (Merge, Quick, Heap) scale much better. Try Array Size = 100 to see the difference clearly.

3. Stable vs Unstable Sort

A stable sort preserves the relative order of equal elements. Bubble, Insertion, and Merge Sort are stable. Selection, Quick, and Heap Sort are not.


2026 ยฉ DevSupporter - Playground for Developers by DevSupporter