Sorting Algorithm Visualizer

An interactive environment built to demonstrate how complex sorting algorithms process data in real-time. Adjust the array size and timing speed, then execute a sort to watch it run.

The Algorithms Explained

Bubble Sort: The simplest sorting algorithm. It repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. (Slow: O(n²))

Quick Sort: Picks a "pivot" element and partitions the array so smaller numbers are on the left and larger numbers on the right, then recursively sorts the halves. (Fast: O(n log n))

Merge Sort: A divide-and-conquer algorithm that splits the array down to single elements, then perfectly merges them back together in order. (Reliable: O(n log n))

Heap Sort: Visualizes the array as a binary tree (a max-heap). It repeatedly swaps the largest found element to the end of the array and rebuilds the tree. (Efficient: O(n log n))

Comb Sort: An improvement over Bubble Sort. Instead of comparing adjacent items, it compares items far apart, shrinking the gap over time to quickly eliminate small values stuck at the end.

Shell Sort: A highly optimized version of Insertion Sort. It sorts elements separated by a large gap, progressively reducing the gap down to 1.

Instructions & Color Legend

How to use:

  • Use the sliders above to adjust the array size and the animation speed.
  • Click New Array to scramble the bars.
  • Click Reset Array to reorganize the bars to an unsorted state.
  • Select any algorithm to watch it execute in real-time.

What the colors mean:

Unsorted: The default state of a bar.
Comparing: The algorithm is checking these values.
Swapping: The bars are changing places.
Sorted: The bar is in its final, correct position.